diff --git a/appengine/standard/i18n/i18n_utils.py b/appengine/standard/i18n/i18n_utils.py index 12eb5e59179..18ebf35ae80 100644 --- a/appengine/standard/i18n/i18n_utils.py +++ b/appengine/standard/i18n/i18n_utils.py @@ -19,7 +19,7 @@ The idea of this example, especially for how to translate strings in Javascript is originally from an implementation of Django i18n. """ - +from __future__ import print_function import gettext import json @@ -31,6 +31,11 @@ from webob import Request +try: + basestring +except NameError: + basestring = str + def _get_plural_forms(js_translations): """Extracts the parameters for what constitutes a plural. @@ -49,7 +54,7 @@ def _get_plural_forms(js_translations): for l in js_translations._catalog[''].split('\n'): if l.startswith('Plural-Forms:'): plural = l.split(':', 1)[1].strip() - print "plural is %s" % plural + print('plural is {}'.format(plural)) if plural is not None: for raw_element in plural.split(';'): element = raw_element.strip() @@ -57,7 +62,7 @@ def _get_plural_forms(js_translations): n_plural = int(element.split('=', 1)[1]) elif element.startswith('plural='): plural = element.split('=', 1)[1] - print "plural is now %s" % plural + print('plural is now {}'.format(plural)) else: n_plural = 2 plural = '(n == 1) ? 0 : 1' @@ -83,9 +88,9 @@ def convert_translations_to_dict(js_translations): for key, value in js_translations._catalog.items(): if key == '': continue - if type(key) in (str, unicode): + if isinstance(key, basestring): translations_dict['catalog'][key] = value - elif type(key) == tuple: + elif isinstance(key, tuple): if key[0] not in translations_dict['catalog']: translations_dict['catalog'][key[0]] = [''] * n_plural translations_dict['catalog'][key[0]][int(key[1])] = value diff --git a/appengine/standard/mail/header.py b/appengine/standard/mail/header.py index 4a84edeac23..7f994600bf2 100644 --- a/appengine/standard/mail/header.py +++ b/appengine/standard/mail/header.py @@ -1,3 +1,4 @@ +from __future__ import print_function # Copyright 2016 Google Inc. All rights reserved. # # Licensed under the Apache License, Version 2.0 (the "License"); @@ -40,7 +41,7 @@ def get(self): """) def post(self): - print repr(self.request.POST) + print(repr(self.request.POST)) id = self.request.POST['thread_id'] send_example_mail('{}@appspot.gserviceaccount.com'.format( app_identity.get_application_id()), id) diff --git a/appengine/standard/ndb/properties/snippets.py b/appengine/standard/ndb/properties/snippets.py index 9c98ac6701d..fecdbd3c65e 100644 --- a/appengine/standard/ndb/properties/snippets.py +++ b/appengine/standard/ndb/properties/snippets.py @@ -1,3 +1,4 @@ +from __future__ import print_function # Copyright 2016 Google Inc. All rights reserved. # # Licensed under the Apache License, Version 2.0 (the "License"); @@ -147,4 +148,4 @@ class Part(ndb.Model): def print_part(): p1 = Part(name='foo', color=Color.RED) - print p1.color # prints "RED" + print(p1.color) # prints "RED" diff --git a/appengine/standard/ndb/queries/snippets_test.py b/appengine/standard/ndb/queries/snippets_test.py index d8e6ddef79c..7000fc055e7 100644 --- a/appengine/standard/ndb/queries/snippets_test.py +++ b/appengine/standard/ndb/queries/snippets_test.py @@ -1,3 +1,4 @@ +from __future__ import print_function # Copyright 2016 Google Inc. All rights reserved. # # Licensed under the Apache License, Version 2.0 (the "License"); @@ -343,7 +344,7 @@ def test_fetch_message_accounts_inefficient(testbed): assert len(message_account_pairs) == 5 - print repr(message_account_pairs) + print(repr(message_account_pairs)) for i in range(1, 6): message, account = message_account_pairs[i - 1] assert message.content == 'Message %s' % i