From 596cb9c7e287abbb98c64974fb4944d522cb6b5a Mon Sep 17 00:00:00 2001 From: Claude Paroz Date: Sat, 28 Apr 2012 18:02:01 +0200 Subject: [PATCH] Replaced print statement by print function (forward compatibility syntax). --- django/bin/profiling/gather_profile_stats.py | 2 +- django/bin/unique-messages.py | 2 +- django/contrib/auth/management/__init__.py | 2 +- django/contrib/contenttypes/management.py | 6 +- .../gis/db/backends/spatialite/creation.py | 2 +- django/contrib/gis/gdal/geometries.py | 16 ++--- django/contrib/gis/gdal/srs.py | 24 +++---- django/contrib/gis/gdal/tests/test_ds.py | 4 +- django/contrib/gis/gdal/tests/test_geom.py | 4 +- django/contrib/gis/geos/tests/test_geos.py | 12 ++-- django/contrib/gis/utils/ogrinfo.py | 18 ++--- django/contrib/gis/utils/ogrinspect.py | 4 +- django/contrib/sites/management.py | 4 +- django/core/management/__init__.py | 4 +- django/core/management/sql.py | 2 +- django/core/servers/fastcgi.py | 16 ++--- django/db/backends/creation.py | 14 ++-- django/db/backends/oracle/creation.py | 28 ++++---- django/db/backends/sqlite3/creation.py | 4 +- django/dispatch/saferef.py | 6 +- django/test/_doctest.py | 48 ++++++------- django/utils/dateformat.py | 2 +- django/utils/termcolors.py | 10 +-- django/utils/unittest/main.py | 4 +- docs/_ext/applyxrefs.py | 6 +- docs/_ext/literals_to_xrefs.py | 10 +-- docs/howto/custom-model-fields.txt | 2 +- docs/intro/install.txt | 2 +- docs/ref/contrib/gis/db-api.txt | 2 +- docs/ref/contrib/gis/gdal.txt | 24 +++---- docs/ref/contrib/gis/geoquerysets.txt | 16 ++--- docs/ref/contrib/gis/geos.txt | 2 +- docs/ref/contrib/gis/layermapping.txt | 8 +-- docs/ref/contrib/gis/measure.txt | 22 +++--- docs/ref/contrib/gis/tutorial.txt | 24 +++---- docs/ref/contrib/syndication.txt | 2 +- docs/ref/forms/api.txt | 68 +++++++++---------- docs/ref/forms/fields.txt | 14 ++-- docs/ref/models/instances.txt | 2 +- docs/ref/models/querysets.txt | 6 +- docs/ref/template-response.txt | 6 +- docs/ref/templates/api.txt | 2 +- docs/topics/auth.txt | 6 +- docs/topics/db/examples/many_to_many.txt | 4 +- docs/topics/db/queries.txt | 20 +++--- docs/topics/db/sql.txt | 8 +-- docs/topics/forms/formsets.txt | 16 ++--- docs/topics/forms/media.txt | 16 ++--- docs/topics/forms/modelforms.txt | 4 +- docs/topics/http/urls.txt | 2 +- docs/topics/i18n/translation.txt | 2 +- docs/topics/install.txt | 2 +- docs/topics/signals.txt | 4 +- docs/topics/signing.txt | 2 +- extras/csrf_migration_helper.py | 32 ++++----- .../management/commands/app_command.py | 2 +- .../management/commands/base_command.py | 2 +- .../management/commands/label_command.py | 2 +- .../management/commands/noargs_command.py | 2 +- tests/regressiontests/test_runner/tests.py | 2 +- tests/runtests.py | 36 +++++----- 61 files changed, 310 insertions(+), 310 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 : - >>> print 'foo\n\nbar\n' + >>> print('foo\n\nbar\n') foo 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): diff --git a/docs/_ext/applyxrefs.py b/docs/_ext/applyxrefs.py index 3809088c1f..14d18bd856 100644 --- a/docs/_ext/applyxrefs.py +++ b/docs/_ext/applyxrefs.py @@ -77,12 +77,12 @@ def main(argv=None): target_found, lines = has_target(fn) if not target_found: if testing: - print '%s: %s' % (fn, lines[0]), + print('%s: %s' % (fn, lines[0])) else: - print "Adding xref to %s" % fn + print("Adding xref to %s" % fn) process_file(fn, lines) else: print "Skipping %s: already has a xref" % fn if __name__ == '__main__': - sys.exit(main()) \ No newline at end of file + sys.exit(main()) diff --git a/docs/_ext/literals_to_xrefs.py b/docs/_ext/literals_to_xrefs.py index 569193c72d..d1487ca729 100644 --- a/docs/_ext/literals_to_xrefs.py +++ b/docs/_ext/literals_to_xrefs.py @@ -136,10 +136,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') """ color_names = ('black', 'red', 'green', 'yellow', 'blue', 'magenta', 'cyan', 'white') foreground = dict([(color_names[x], '3%s' % x) for x in range(8)]) @@ -168,4 +168,4 @@ if __name__ == '__main__': try: fixliterals(sys.argv[1]) except (KeyboardInterrupt, SystemExit): - print \ No newline at end of file + print('') diff --git a/docs/howto/custom-model-fields.txt b/docs/howto/custom-model-fields.txt index 7f0ea3799d..5c2fed3b34 100644 --- a/docs/howto/custom-model-fields.txt +++ b/docs/howto/custom-model-fields.txt @@ -55,7 +55,7 @@ We'd like to be able to do things like this in our models (we assume the ``hand`` attribute on the model is an instance of ``Hand``):: example = MyModel.objects.get(pk=1) - print example.hand.north + print(example.hand.north) new_hand = Hand(north, east, south, west) example.hand = new_hand diff --git a/docs/intro/install.txt b/docs/intro/install.txt index 95f7b27396..41339b5f11 100644 --- a/docs/intro/install.txt +++ b/docs/intro/install.txt @@ -83,7 +83,7 @@ To verify that Django can be seen by Python, type ``python`` from your shell. Then at the Python prompt, try to import Django:: >>> import django - >>> print django.get_version() + >>> print(django.get_version()) 1.4 diff --git a/docs/ref/contrib/gis/db-api.txt b/docs/ref/contrib/gis/db-api.txt index 45698dd669..4cf65e513e 100644 --- a/docs/ref/contrib/gis/db-api.txt +++ b/docs/ref/contrib/gis/db-api.txt @@ -76,7 +76,7 @@ transform procedure:: >>> z = Zipcode(code=78212, poly=poly_3084) >>> z.save() >>> from django.db import connection - >>> print connection.queries[-1]['sql'] # printing the last SQL statement executed (requires DEBUG=True) + >>> print(connection.queries[-1]['sql']) # printing the last SQL statement executed (requires DEBUG=True) INSERT INTO "geoapp_zipcode" ("code", "poly") VALUES (78212, ST_Transform(ST_GeomFromWKB('\\001 ... ', 3084), 4326)) Thus, geometry parameters may be passed in using the ``GEOSGeometry`` object, WKT diff --git a/docs/ref/contrib/gis/gdal.txt b/docs/ref/contrib/gis/gdal.txt index 77c7c07618..5cd6187c6c 100644 --- a/docs/ref/contrib/gis/gdal.txt +++ b/docs/ref/contrib/gis/gdal.txt @@ -114,7 +114,7 @@ __ http://www.gdal.org/ogr/ogr_formats.html information about each layer in a :class:`DataSource`:: >>> for layer in ds: - ... print 'Layer "%s": %i %ss' % (layer.name, len(layer), layer.geom_type.name) + ... print('Layer "%s": %i %ss' % (layer.name, len(layer), layer.geom_type.name)) ... Layer "cities": 3 Points @@ -200,7 +200,7 @@ __ http://www.gdal.org/ogr/ogr_formats.html Property that returns the :class:`SpatialReference` associated with this layer:: - >>> print layer.srs + >>> print(layer.srs) GEOGCS["GCS_WGS_1984", DATUM["WGS_1984", SPHEROID["WGS_1984",6378137,298.257223563]], @@ -220,9 +220,9 @@ __ http://www.gdal.org/ogr/ogr_formats.html other than ``None``, only features that intersect the filter will be returned when iterating over the layer:: - >>> print layer.spatial_filter + >>> print(layer.spatial_filter) None - >>> print len(layer) + >>> print(len(layer)) 3 >>> [feat.get('Name') for feat in layer] ['Pueblo', 'Lawrence', 'Houston'] @@ -814,7 +814,7 @@ systems and coordinate transformation:: >>> 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 + >>> print(gt1 == 3, gt1 == 'Polygon') # Equivalence works w/non-OGRGeomType objects True True .. attribute:: name @@ -927,19 +927,19 @@ Coordinate System Objects >>> 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 symbol. + >>> print(srs['UNIT|AUTHORITY']) # For the units authority, have to use the pipe symbol. EPSG - >>> print srs['UNIT|AUTHORITY', 1] # The authority value for the units + >>> print(srs['UNIT|AUTHORITY', 1]) # The authority value for the units 9122 .. method:: attr_value(target, index=0) diff --git a/docs/ref/contrib/gis/geoquerysets.txt b/docs/ref/contrib/gis/geoquerysets.txt index 832f21e3e7..5bc9ab1f64 100644 --- a/docs/ref/contrib/gis/geoquerysets.txt +++ b/docs/ref/contrib/gis/geoquerysets.txt @@ -714,7 +714,7 @@ the distance from the `Tasmanian`__ city of Hobart to every other :class:`PointField` in the ``AustraliaCity`` queryset is calculated:: >>> pnt = AustraliaCity.objects.get(name='Hobart').point - >>> for city in AustraliaCity.objects.distance(pnt): print city.name, city.distance + >>> for city in AustraliaCity.objects.distance(pnt): print(city.name, city.distance) Wollongong 990071.220408 m Shellharbour 972804.613941 m Thirroul 1002334.36351 m @@ -874,9 +874,9 @@ Example:: >>> qs = Zipcode.objects.all().transform() # Transforms to WGS84 >>> qs = Zipcode.objects.all().transform(32140) # Transforming to "NAD83 / Texas South Central" - >>> print qs[0].poly.srid + >>> print(qs[0].poly.srid) 32140 - >>> print qs[0].poly + >>> print(qs[0].poly) POLYGON ((234055.1698884720099159 4937796.9232223574072123 ... ``translate`` @@ -990,7 +990,7 @@ Attaches a ``gml`` attribute to every model in the queryset that contains the Example:: >>> qs = Zipcode.objects.all().gml() - >>> print qs[0].gml + >>> print(qs[0].gml) -147.78711,70.245363 ... -147.78711,70.245363 ===================== ===================================================== @@ -1023,7 +1023,7 @@ necessary. Example:: >>> qs = Zipcode.objects.all().kml() - >>> print qs[0].kml + >>> print(qs[0].kml) -103.04135,36.217596,0 ... -103.04135,36.217596,0 ===================== ===================================================== @@ -1128,7 +1128,7 @@ lower left coordinate and the upper right coordinate. Example:: >>> qs = City.objects.filter(name__in=('Houston', 'Dallas')) - >>> print qs.extent() + >>> print(qs.extent()) (-96.8016128540039, 29.7633724212646, -95.3631439208984, 32.782058715820) ``extent3d`` @@ -1146,7 +1146,7 @@ the lower left coordinate and upper right coordinate. Example:: >>> qs = City.objects.filter(name__in=('Houston', 'Dallas')) - >>> print qs.extent3d() + >>> print(qs.extent3d()) (-96.8016128540039, 29.7633724212646, 0, -95.3631439208984, 32.782058715820, 0) ``make_line`` @@ -1161,7 +1161,7 @@ Returns a ``LineString`` constructed from the point field geometries in the Example:: - >>> print City.objects.filter(name__in=('Houston', 'Dallas')).make_line() + >>> print(City.objects.filter(name__in=('Houston', 'Dallas')).make_line()) LINESTRING (-95.3631510000000020 29.7633739999999989, -96.8016109999999941 32.7820570000000018) ``unionagg`` diff --git a/docs/ref/contrib/gis/geos.txt b/docs/ref/contrib/gis/geos.txt index 9fceda32d0..d3d9fe4442 100644 --- a/docs/ref/contrib/gis/geos.txt +++ b/docs/ref/contrib/gis/geos.txt @@ -231,7 +231,7 @@ Property that may be used to retrieve or set the SRID associated with the geometry. For example:: >>> pnt = Point(5, 23) - >>> print pnt.srid + >>> print(pnt.srid) None >>> pnt.srid = 4326 >>> pnt.srid diff --git a/docs/ref/contrib/gis/layermapping.txt b/docs/ref/contrib/gis/layermapping.txt index b0fb29e77a..dd0a41cbc0 100644 --- a/docs/ref/contrib/gis/layermapping.txt +++ b/docs/ref/contrib/gis/layermapping.txt @@ -39,13 +39,13 @@ Example >>> from django.contrib.gis.gdal import DataSource >>> ds = DataSource('test_poly.shp') >>> layer = ds[0] - >>> print layer.fields # Exploring the fields in the layer, we only want the 'str' field. + >>> print(layer.fields) # Exploring the fields in the layer, we only want the 'str' field. ['float', 'int', 'str'] - >>> print len(layer) # getting the number of features in the layer (should be 3) + >>> print(len(layer)) # getting the number of features in the layer (should be 3) 3 - >>> print layer.geom_type # Should be 'Polygon' + >>> print(layer.geom_type) # Should be 'Polygon' Polygon - >>> print layer.srs # WGS84 in WKT + >>> print(layer.srs) # WGS84 in WKT GEOGCS["GCS_WGS_1984", DATUM["WGS_1984", SPHEROID["WGS_1984",6378137,298.257223563]], diff --git a/docs/ref/contrib/gis/measure.txt b/docs/ref/contrib/gis/measure.txt index 6971788b4e..699677a50c 100644 --- a/docs/ref/contrib/gis/measure.txt +++ b/docs/ref/contrib/gis/measure.txt @@ -22,41 +22,41 @@ instantiated in units of kilometers (``km``) and miles (``mi``):: >>> from django.contrib.gis.measure import Distance, D >>> d1 = Distance(km=5) - >>> print d1 + >>> print(d1) 5.0 km >>> d2 = D(mi=5) # `D` is an alias for `Distance` - >>> print d2 + >>> print(d2) 5.0 mi Conversions are easy, just access the preferred unit attribute to get a converted distance quantity:: - >>> print d1.mi # Converting 5 kilometers to miles + >>> print(d1.mi) # Converting 5 kilometers to miles 3.10685596119 - >>> print d2.km # Converting 5 miles to kilometers + >>> print(d2.km) # Converting 5 miles to kilometers 8.04672 Moreover, arithmetic operations may be performed between the distance objects:: - >>> print d1 + d2 # Adding 5 miles to 5 kilometers + >>> print(d1 + d2) # Adding 5 miles to 5 kilometers 13.04672 km - >>> print d2 - d1 # Subtracting 5 kilometers from 5 miles + >>> print(d2 - d1) # Subtracting 5 kilometers from 5 miles 1.89314403881 mi Two :class:`Distance` objects multiplied together will yield an :class:`Area` object, which uses squared units of measure:: >>> a = d1 * d2 # Returns an Area object. - >>> print a + >>> print(a) 40.2336 sq_km To determine what the attribute abbreviation of a unit is, the ``unit_attname`` class method may be used:: - >>> print Distance.unit_attname('US Survey Foot') + >>> print(Distance.unit_attname('US Survey Foot')) survey_ft - >>> print Distance.unit_attname('centimeter') + >>> print(Distance.unit_attname('centimeter')) cm .. _supported_units: @@ -127,7 +127,7 @@ Measurement API Returns the distance value in units corresponding to the given unit attribute. For example:: - >>> print dist.km + >>> print(dist.km) 8.04672 .. classmethod:: unit_attname(unit_name) @@ -159,7 +159,7 @@ Measurement API Returns the area value in units corresponding to the given unit attribute. For example:: - >>> print a.sq_km + >>> print(a.sq_km) 12.949940551680001 .. classmethod:: unit_attname(unit_name) diff --git a/docs/ref/contrib/gis/tutorial.txt b/docs/ref/contrib/gis/tutorial.txt index 34014d7be4..395eac1821 100644 --- a/docs/ref/contrib/gis/tutorial.txt +++ b/docs/ref/contrib/gis/tutorial.txt @@ -362,24 +362,24 @@ Now, the world borders shapefile may be opened using GeoDjango's >>> from django.contrib.gis.gdal import DataSource >>> ds = DataSource(world_shp) - >>> print ds + >>> print(ds) / ... /geodjango/world/data/TM_WORLD_BORDERS-0.3.shp (ESRI Shapefile) Data source objects can have different layers of geospatial features; however, shapefiles are only allowed to have one layer:: - >>> print len(ds) + >>> print(len(ds)) 1 >>> lyr = ds[0] - >>> print lyr + >>> print(lyr) TM_WORLD_BORDERS-0.3 You can see what the geometry type of the layer is and how many features it contains:: - >>> print lyr.geom_type + >>> print(lyr.geom_type) Polygon - >>> print len(lyr) + >>> print(len(lyr)) 246 .. note:: @@ -397,7 +397,7 @@ system associated with it -- if it does, the ``srs`` attribute will return a :class:`~django.contrib.gis.gdal.SpatialReference` object:: >>> srs = lyr.srs - >>> print srs + >>> print(srs) GEOGCS["GCS_WGS_1984", DATUM["WGS_1984", SPHEROID["WGS_1984",6378137.0,298.257223563]], @@ -413,7 +413,7 @@ latitude. In addition, shapefiles also support attribute fields that may contain additional data. Here are the fields on the World Borders layer: - >>> print lyr.fields + >>> print(lyr.fields) ['FIPS', 'ISO2', 'ISO3', 'UN', 'NAME', 'AREA', 'POP2005', 'REGION', 'SUBREGION', 'LON', 'LAT'] Here we are examining the OGR types (e.g., whether a field is an integer or @@ -428,7 +428,7 @@ feature's attribute fields (whose **values** are accessed via ``get()`` method):: >>> for feat in lyr: - ... print feat.get('NAME'), feat.geom.num_points + ... print(feat.get('NAME'), feat.geom.num_points) ... Guernsey 18 Jersey 26 @@ -443,16 +443,16 @@ method):: And individual features may be retrieved by their feature ID:: >>> feat = lyr[234] - >>> print feat.get('NAME') + >>> print(feat.get('NAME')) San Marino Here the boundary geometry for San Marino is extracted and looking exported to WKT and GeoJSON:: >>> geom = feat.geom - >>> print geom.wkt + >>> print(geom.wkt) POLYGON ((12.415798 43.957954,12.450554 ... - >>> print geom.json + >>> print(geom.json) { "type": "Polygon", "coordinates": [ [ [ 12.415798, 43.957954 ], [ 12.450554, 43.979721 ], ... @@ -659,7 +659,7 @@ in transformation SQL, allowing the developer to work at a higher level of abstraction:: >>> qs = WorldBorder.objects.filter(mpoly__intersects=pnt) - >>> print qs.query # Generating the SQL + >>> print(qs.query) # Generating the SQL SELECT "world_worldborder"."id", "world_worldborder"."name", "world_worldborder"."area", "world_worldborder"."pop2005", "world_worldborder"."fips", "world_worldborder"."iso2", "world_worldborder"."iso3", "world_worldborder"."un", "world_worldborder"."region", diff --git a/docs/ref/contrib/syndication.txt b/docs/ref/contrib/syndication.txt index 754ac5843b..76c176e7b3 100644 --- a/docs/ref/contrib/syndication.txt +++ b/docs/ref/contrib/syndication.txt @@ -891,7 +891,7 @@ For example, to create an Atom 1.0 feed and print it to standard output:: ... link=u"http://www.example.com/entries/1/", ... pubdate=datetime.now(), ... description=u"

