diff options
| author | Claude Paroz <claude@2xlibre.net> | 2012-04-28 18:02:01 +0200 |
|---|---|---|
| committer | Claude Paroz <claude@2xlibre.net> | 2012-04-30 20:45:03 +0200 |
| commit | 596cb9c7e287abbb98c64974fb4944d522cb6b5a (patch) | |
| tree | e8ad5402dd233458b392d1822146bb1102ba74a6 /django | |
| parent | fe43ad5707d116bb1729bc17a24ca16c90ae040d (diff) | |
Replaced print statement by print function (forward compatibility syntax).
Diffstat (limited to 'django')
24 files changed, 119 insertions, 119 deletions
diff --git a/django/bin/profiling/gather_profile_stats.py b/django/bin/profiling/gather_profile_stats.py index 2274eadee9..0244eb6034 100644 --- a/django/bin/profiling/gather_profile_stats.py +++ b/django/bin/profiling/gather_profile_stats.py @@ -24,7 +24,7 @@ def gather_stats(p): prof = stats.load(os.path.join(p, f)) else: continue - print "Processing %s" % f + print("Processing %s" % f) if path in profiles: profiles[path].add(prof) else: diff --git a/django/bin/unique-messages.py b/django/bin/unique-messages.py index c43374a5b9..fbc74f8f46 100755 --- a/django/bin/unique-messages.py +++ b/django/bin/unique-messages.py @@ -11,7 +11,7 @@ def unique_messages(): elif os.path.isdir('locale'): basedir = os.path.abspath('locale') else: - print "This script should be run from the Django Git tree or your project or app tree." + print("This script should be run from the Django Git tree or your project or app tree.") sys.exit(1) for (dirpath, dirnames, filenames) in os.walk(basedir): diff --git a/django/contrib/auth/management/__init__.py b/django/contrib/auth/management/__init__.py index b516507277..66f54f18a8 100644 --- a/django/contrib/auth/management/__init__.py +++ b/django/contrib/auth/management/__init__.py @@ -54,7 +54,7 @@ def create_permissions(app, created_models, verbosity, **kwargs): auth_app.Permission.objects.bulk_create(objs) if verbosity >= 2: for obj in objs: - print "Adding permission '%s'" % obj + print("Adding permission '%s'" % obj) def create_superuser(app, created_models, verbosity, db, **kwargs): diff --git a/django/contrib/contenttypes/management.py b/django/contrib/contenttypes/management.py index d47d5579ba..6a23ef5287 100644 --- a/django/contrib/contenttypes/management.py +++ b/django/contrib/contenttypes/management.py @@ -39,7 +39,7 @@ def update_contenttypes(app, created_models, verbosity=2, **kwargs): ]) if verbosity >= 2: for ct in cts: - print "Adding content type '%s | %s'" % (ct.app_label, ct.model) + print("Adding content type '%s | %s'" % (ct.app_label, ct.model)) # Confirm that the content type is stale before deletion. if to_remove: @@ -63,11 +63,11 @@ If you're unsure, answer 'no'. if ok_to_delete == 'yes': for ct in to_remove: if verbosity >= 2: - print "Deleting stale content type '%s | %s'" % (ct.app_label, ct.model) + print("Deleting stale content type '%s | %s'" % (ct.app_label, ct.model)) ct.delete() else: if verbosity >= 2: - print "Stale content types remain." + print("Stale content types remain.") def update_all_contenttypes(verbosity=2, **kwargs): for app in get_apps(): diff --git a/django/contrib/gis/db/backends/spatialite/creation.py b/django/contrib/gis/db/backends/spatialite/creation.py index 33b6f95864..aab03e8d58 100644 --- a/django/contrib/gis/db/backends/spatialite/creation.py +++ b/django/contrib/gis/db/backends/spatialite/creation.py @@ -24,7 +24,7 @@ class SpatiaLiteCreation(DatabaseCreation): test_db_repr = '' if verbosity >= 2: test_db_repr = " ('%s')" % test_database_name - print "Creating test database for alias '%s'%s..." % (self.connection.alias, test_db_repr) + print("Creating test database for alias '%s'%s..." % (self.connection.alias, test_db_repr)) self._create_test_db(verbosity, autoclobber) diff --git a/django/contrib/gis/gdal/geometries.py b/django/contrib/gis/gdal/geometries.py index 30125d5764..b4d4ad1646 100644 --- a/django/contrib/gis/gdal/geometries.py +++ b/django/contrib/gis/gdal/geometries.py @@ -13,21 +13,21 @@ >>> from django.contrib.gis.gdal import OGRGeometry, OGRGeomType, SpatialReference >>> wkt1, wkt2 = 'POINT(-90 30)', 'POLYGON((0 0, 5 0, 5 5, 0 5)' >>> pnt = OGRGeometry(wkt1) - >>> print pnt + >>> print(pnt) POINT (-90 30) >>> mpnt = OGRGeometry(OGRGeomType('MultiPoint'), SpatialReference('WGS84')) >>> mpnt.add(wkt1) >>> mpnt.add(wkt1) - >>> print mpnt + >>> print(mpnt) MULTIPOINT (-90 30,-90 30) - >>> print mpnt.srs.name + >>> print(mpnt.srs.name) WGS 84 - >>> print mpnt.srs.proj + >>> print(mpnt.srs.proj) +proj=longlat +ellps=WGS84 +datum=WGS84 +no_defs >>> mpnt.transform_to(SpatialReference('NAD27')) - >>> print mpnt.proj + >>> print(mpnt.proj) +proj=longlat +ellps=clrk66 +datum=NAD27 +no_defs - >>> print mpnt + >>> print(mpnt) MULTIPOINT (-89.999930378602485 29.999797886557641,-89.999930378602485 29.999797886557641) The OGRGeomType class is to make it easy to specify an OGR geometry type: @@ -35,8 +35,8 @@ >>> gt1 = OGRGeomType(3) # Using an integer for the type >>> gt2 = OGRGeomType('Polygon') # Using a string >>> gt3 = OGRGeomType('POLYGON') # It's case-insensitive - >>> print gt1 == 3, gt1 == 'Polygon' # Equivalence works w/non-OGRGeomType objects - True + >>> print(gt1 == 3, gt1 == 'Polygon') # Equivalence works w/non-OGRGeomType objects + True True """ # Python library requisites. import sys diff --git a/django/contrib/gis/gdal/srs.py b/django/contrib/gis/gdal/srs.py index e211bace91..67049731de 100644 --- a/django/contrib/gis/gdal/srs.py +++ b/django/contrib/gis/gdal/srs.py @@ -4,7 +4,7 @@ Example: >>> from django.contrib.gis.gdal import SpatialReference >>> srs = SpatialReference('WGS84') - >>> print srs + >>> print(srs) GEOGCS["WGS 84", DATUM["WGS_1984", SPHEROID["WGS 84",6378137,298.257223563, @@ -16,14 +16,14 @@ UNIT["degree",0.01745329251994328, AUTHORITY["EPSG","9122"]], AUTHORITY["EPSG","4326"]] - >>> print srs.proj + >>> print(srs.proj) +proj=longlat +ellps=WGS84 +datum=WGS84 +no_defs - >>> print srs.ellipsoid + >>> print(srs.ellipsoid) (6378137.0, 6356752.3142451793, 298.25722356300003) - >>> print srs.projected, srs.geographic + >>> print(srs.projected, srs.geographic) False True >>> srs.import_epsg(32140) - >>> print srs.name + >>> print(srs.name) NAD83 / Texas South Central """ from ctypes import byref, c_char_p, c_int @@ -103,19 +103,19 @@ class SpatialReference(GDALBase): >>> wkt = 'GEOGCS["WGS 84", DATUM["WGS_1984, ... AUTHORITY["EPSG","4326"]]') >>> srs = SpatialReference(wkt) # could also use 'WGS84', or 4326 - >>> print srs['GEOGCS'] + >>> print(srs['GEOGCS']) WGS 84 - >>> print srs['DATUM'] + >>> print(srs['DATUM']) WGS_1984 - >>> print srs['AUTHORITY'] + >>> print(srs['AUTHORITY']) EPSG - >>> print srs['AUTHORITY', 1] # The authority value + >>> print(srs['AUTHORITY', 1]) # The authority value 4326 - >>> print srs['TOWGS84', 4] # the fourth value in this wkt + >>> print(srs['TOWGS84', 4]) # the fourth value in this wkt 0 - >>> print srs['UNIT|AUTHORITY'] # For the units authority, have to use the pipe symbole. + >>> print(srs['UNIT|AUTHORITY']) # For the units authority, have to use the pipe symbole. EPSG - >>> print srs['UNIT|AUTHORITY', 1] # The authority value for the untis + >>> print(srs['UNIT|AUTHORITY', 1]) # The authority value for the untis 9122 """ if isinstance(target, tuple): diff --git a/django/contrib/gis/gdal/tests/test_ds.py b/django/contrib/gis/gdal/tests/test_ds.py index 16d6e8603b..71d22a0a27 100644 --- a/django/contrib/gis/gdal/tests/test_ds.py +++ b/django/contrib/gis/gdal/tests/test_ds.py @@ -59,7 +59,7 @@ class DataSourceTest(unittest.TestCase): def test03a_layers(self): "Testing Data Source Layers." - print "\nBEGIN - expecting out of range feature id error; safe to ignore.\n" + print("\nBEGIN - expecting out of range feature id error; safe to ignore.\n") for source in ds_list: ds = DataSource(source.ds) @@ -108,7 +108,7 @@ class DataSourceTest(unittest.TestCase): # the feature values here while in this loop. for fld_name in fld_names: self.assertEqual(source.field_values[fld_name][i], feat.get(fld_name)) - print "\nEND - expecting out of range feature id error; safe to ignore." + print("\nEND - expecting out of range feature id error; safe to ignore.") def test03b_layer_slice(self): "Test indexing and slicing on Layers." diff --git a/django/contrib/gis/gdal/tests/test_geom.py b/django/contrib/gis/gdal/tests/test_geom.py index 656901b55e..b68aa41b0a 100644 --- a/django/contrib/gis/gdal/tests/test_geom.py +++ b/django/contrib/gis/gdal/tests/test_geom.py @@ -234,7 +234,7 @@ class OGRGeomTest(unittest.TestCase, TestDataMixin): # Both rings in this geometry are not closed. poly = OGRGeometry('POLYGON((0 0, 5 0, 5 5, 0 5), (1 1, 2 1, 2 2, 2 1))') self.assertEqual(8, poly.point_count) - print "\nBEGIN - expecting IllegalArgumentException; safe to ignore.\n" + print("\nBEGIN - expecting IllegalArgumentException; safe to ignore.\n") try: c = poly.centroid except OGRException: @@ -242,7 +242,7 @@ class OGRGeomTest(unittest.TestCase, TestDataMixin): pass else: self.fail('Should have raised an OGRException!') - print "\nEND - expecting IllegalArgumentException; safe to ignore.\n" + print("\nEND - expecting IllegalArgumentException; safe to ignore.\n") # Closing the rings -- doesn't work on GDAL versions 1.4.1 and below: # http://trac.osgeo.org/gdal/ticket/1673 diff --git a/django/contrib/gis/geos/tests/test_geos.py b/django/contrib/gis/geos/tests/test_geos.py index a6b50df635..a81925aec1 100644 --- a/django/contrib/gis/geos/tests/test_geos.py +++ b/django/contrib/gis/geos/tests/test_geos.py @@ -134,7 +134,7 @@ class GEOSTest(unittest.TestCase, TestDataMixin): def test01d_errors(self): "Testing the Error handlers." # string-based - print "\nBEGIN - expecting GEOS_ERROR; safe to ignore.\n" + print("\nBEGIN - expecting GEOS_ERROR; safe to ignore.\n") for err in self.geometries.errors: try: g = fromstr(err.wkt) @@ -144,7 +144,7 @@ class GEOSTest(unittest.TestCase, TestDataMixin): # Bad WKB self.assertRaises(GEOSException, GEOSGeometry, buffer('0')) - print "\nEND - expecting GEOS_ERROR; safe to ignore.\n" + print("\nEND - expecting GEOS_ERROR; safe to ignore.\n") class NotAGeometry(object): pass @@ -439,7 +439,7 @@ class GEOSTest(unittest.TestCase, TestDataMixin): def test05b_multipolygons(self): "Testing MultiPolygon objects." - print "\nBEGIN - expecting GEOS_NOTICE; safe to ignore.\n" + print("\nBEGIN - expecting GEOS_NOTICE; safe to ignore.\n") prev = fromstr('POINT (0 0)') for mp in self.geometries.multipolygons: mpoly = fromstr(mp.wkt) @@ -458,7 +458,7 @@ class GEOSTest(unittest.TestCase, TestDataMixin): self.assertEqual(p.valid, True) self.assertEqual(mpoly.wkt, MultiPolygon(*tuple(poly.clone() for poly in mpoly)).wkt) - print "\nEND - expecting GEOS_NOTICE; safe to ignore.\n" + print("\nEND - expecting GEOS_NOTICE; safe to ignore.\n") def test06a_memory_hijinks(self): "Testing Geometry __del__() on rings and polygons." @@ -995,7 +995,7 @@ class GEOSTest(unittest.TestCase, TestDataMixin): self.assertTrue(isinstance(g.valid_reason, basestring)) self.assertEqual(g.valid_reason, "Valid Geometry") - print "\nBEGIN - expecting GEOS_NOTICE; safe to ignore.\n" + print("\nBEGIN - expecting GEOS_NOTICE; safe to ignore.\n") g = GEOSGeometry("LINESTRING(0 0, 0 0)") @@ -1003,7 +1003,7 @@ class GEOSTest(unittest.TestCase, TestDataMixin): self.assertTrue(isinstance(g.valid_reason, basestring)) self.assertTrue(g.valid_reason.startswith("Too few points in geometry component")) - print "\nEND - expecting GEOS_NOTICE; safe to ignore.\n" + print("\nEND - expecting GEOS_NOTICE; safe to ignore.\n") def test28_geos_version(self): "Testing the GEOS version regular expression." diff --git a/django/contrib/gis/utils/ogrinfo.py b/django/contrib/gis/utils/ogrinfo.py index 1e4c42daa5..d9c3e09155 100644 --- a/django/contrib/gis/utils/ogrinfo.py +++ b/django/contrib/gis/utils/ogrinfo.py @@ -22,19 +22,19 @@ def ogrinfo(data_source, num_features=10): raise Exception('Data source parameter must be a string or a DataSource object.') for i, layer in enumerate(data_source): - print "data source : %s" % data_source.name - print "==== layer %s" % i - print " shape type: %s" % GEO_CLASSES[layer.geom_type.num].__name__ - print " # features: %s" % len(layer) - print " srs: %s" % layer.srs + print("data source : %s" % data_source.name) + print("==== layer %s" % i) + print(" shape type: %s" % GEO_CLASSES[layer.geom_type.num].__name__) + print(" # features: %s" % len(layer)) + print(" srs: %s" % layer.srs) extent_tup = layer.extent.tuple - print " extent: %s - %s" % (extent_tup[0:2], extent_tup[2:4]) - print "Displaying the first %s features ====" % num_features + print(" extent: %s - %s" % (extent_tup[0:2], extent_tup[2:4])) + print("Displaying the first %s features ====" % num_features) width = max(*map(len,layer.fields)) fmt = " %%%ss: %%s" % width for j, feature in enumerate(layer[:num_features]): - print "=== Feature %s" % j + print("=== Feature %s" % j) for fld_name in layer.fields: type_name = feature[fld_name].type_name output = fmt % (fld_name, type_name) @@ -47,7 +47,7 @@ def ogrinfo(data_source, num_features=10): output += val_fmt % val else: output += ' (None)' - print output + print(output) # For backwards compatibility. sample = ogrinfo diff --git a/django/contrib/gis/utils/ogrinspect.py b/django/contrib/gis/utils/ogrinspect.py index aa4e209877..a99989978e 100644 --- a/django/contrib/gis/utils/ogrinspect.py +++ b/django/contrib/gis/utils/ogrinspect.py @@ -68,8 +68,8 @@ def ogrinspect(*args, **kwargs): shp_file = 'data/mapping_hacks/world_borders.shp' model_name = 'WorldBorders' - print ogrinspect(shp_file, model_name, multi_geom=True, srid=4326, - geom_name='shapes', blank=True) + print(ogrinspect(shp_file, model_name, multi_geom=True, srid=4326, + geom_name='shapes', blank=True)) Required Arguments `datasource` => string or DataSource object to file pointer diff --git a/django/contrib/sites/management.py b/django/contrib/sites/management.py index 1b76bf5411..7a29e82d4c 100644 --- a/django/contrib/sites/management.py +++ b/django/contrib/sites/management.py @@ -18,7 +18,7 @@ def create_default_site(app, created_models, verbosity, db, **kwargs): # the next id will be 1, so we coerce it. See #15573 and #16353. This # can also crop up outside of tests - see #15346. if verbosity >= 2: - print "Creating example.com Site object" + print("Creating example.com Site object") Site(pk=1, domain="example.com", name="example.com").save(using=db) # We set an explicit pk instead of relying on auto-incrementation, @@ -26,7 +26,7 @@ def create_default_site(app, created_models, verbosity, db, **kwargs): sequence_sql = connections[db].ops.sequence_reset_sql(no_style(), [Site]) if sequence_sql: if verbosity >= 2: - print "Resetting sequence" + print("Resetting sequence") cursor = connections[db].cursor() for command in sequence_sql: cursor.execute(command) diff --git a/django/core/management/__init__.py b/django/core/management/__init__.py index 840a3b74df..b4e82e454f 100644 --- a/django/core/management/__init__.py +++ b/django/core/management/__init__.py @@ -299,7 +299,7 @@ class ManagementUtility(object): # subcommand if cword == 1: - print ' '.join(sorted(filter(lambda x: x.startswith(curr), subcommands))) + print(' '.join(sorted(filter(lambda x: x.startswith(curr), subcommands)))) # subcommand options # special case: the 'help' subcommand has no options elif cwords[0] in subcommands and cwords[0] != 'help': @@ -333,7 +333,7 @@ class ManagementUtility(object): # append '=' to options which require args if option[1]: opt_label += '=' - print opt_label + print(opt_label) sys.exit(1) def execute(self): diff --git a/django/core/management/sql.py b/django/core/management/sql.py index 68c72b3487..83c17d9731 100644 --- a/django/core/management/sql.py +++ b/django/core/management/sql.py @@ -173,7 +173,7 @@ def emit_post_sync_signal(created_models, verbosity, interactive, db): for app in models.get_apps(): app_name = app.__name__.split('.')[-2] if verbosity >= 2: - print "Running post-sync handlers for application", app_name + print("Running post-sync handlers for application %s" % app_name) models.signals.post_syncdb.send(sender=app, app=app, created_models=created_models, verbosity=verbosity, interactive=interactive, db=db) diff --git a/django/core/servers/fastcgi.py b/django/core/servers/fastcgi.py index 9c652a74ef..750bff7e9f 100644 --- a/django/core/servers/fastcgi.py +++ b/django/core/servers/fastcgi.py @@ -82,9 +82,9 @@ Examples: """ % FASTCGI_OPTIONS def fastcgi_help(message=None): - print FASTCGI_HELP + print(FASTCGI_HELP) if message: - print message + print(message) return False def runfastcgi(argset=[], **kwargs): @@ -103,11 +103,11 @@ def runfastcgi(argset=[], **kwargs): try: import flup except ImportError as e: - print >> sys.stderr, "ERROR: %s" % e - print >> sys.stderr, " Unable to load the flup package. In order to run django" - print >> sys.stderr, " as a FastCGI application, you will need to get flup from" - print >> sys.stderr, " http://www.saddi.com/software/flup/ If you've already" - print >> sys.stderr, " installed flup, then make sure you have it in your PYTHONPATH." + sys.stderr.write("ERROR: %s\n" % e) + sys.stderr.write(" Unable to load the flup package. In order to run django\n") + sys.stderr.write(" as a FastCGI application, you will need to get flup from\n") + sys.stderr.write(" http://www.saddi.com/software/flup/ If you've already\n") + sys.stderr.write(" installed flup, then make sure you have it in your PYTHONPATH.\n") return False flup_module = 'server.' + options['protocol'] @@ -136,7 +136,7 @@ def runfastcgi(argset=[], **kwargs): module = importlib.import_module('.%s' % flup_module, 'flup') WSGIServer = module.WSGIServer except Exception: - print "Can't import flup." + flup_module + print("Can't import flup." + flup_module) return False # Prep up and go diff --git a/django/db/backends/creation.py b/django/db/backends/creation.py index e672253009..ba90cb970b 100644 --- a/django/db/backends/creation.py +++ b/django/db/backends/creation.py @@ -256,8 +256,8 @@ class BaseDatabaseCreation(object): test_db_repr = '' if verbosity >= 2: test_db_repr = " ('%s')" % test_database_name - print "Creating test database for alias '%s'%s..." % ( - self.connection.alias, test_db_repr) + print("Creating test database for alias '%s'%s..." % ( + self.connection.alias, test_db_repr)) self._create_test_db(verbosity, autoclobber) @@ -339,8 +339,8 @@ class BaseDatabaseCreation(object): if autoclobber or confirm == 'yes': try: if verbosity >= 1: - print ("Destroying old test database '%s'..." - % self.connection.alias) + print("Destroying old test database '%s'..." + % self.connection.alias) cursor.execute( "DROP DATABASE %s" % qn(test_database_name)) cursor.execute( @@ -351,7 +351,7 @@ class BaseDatabaseCreation(object): "Got an error recreating the test database: %s\n" % e) sys.exit(2) else: - print "Tests cancelled." + print("Tests cancelled.") sys.exit(1) return test_database_name @@ -367,8 +367,8 @@ class BaseDatabaseCreation(object): test_db_repr = '' if verbosity >= 2: test_db_repr = " ('%s')" % test_database_name - print "Destroying test database for alias '%s'%s..." % ( - self.connection.alias, test_db_repr) + print("Destroying test database for alias '%s'%s..." % ( + self.connection.alias, test_db_repr)) # Temporarily use a new connection and a copy of the settings dict. # This prevents the production database from being exposed to potential diff --git a/django/db/backends/oracle/creation.py b/django/db/backends/oracle/creation.py index 758c9ecd4a..2f096f735a 100644 --- a/django/db/backends/oracle/creation.py +++ b/django/db/backends/oracle/creation.py @@ -69,19 +69,19 @@ class DatabaseCreation(BaseDatabaseCreation): if autoclobber or confirm == 'yes': try: if verbosity >= 1: - print "Destroying old test database '%s'..." % self.connection.alias + print("Destroying old test database '%s'..." % self.connection.alias) self._execute_test_db_destruction(cursor, parameters, verbosity) self._execute_test_db_creation(cursor, parameters, verbosity) except Exception as e: sys.stderr.write("Got an error recreating the test database: %s\n" % e) sys.exit(2) else: - print "Tests cancelled." + print("Tests cancelled.") sys.exit(1) if self._test_user_create(): if verbosity >= 1: - print "Creating test user..." + print("Creating test user...") try: self._create_test_user(cursor, parameters, verbosity) except Exception as e: @@ -91,16 +91,16 @@ class DatabaseCreation(BaseDatabaseCreation): if autoclobber or confirm == 'yes': try: if verbosity >= 1: - print "Destroying old test user..." + print("Destroying old test user...") self._destroy_test_user(cursor, parameters, verbosity) if verbosity >= 1: - print "Creating test user..." + print("Creating test user...") self._create_test_user(cursor, parameters, verbosity) except Exception as e: sys.stderr.write("Got an error recreating the test user: %s\n" % e) sys.exit(2) else: - print "Tests cancelled." + print("Tests cancelled.") sys.exit(1) self.connection.settings_dict['SAVED_USER'] = self.connection.settings_dict['USER'] @@ -136,17 +136,17 @@ class DatabaseCreation(BaseDatabaseCreation): time.sleep(1) # To avoid "database is being accessed by other users" errors. if self._test_user_create(): if verbosity >= 1: - print 'Destroying test user...' + print('Destroying test user...') self._destroy_test_user(cursor, parameters, verbosity) if self._test_database_create(): if verbosity >= 1: - print 'Destroying test database tables...' + print('Destroying test database tables...') self._execute_test_db_destruction(cursor, parameters, verbosity) self.connection.close() def _execute_test_db_creation(self, cursor, parameters, verbosity): if verbosity >= 2: - print "_create_test_db(): dbname = %s" % parameters['dbname'] + print("_create_test_db(): dbname = %s" % parameters['dbname']) statements = [ """CREATE TABLESPACE %(tblspace)s DATAFILE '%(tblspace)s.dbf' SIZE 20M @@ -161,7 +161,7 @@ class DatabaseCreation(BaseDatabaseCreation): def _create_test_user(self, cursor, parameters, verbosity): if verbosity >= 2: - print "_create_test_user(): username = %s" % parameters['user'] + print("_create_test_user(): username = %s" % parameters['user']) statements = [ """CREATE USER %(user)s IDENTIFIED BY %(password)s @@ -174,7 +174,7 @@ class DatabaseCreation(BaseDatabaseCreation): def _execute_test_db_destruction(self, cursor, parameters, verbosity): if verbosity >= 2: - print "_execute_test_db_destruction(): dbname=%s" % parameters['dbname'] + print("_execute_test_db_destruction(): dbname=%s" % parameters['dbname']) statements = [ 'DROP TABLESPACE %(tblspace)s INCLUDING CONTENTS AND DATAFILES CASCADE CONSTRAINTS', 'DROP TABLESPACE %(tblspace_temp)s INCLUDING CONTENTS AND DATAFILES CASCADE CONSTRAINTS', @@ -183,8 +183,8 @@ class DatabaseCreation(BaseDatabaseCreation): def _destroy_test_user(self, cursor, parameters, verbosity): if verbosity >= 2: - print "_destroy_test_user(): user=%s" % parameters['user'] - print "Be patient. This can take some time..." + print("_destroy_test_user(): user=%s" % parameters['user']) + print("Be patient. This can take some time...") statements = [ 'DROP USER %(user)s CASCADE', ] @@ -194,7 +194,7 @@ class DatabaseCreation(BaseDatabaseCreation): for template in statements: stmt = template % parameters if verbosity >= 2: - print stmt + print(stmt) try: cursor.execute(stmt) except Exception as err: diff --git a/django/db/backends/sqlite3/creation.py b/django/db/backends/sqlite3/creation.py index 9e660fa387..efdc457be0 100644 --- a/django/db/backends/sqlite3/creation.py +++ b/django/db/backends/sqlite3/creation.py @@ -50,7 +50,7 @@ class DatabaseCreation(BaseDatabaseCreation): if test_database_name != ':memory:': # Erase the old test database if verbosity >= 1: - print "Destroying old test database '%s'..." % self.connection.alias + print("Destroying old test database '%s'..." % self.connection.alias) if os.access(test_database_name, os.F_OK): if not autoclobber: confirm = raw_input("Type 'yes' if you would like to try deleting the test database '%s', or 'no' to cancel: " % test_database_name) @@ -61,7 +61,7 @@ class DatabaseCreation(BaseDatabaseCreation): sys.stderr.write("Got an error deleting the old test database: %s\n" % e) sys.exit(2) else: - print "Tests cancelled." + print("Tests cancelled.") sys.exit(1) return test_database_name diff --git a/django/dispatch/saferef.py b/django/dispatch/saferef.py index 364c13e43b..ebf423fc91 100644 --- a/django/dispatch/saferef.py +++ b/django/dispatch/saferef.py @@ -122,9 +122,9 @@ class BoundMethodWeakref(object): except Exception as e: try: traceback.print_exc() - except AttributeError as err: - print '''Exception during saferef %s cleanup function %s: %s'''%( - self, function, e + except AttributeError: + print('Exception during saferef %s cleanup function %s: %s' % ( + self, function, e) ) self.deletionMethods = [onDelete] self.key = self.calculateKey( target ) diff --git a/django/test/_doctest.py b/django/test/_doctest.py index af2f409e32..b07829318d 100644 --- a/django/test/_doctest.py +++ b/django/test/_doctest.py @@ -878,7 +878,7 @@ class DocTestFinder: add them to `tests`. """ if self._verbose: - print 'Finding tests in %s' % name + print('Finding tests in %s' % name) # If we've already processed this object, then ignore it. if id(obj) in seen: @@ -1034,7 +1034,7 @@ class DocTestRunner: >>> tests = DocTestFinder().find(_TestClass) >>> runner = DocTestRunner(verbose=False) >>> for test in tests: - ... print runner.run(test) + ... print(runner.run(test)) (0, 2) (0, 1) (0, 2) @@ -1406,28 +1406,28 @@ class DocTestRunner: failed.append(x) if verbose: if notests: - print len(notests), "items had no tests:" + print("%d items had no tests:" % len(notests)) notests.sort() for thing in notests: - print " ", thing + print(" %s" % thing) if passed: - print len(passed), "items passed all tests:" + print("%d items passed all tests:" % len(passed)) passed.sort() for thing, count in passed: - print " %3d tests in %s" % (count, thing) + print(" %3d tests in %s" % (count, thing)) if failed: - print self.DIVIDER - print len(failed), "items had failures:" + print(self.DIVIDER) + print("%d items had failures:" % len(failed)) failed.sort() for thing, (f, t) in failed: - print " %3d of %3d in %s" % (f, t, thing) + print(" %3d of %3d in %s" % (f, t, thing)) if verbose: - print totalt, "tests in", len(self._name2ft), "items." - print totalt - totalf, "passed and", totalf, "failed." + print("%d tests in % d items" % (len(self._name2ft), totalt)) + print("%d passed and %d failed." % (totalt - totalf, totalf)) if totalf: - print "***Test Failed***", totalf, "failures." + print("***Test Failed*** %d failures." % totalf) elif verbose: - print "Test passed." + print("Test passed.") return totalf, totalt #///////////////////////////////////////////////////////////////// @@ -1437,8 +1437,8 @@ class DocTestRunner: d = self._name2ft for name, (f, t) in other._name2ft.items(): if name in d: - print "*** DocTestRunner.merge: '" + name + "' in both" \ - " testers; summing outcomes." + print("*** DocTestRunner.merge: '" + name + "' in both" \ + " testers; summing outcomes.") f2, t2 = d[name] f = f + f2 t = t + t2 @@ -2007,10 +2007,10 @@ class Tester: def runstring(self, s, name): test = DocTestParser().get_doctest(s, self.globs, name, None, None) if self.verbose: - print "Running string", name + print("Running string %s" % name) (f,t) = self.testrunner.run(test) if self.verbose: - print f, "of", t, "examples failed in string", name + print("%s of %s examples failed in string %s" % (f, t, name)) return (f,t) def rundoc(self, object, name=None, module=None): @@ -2442,7 +2442,7 @@ def script_from_examples(s): ... Ho hum ... ''' - >>> print script_from_examples(text) + >>> print(script_from_examples(text)) # Here are examples of simple math. # # Python has super accurate integer addition @@ -2533,7 +2533,7 @@ def debug_script(src, pm=False, globs=None): try: execfile(srcfilename, globs, globs) except: - print sys.exc_info()[1] + print(sys.exc_info()[1]) pdb.post_mortem(sys.exc_info()[2]) else: # Note that %r is vital here. '%s' instead can, e.g., cause @@ -2575,7 +2575,7 @@ class _TestClass: """val -> _TestClass object with associated value val. >>> t = _TestClass(123) - >>> print t.get() + >>> print(t.get()) 123 """ @@ -2595,7 +2595,7 @@ class _TestClass: """get() -> return TestClass's associated value. >>> x = _TestClass(-42) - >>> print x.get() + >>> print(x.get()) -42 """ @@ -2627,7 +2627,7 @@ __test__ = {"_TestClass": _TestClass, "blank lines": r""" Blank lines can be marked with <BLANKLINE>: - >>> print 'foo\n\nbar\n' + >>> print('foo\n\nbar\n') foo <BLANKLINE> bar @@ -2637,14 +2637,14 @@ __test__ = {"_TestClass": _TestClass, "ellipsis": r""" If the ellipsis flag is used, then '...' can be used to elide substrings in the desired output: - >>> print range(1000) #doctest: +ELLIPSIS + >>> print(range(1000)) #doctest: +ELLIPSIS [0, 1, 2, ..., 999] """, "whitespace normalization": r""" If the whitespace normalization flag is used, then differences in whitespace are ignored. - >>> print range(30) #doctest: +NORMALIZE_WHITESPACE + >>> print(range(30)) #doctest: +NORMALIZE_WHITESPACE [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29] diff --git a/django/utils/dateformat.py b/django/utils/dateformat.py index 1b2dd57fe7..e16a2df1f2 100644 --- a/django/utils/dateformat.py +++ b/django/utils/dateformat.py @@ -6,7 +6,7 @@ Usage: >>> import datetime >>> d = datetime.datetime.now() >>> df = DateFormat(d) ->>> print df.format('jS F Y H:i') +>>> print(df.format('jS F Y H:i')) 7th October 2003 11:39 >>> """ diff --git a/django/utils/termcolors.py b/django/utils/termcolors.py index 4fb64ac9a0..1eebaa2316 100644 --- a/django/utils/termcolors.py +++ b/django/utils/termcolors.py @@ -33,10 +33,10 @@ def colorize(text='', opts=(), **kwargs): colorize('hello', fg='red', bg='blue', opts=('blink',)) colorize() colorize('goodbye', opts=('underscore',)) - print colorize('first line', fg='red', opts=('noreset',)) - print 'this should be red too' - print colorize('and so should this') - print 'this should not be red' + print(colorize('first line', fg='red', opts=('noreset',))) + print('this should be red too') + print(colorize('and so should this')) + print('this should not be red') """ code_list = [] if text == '' and len(opts) == 1 and opts[0] == 'reset': @@ -59,7 +59,7 @@ def make_style(opts=(), **kwargs): Example: bold_red = make_style(opts=('bold',), fg='red') - print bold_red('hello') + print(bold_red('hello')) KEYWORD = make_style(fg='yellow') COMMENT = make_style(fg='blue', opts=('bold',)) """ diff --git a/django/utils/unittest/main.py b/django/utils/unittest/main.py index 744cacd841..0f25a98a22 100644 --- a/django/utils/unittest/main.py +++ b/django/utils/unittest/main.py @@ -99,7 +99,7 @@ class TestProgram(object): def usageExit(self, msg=None): if msg: - print msg + print(msg) usage = {'progName': self.progName, 'catchbreak': '', 'failfast': '', 'buffer': ''} if self.failfast != False: @@ -108,7 +108,7 @@ class TestProgram(object): usage['catchbreak'] = CATCHBREAK if self.buffer != False: usage['buffer'] = BUFFEROUTPUT - print self.USAGE % usage + print(self.USAGE % usage) sys.exit(2) def parseArgs(self, argv): |
