Skip to content

Commit 02998e8

Browse files
cclaussgguuss
authored andcommitted
Use print() function in both Python 2 and Python 3 (#2234)
Legacy __print__ statements are syntax errors in Python 3 but __print()__ function works as expected in both Python 2 and Python 3.
1 parent 5907fab commit 02998e8

File tree

4 files changed

+16
-8
lines changed

4 files changed

+16
-8
lines changed

appengine/standard/i18n/i18n_utils.py

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919
The idea of this example, especially for how to translate strings in
2020
Javascript is originally from an implementation of Django i18n.
2121
"""
22-
22+
from __future__ import print_function
2323

2424
import gettext
2525
import json
@@ -31,6 +31,11 @@
3131

3232
from webob import Request
3333

34+
try:
35+
basestring
36+
except NameError:
37+
basestring = str
38+
3439

3540
def _get_plural_forms(js_translations):
3641
"""Extracts the parameters for what constitutes a plural.
@@ -49,15 +54,15 @@ def _get_plural_forms(js_translations):
4954
for l in js_translations._catalog[''].split('\n'):
5055
if l.startswith('Plural-Forms:'):
5156
plural = l.split(':', 1)[1].strip()
52-
print "plural is %s" % plural
57+
print('plural is {}'.format(plural))
5358
if plural is not None:
5459
for raw_element in plural.split(';'):
5560
element = raw_element.strip()
5661
if element.startswith('nplurals='):
5762
n_plural = int(element.split('=', 1)[1])
5863
elif element.startswith('plural='):
5964
plural = element.split('=', 1)[1]
60-
print "plural is now %s" % plural
65+
print('plural is now {}'.format(plural))
6166
else:
6267
n_plural = 2
6368
plural = '(n == 1) ? 0 : 1'
@@ -83,9 +88,9 @@ def convert_translations_to_dict(js_translations):
8388
for key, value in js_translations._catalog.items():
8489
if key == '':
8590
continue
86-
if type(key) in (str, unicode):
91+
if isinstance(key, basestring):
8792
translations_dict['catalog'][key] = value
88-
elif type(key) == tuple:
93+
elif isinstance(key, tuple):
8994
if key[0] not in translations_dict['catalog']:
9095
translations_dict['catalog'][key[0]] = [''] * n_plural
9196
translations_dict['catalog'][key[0]][int(key[1])] = value

appengine/standard/mail/header.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
from __future__ import print_function
12
# Copyright 2016 Google Inc. All rights reserved.
23
#
34
# Licensed under the Apache License, Version 2.0 (the "License");
@@ -40,7 +41,7 @@ def get(self):
4041
</form></body></html>""")
4142

4243
def post(self):
43-
print repr(self.request.POST)
44+
print(repr(self.request.POST))
4445
id = self.request.POST['thread_id']
4546
send_example_mail('{}@appspot.gserviceaccount.com'.format(
4647
app_identity.get_application_id()), id)

appengine/standard/ndb/properties/snippets.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
from __future__ import print_function
12
# Copyright 2016 Google Inc. All rights reserved.
23
#
34
# Licensed under the Apache License, Version 2.0 (the "License");
@@ -147,4 +148,4 @@ class Part(ndb.Model):
147148

148149
def print_part():
149150
p1 = Part(name='foo', color=Color.RED)
150-
print p1.color # prints "RED"
151+
print(p1.color) # prints "RED"

appengine/standard/ndb/queries/snippets_test.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
from __future__ import print_function
12
# Copyright 2016 Google Inc. All rights reserved.
23
#
34
# Licensed under the Apache License, Version 2.0 (the "License");
@@ -343,7 +344,7 @@ def test_fetch_message_accounts_inefficient(testbed):
343344

344345
assert len(message_account_pairs) == 5
345346

346-
print repr(message_account_pairs)
347+
print(repr(message_account_pairs))
347348
for i in range(1, 6):
348349
message, account = message_account_pairs[i - 1]
349350
assert message.content == 'Message %s' % i

0 commit comments

Comments
 (0)