Today I had a Vienna Beef hot dog. It was pink, plump and perfect.

") - >>> print f.writeString('UTF-8') + >>> print(f.writeString('UTF-8')) ... diff --git a/docs/ref/forms/api.txt b/docs/ref/forms/api.txt index 86b6bb453e..a866fc550c 100644 --- a/docs/ref/forms/api.txt +++ b/docs/ref/forms/api.txt @@ -161,7 +161,7 @@ and the latter gets precedence:: ... url = forms.URLField() ... comment = forms.CharField() >>> f = CommentForm(initial={'name': 'instance'}, auto_id=False) - >>> print f + >>> print(f) Name: Url: Comment: @@ -266,7 +266,7 @@ The second task of a ``Form`` object is to render itself as HTML. To do so, simply ``print`` it:: >>> f = ContactForm() - >>> print f + >>> print(f) @@ -283,7 +283,7 @@ include ``checked="checked"`` if appropriate:: ... 'sender': 'foo@example.com', ... 'cc_myself': True} >>> f = ContactForm(data) - >>> print f + >>> print(f) @@ -331,7 +331,7 @@ a form object, and each rendering method returns a Unicode object. >>> f = ContactForm() >>> f.as_p() u'

\n

\n

\n

' - >>> print f.as_p() + >>> print(f.as_p())

@@ -350,7 +350,7 @@ a form object, and each rendering method returns a Unicode object. >>> f = ContactForm() >>> f.as_ul() u'
  • \n
  • \n
  • \n
  • ' - >>> print f.as_ul() + >>> print(f.as_ul())
  • @@ -368,7 +368,7 @@ a form object, and each rendering method returns a Unicode object. >>> f = ContactForm() >>> f.as_table() u'\n\n\n' - >>> print f.as_table() + >>> print(f.as_table()) @@ -398,7 +398,7 @@ Once you've done that, rows will be given ``"error"`` and/or ``"required"`` classes, as needed. The HTML will look something like:: >>> f = ContactForm(data) - >>> print f.as_table() + >>> print(f.as_table()) ... ... ... @@ -426,17 +426,17 @@ If ``auto_id`` is ``False``, then the form output will not include ``