From 895dc880ebef46c9577c6908daf283248685f73c Mon Sep 17 00:00:00 2001 From: Michael Hall Date: Sat, 13 Dec 2014 06:04:36 -0700 Subject: [PATCH] Fixed #23812 -- Changed django.utils.six.moves.xrange imports to range --- django/contrib/gis/gdal/datasource.py | 4 ++-- django/contrib/gis/gdal/feature.py | 6 +++--- django/contrib/gis/gdal/geometries.py | 20 ++++++++++---------- django/contrib/gis/gdal/layer.py | 14 +++++++------- django/contrib/gis/gdal/tests/test_geom.py | 10 +++++----- django/contrib/gis/geos/collections.py | 4 ++-- django/contrib/gis/geos/coordseq.py | 8 ++++---- django/contrib/gis/geos/linestring.py | 10 +++++----- django/contrib/gis/geos/mutable_list.py | 14 +++++++------- django/contrib/gis/geos/point.py | 4 ++-- django/contrib/gis/geos/polygon.py | 8 ++++---- django/contrib/gis/geos/prototypes/misc.py | 4 ++-- django/contrib/gis/geos/tests/test_geos.py | 22 +++++++++++----------- django/contrib/gis/maps/google/gmap.py | 4 ++-- django/contrib/gis/maps/google/zoom.py | 6 +++--- django/contrib/sessions/backends/cache.py | 4 ++-- django/db/models/lookups.py | 4 ++-- django/db/models/sql/where.py | 4 ++-- django/dispatch/dispatcher.py | 4 ++-- django/forms/formsets.py | 4 ++-- django/utils/crypto.py | 4 ++-- django/utils/ipv6.py | 4 ++-- tests/backends/tests.py | 4 ++-- tests/delete/tests.py | 8 ++++---- tests/middleware/tests.py | 4 ++-- tests/model_forms/models.py | 3 ++- tests/utils_tests/test_baseconv.py | 4 ++-- 27 files changed, 95 insertions(+), 94 deletions(-) diff --git a/django/contrib/gis/gdal/datasource.py b/django/contrib/gis/gdal/datasource.py index d8f4438434f..bff8ffaa75e 100644 --- a/django/contrib/gis/gdal/datasource.py +++ b/django/contrib/gis/gdal/datasource.py @@ -47,7 +47,7 @@ from django.contrib.gis.gdal.prototypes import ds as capi from django.utils.encoding import force_bytes, force_text from django.utils import six -from django.utils.six.moves import xrange +from django.utils.six.moves import range # For more information, see the OGR C API source code: @@ -98,7 +98,7 @@ class DataSource(GDALBase): def __iter__(self): "Allows for iteration over the layers in a data source." - for i in xrange(self.layer_count): + for i in range(self.layer_count): yield self[i] def __getitem__(self, index): diff --git a/django/contrib/gis/gdal/feature.py b/django/contrib/gis/gdal/feature.py index 2184aeb708a..afed7aefff9 100644 --- a/django/contrib/gis/gdal/feature.py +++ b/django/contrib/gis/gdal/feature.py @@ -9,7 +9,7 @@ from django.contrib.gis.gdal.prototypes import ds as capi, geom as geom_api from django.utils.encoding import force_bytes, force_text from django.utils import six -from django.utils.six.moves import xrange +from django.utils.six.moves import range # For more information, see the OGR C API source code: @@ -54,7 +54,7 @@ class Feature(GDALBase): def __iter__(self): "Iterates over each field in the Feature." - for i in xrange(self.num_fields): + for i in range(self.num_fields): yield self[i] def __len__(self): @@ -94,7 +94,7 @@ class Feature(GDALBase): def fields(self): "Returns a list of fields in the Feature." return [capi.get_field_name(capi.get_field_defn(self._layer._ldefn, i)) - for i in xrange(self.num_fields)] + for i in range(self.num_fields)] @property def geom(self): diff --git a/django/contrib/gis/gdal/geometries.py b/django/contrib/gis/gdal/geometries.py index 0006923e426..918f4e68a2c 100644 --- a/django/contrib/gis/gdal/geometries.py +++ b/django/contrib/gis/gdal/geometries.py @@ -57,7 +57,7 @@ from django.contrib.gis.gdal.prototypes import geom as capi, srs as srs_api from django.contrib.gis.geometry.regex import hex_regex, wkt_regex, json_regex from django.utils import six -from django.utils.six.moves import xrange +from django.utils.six.moves import range # For more information, see the OGR C API source code: # http://www.gdal.org/ogr/ogr__api_8h.html @@ -546,7 +546,7 @@ class LineString(OGRGeometry): def __iter__(self): "Iterates over each point in the LineString." - for i in xrange(self.point_count): + for i in range(self.point_count): yield self[i] def __len__(self): @@ -556,7 +556,7 @@ class LineString(OGRGeometry): @property def tuple(self): "Returns the tuple representation of this LineString." - return tuple(self[i] for i in xrange(len(self))) + return tuple(self[i] for i in range(len(self))) coords = tuple def _listarr(self, func): @@ -564,7 +564,7 @@ class LineString(OGRGeometry): Internal routine that returns a sequence (list) corresponding with the given function. """ - return [func(self.ptr, i) for i in xrange(len(self))] + return [func(self.ptr, i) for i in range(len(self))] @property def x(self): @@ -596,7 +596,7 @@ class Polygon(OGRGeometry): def __iter__(self): "Iterates through each ring in the Polygon." - for i in xrange(self.geom_count): + for i in range(self.geom_count): yield self[i] def __getitem__(self, index): @@ -616,14 +616,14 @@ class Polygon(OGRGeometry): @property def tuple(self): "Returns a tuple of LinearRing coordinate tuples." - return tuple(self[i].tuple for i in xrange(self.geom_count)) + return tuple(self[i].tuple for i in range(self.geom_count)) coords = tuple @property def point_count(self): "The number of Points in this Polygon." # Summing up the number of points in each ring of the Polygon. - return sum(self[i].point_count for i in xrange(self.geom_count)) + return sum(self[i].point_count for i in range(self.geom_count)) @property def centroid(self): @@ -647,7 +647,7 @@ class GeometryCollection(OGRGeometry): def __iter__(self): "Iterates over each Geometry." - for i in xrange(self.geom_count): + for i in range(self.geom_count): yield self[i] def __len__(self): @@ -672,12 +672,12 @@ class GeometryCollection(OGRGeometry): def point_count(self): "The number of Points in this Geometry Collection." # Summing up the number of points in each geometry in this collection - return sum(self[i].point_count for i in xrange(self.geom_count)) + return sum(self[i].point_count for i in range(self.geom_count)) @property def tuple(self): "Returns a tuple representation of this Geometry Collection." - return tuple(self[i].tuple for i in xrange(self.geom_count)) + return tuple(self[i].tuple for i in range(self.geom_count)) coords = tuple diff --git a/django/contrib/gis/gdal/layer.py b/django/contrib/gis/gdal/layer.py index 33fb3cb969d..600a335bfe4 100644 --- a/django/contrib/gis/gdal/layer.py +++ b/django/contrib/gis/gdal/layer.py @@ -16,7 +16,7 @@ from django.contrib.gis.gdal.prototypes import ds as capi, geom as geom_api, srs from django.utils.encoding import force_bytes, force_text from django.utils import six -from django.utils.six.moves import xrange +from django.utils.six.moves import range # For more information, see the OGR C API source code: @@ -54,7 +54,7 @@ class Layer(GDALBase): elif isinstance(index, slice): # A slice was given start, stop, stride = index.indices(self.num_feat) - return [self._make_feature(fid) for fid in xrange(start, stop, stride)] + return [self._make_feature(fid) for fid in range(start, stop, stride)] else: raise TypeError('Integers and slices may only be used when indexing OGR Layers.') @@ -62,7 +62,7 @@ class Layer(GDALBase): "Iterates over each Feature in the Layer." # ResetReading() must be called before iteration is to begin. capi.reset_reading(self._ptr) - for i in xrange(self.num_feat): + for i in range(self.num_feat): yield Feature(capi.get_next_feature(self._ptr), self) def __len__(self): @@ -141,7 +141,7 @@ class Layer(GDALBase): """ return [force_text(capi.get_field_name(capi.get_field_defn(self._ldefn, i)), self._ds.encoding, strings_only=True) - for i in xrange(self.num_fields)] + for i in range(self.num_fields)] @property def field_types(self): @@ -152,19 +152,19 @@ class Layer(GDALBase): fields. """ return [OGRFieldTypes[capi.get_field_type(capi.get_field_defn(self._ldefn, i))] - for i in xrange(self.num_fields)] + for i in range(self.num_fields)] @property def field_widths(self): "Returns a list of the maximum field widths for the features." return [capi.get_field_width(capi.get_field_defn(self._ldefn, i)) - for i in xrange(self.num_fields)] + for i in range(self.num_fields)] @property def field_precisions(self): "Returns the field precisions for the features." return [capi.get_field_precision(capi.get_field_defn(self._ldefn, i)) - for i in xrange(self.num_fields)] + for i in range(self.num_fields)] def _get_spatial_filter(self): try: diff --git a/django/contrib/gis/gdal/tests/test_geom.py b/django/contrib/gis/gdal/tests/test_geom.py index bf028d19db1..08ff509dfd6 100644 --- a/django/contrib/gis/gdal/tests/test_geom.py +++ b/django/contrib/gis/gdal/tests/test_geom.py @@ -9,7 +9,7 @@ from unittest import skipUnless from django.contrib.gis.gdal import HAS_GDAL from django.contrib.gis.geometry.test_data import TestDataMixin -from django.utils.six.moves import xrange +from django.utils.six.moves import range if HAS_GDAL: from django.contrib.gis.gdal import (OGRGeometry, OGRGeomType, @@ -355,7 +355,7 @@ class OGRGeomTest(unittest.TestCase, TestDataMixin): def test10_difference(self): "Testing difference()." - for i in xrange(len(self.geometries.topology_geoms)): + for i in range(len(self.geometries.topology_geoms)): a = OGRGeometry(self.geometries.topology_geoms[i].wkt_a) b = OGRGeometry(self.geometries.topology_geoms[i].wkt_b) d1 = OGRGeometry(self.geometries.diff_geoms[i].wkt) @@ -367,7 +367,7 @@ class OGRGeomTest(unittest.TestCase, TestDataMixin): def test11_intersection(self): "Testing intersects() and intersection()." - for i in xrange(len(self.geometries.topology_geoms)): + for i in range(len(self.geometries.topology_geoms)): a = OGRGeometry(self.geometries.topology_geoms[i].wkt_a) b = OGRGeometry(self.geometries.topology_geoms[i].wkt_b) i1 = OGRGeometry(self.geometries.intersect_geoms[i].wkt) @@ -380,7 +380,7 @@ class OGRGeomTest(unittest.TestCase, TestDataMixin): def test12_symdifference(self): "Testing sym_difference()." - for i in xrange(len(self.geometries.topology_geoms)): + for i in range(len(self.geometries.topology_geoms)): a = OGRGeometry(self.geometries.topology_geoms[i].wkt_a) b = OGRGeometry(self.geometries.topology_geoms[i].wkt_b) d1 = OGRGeometry(self.geometries.sdiff_geoms[i].wkt) @@ -392,7 +392,7 @@ class OGRGeomTest(unittest.TestCase, TestDataMixin): def test13_union(self): "Testing union()." - for i in xrange(len(self.geometries.topology_geoms)): + for i in range(len(self.geometries.topology_geoms)): a = OGRGeometry(self.geometries.topology_geoms[i].wkt_a) b = OGRGeometry(self.geometries.topology_geoms[i].wkt_b) u1 = OGRGeometry(self.geometries.union_geoms[i].wkt) diff --git a/django/contrib/gis/geos/collections.py b/django/contrib/gis/geos/collections.py index 483cb6f4050..83f57cbd18f 100644 --- a/django/contrib/gis/geos/collections.py +++ b/django/contrib/gis/geos/collections.py @@ -9,7 +9,7 @@ from django.contrib.gis.geos.linestring import LineString, LinearRing from django.contrib.gis.geos.point import Point from django.contrib.gis.geos.polygon import Polygon from django.contrib.gis.geos import prototypes as capi -from django.utils.six.moves import xrange +from django.utils.six.moves import range class GeometryCollection(GEOSGeometry): @@ -42,7 +42,7 @@ class GeometryCollection(GEOSGeometry): def __iter__(self): "Iterates over each Geometry in the Collection." - for i in xrange(len(self)): + for i in range(len(self)): yield self[i] def __len__(self): diff --git a/django/contrib/gis/geos/coordseq.py b/django/contrib/gis/geos/coordseq.py index c0e455a5c6c..c238d4cda51 100644 --- a/django/contrib/gis/geos/coordseq.py +++ b/django/contrib/gis/geos/coordseq.py @@ -8,7 +8,7 @@ from django.contrib.gis.geos.base import GEOSBase, numpy from django.contrib.gis.geos.error import GEOSException, GEOSIndexError from django.contrib.gis.geos.libgeos import CS_PTR from django.contrib.gis.geos import prototypes as capi -from django.utils.six.moves import xrange +from django.utils.six.moves import range class GEOSCoordSeq(GEOSBase): @@ -26,7 +26,7 @@ class GEOSCoordSeq(GEOSBase): def __iter__(self): "Iterates over each point in the coordinate sequence." - for i in xrange(self.size): + for i in range(self.size): yield self[i] def __len__(self): @@ -151,7 +151,7 @@ class GEOSCoordSeq(GEOSBase): else: substr = '%s,%s,0 ' return '%s' % \ - ''.join(substr % self[i] for i in xrange(len(self))).strip() + ''.join(substr % self[i] for i in range(len(self))).strip() @property def tuple(self): @@ -160,4 +160,4 @@ class GEOSCoordSeq(GEOSBase): if n == 1: return self[0] else: - return tuple(self[i] for i in xrange(n)) + return tuple(self[i] for i in range(n)) diff --git a/django/contrib/gis/geos/linestring.py b/django/contrib/gis/geos/linestring.py index 72f766310ec..829ab48945e 100644 --- a/django/contrib/gis/geos/linestring.py +++ b/django/contrib/gis/geos/linestring.py @@ -4,7 +4,7 @@ from django.contrib.gis.geos.error import GEOSException from django.contrib.gis.geos.geometry import GEOSGeometry from django.contrib.gis.geos.point import Point from django.contrib.gis.geos import prototypes as capi -from django.utils.six.moves import xrange +from django.utils.six.moves import range class LineString(GEOSGeometry): @@ -40,7 +40,7 @@ class LineString(GEOSGeometry): raise TypeError('Cannot initialize on empty sequence.') self._checkdim(ndim) # Incrementing through each of the coordinates and verifying - for i in xrange(1, ncoords): + for i in range(1, ncoords): if not isinstance(coords[i], (tuple, list, Point)): raise TypeError('each coordinate should be a sequence (list or tuple)') if len(coords[i]) != ndim: @@ -61,7 +61,7 @@ class LineString(GEOSGeometry): # set the points using GEOSCoordSeq.__setitem__(). cs = GEOSCoordSeq(capi.create_cs(ncoords, ndim), z=bool(ndim == 3)) - for i in xrange(ncoords): + for i in range(ncoords): if numpy_coords: cs[i] = coords[i, :] elif isinstance(coords[i], Point): @@ -78,7 +78,7 @@ class LineString(GEOSGeometry): def __iter__(self): "Allows iteration over this LineString." - for i in xrange(len(self)): + for i in range(len(self)): yield self[i] def __len__(self): @@ -128,7 +128,7 @@ class LineString(GEOSGeometry): Internal routine that returns a sequence (list) corresponding with the given function. Will return a numpy array if possible. """ - lst = [func(i) for i in xrange(len(self))] + lst = [func(i) for i in range(len(self))] if numpy: return numpy.array(lst) # ARRRR! else: diff --git a/django/contrib/gis/geos/mutable_list.py b/django/contrib/gis/geos/mutable_list.py index d9108d6c586..f01bc4275f6 100644 --- a/django/contrib/gis/geos/mutable_list.py +++ b/django/contrib/gis/geos/mutable_list.py @@ -10,7 +10,7 @@ Author: Aryeh Leib Taurog. """ from django.utils.functional import total_ordering from django.utils import six -from django.utils.six.moves import xrange +from django.utils.six.moves import range @total_ordering @@ -78,7 +78,7 @@ class ListMixin(object): def __getitem__(self, index): "Get the item(s) at the specified index/slice." if isinstance(index, slice): - return [self._get_single_external(i) for i in xrange(*index.indices(len(self)))] + return [self._get_single_external(i) for i in range(*index.indices(len(self)))] else: index = self._checkindex(index) return self._get_single_external(index) @@ -98,7 +98,7 @@ class ListMixin(object): newLen = origLen - len(indexRange) newItems = (self._get_single_internal(i) - for i in xrange(origLen) + for i in range(origLen) if i not in indexRange) self._rebuild(newLen, newItems) @@ -114,7 +114,7 @@ class ListMixin(object): def __iter__(self): "Iterate over the items in the list" - for i in xrange(len(self)): + for i in range(len(self)): yield self[i] ### Special methods for arithmetic operations ### @@ -187,7 +187,7 @@ class ListMixin(object): def index(self, val): "Standard list index method" - for i in xrange(0, len(self)): + for i in range(0, len(self)): if self[i] == val: return i raise ValueError('%s not found in object' % str(val)) @@ -294,7 +294,7 @@ class ListMixin(object): newVals = dict(zip(indexList, valueList)) def newItems(): - for i in xrange(newLen): + for i in range(newLen): if i in newVals: yield newVals[i] else: @@ -321,7 +321,7 @@ class ListMixin(object): newLen = origLen - stop + start + len(valueList) def newItems(): - for i in xrange(origLen + 1): + for i in range(origLen + 1): if i == start: for val in valueList: yield val diff --git a/django/contrib/gis/geos/point.py b/django/contrib/gis/geos/point.py index 5fcf1bb407a..2cc5c13683b 100644 --- a/django/contrib/gis/geos/point.py +++ b/django/contrib/gis/geos/point.py @@ -3,7 +3,7 @@ from django.contrib.gis.geos.error import GEOSException from django.contrib.gis.geos.geometry import GEOSGeometry from django.contrib.gis.geos import prototypes as capi from django.utils import six -from django.utils.six.moves import xrange +from django.utils.six.moves import range class Point(GEOSGeometry): @@ -71,7 +71,7 @@ class Point(GEOSGeometry): def __iter__(self): "Allows iteration over coordinates of this Point." - for i in xrange(len(self)): + for i in range(len(self)): yield self[i] def __len__(self): diff --git a/django/contrib/gis/geos/polygon.py b/django/contrib/gis/geos/polygon.py index ac4cddc2473..38b533df8f4 100644 --- a/django/contrib/gis/geos/polygon.py +++ b/django/contrib/gis/geos/polygon.py @@ -4,7 +4,7 @@ from django.contrib.gis.geos.libgeos import get_pointer_arr, GEOM_PTR from django.contrib.gis.geos.linestring import LinearRing from django.contrib.gis.geos import prototypes as capi from django.utils import six -from django.utils.six.moves import xrange +from django.utils.six.moves import range class Polygon(GEOSGeometry): @@ -49,7 +49,7 @@ class Polygon(GEOSGeometry): def __iter__(self): "Iterates over each ring in the polygon." - for i in xrange(len(self)): + for i in range(len(self)): yield self[i] def __len__(self): @@ -165,12 +165,12 @@ class Polygon(GEOSGeometry): @property def tuple(self): "Gets the tuple for each ring in this Polygon." - return tuple(self[i].tuple for i in xrange(len(self))) + return tuple(self[i].tuple for i in range(len(self))) coords = tuple @property def kml(self): "Returns the KML representation of this Polygon." inner_kml = ''.join("%s" % self[i + 1].kml - for i in xrange(self.num_interior_rings)) + for i in range(self.num_interior_rings)) return "%s%s" % (self[0].kml, inner_kml) diff --git a/django/contrib/gis/geos/prototypes/misc.py b/django/contrib/gis/geos/prototypes/misc.py index a8bb3cbd582..0e62e916b04 100644 --- a/django/contrib/gis/geos/prototypes/misc.py +++ b/django/contrib/gis/geos/prototypes/misc.py @@ -7,7 +7,7 @@ from django.contrib.gis.geos.libgeos import GEOM_PTR from django.contrib.gis.geos.prototypes.errcheck import check_dbl, check_string from django.contrib.gis.geos.prototypes.geom import geos_char_p from django.contrib.gis.geos.prototypes.threadsafe import GEOSFunc -from django.utils.six.moves import xrange +from django.utils.six.moves import range __all__ = ['geos_area', 'geos_distance', 'geos_length', 'geos_isvalidreason'] @@ -18,7 +18,7 @@ def dbl_from_geom(func, num_geom=1): Argument is a Geometry, return type is double that is passed in by reference as the last argument. """ - argtypes = [GEOM_PTR for i in xrange(num_geom)] + argtypes = [GEOM_PTR for i in range(num_geom)] argtypes += [POINTER(c_double)] func.argtypes = argtypes func.restype = c_int # Status code returned diff --git a/django/contrib/gis/geos/tests/test_geos.py b/django/contrib/gis/geos/tests/test_geos.py index bc703664d5f..9d093bfa328 100644 --- a/django/contrib/gis/geos/tests/test_geos.py +++ b/django/contrib/gis/geos/tests/test_geos.py @@ -14,7 +14,7 @@ from django.contrib.gis.geometry.test_data import TestDataMixin from django.utils.encoding import force_bytes from django.utils import six -from django.utils.six.moves import xrange +from django.utils.six.moves import range from .. import HAS_GEOS @@ -500,7 +500,7 @@ class GEOSTest(unittest.TestCase, TestDataMixin): self.assertEqual(len(p.ext_ring_cs), len(cs)) # Making sure __len__ works # Checks __getitem__ and __setitem__ - for i in xrange(len(p.ext_ring_cs)): + for i in range(len(p.ext_ring_cs)): c1 = p.ext_ring_cs[i] # Expected value c2 = cs[i] # Value from coordseq self.assertEqual(c1, c2) @@ -529,7 +529,7 @@ class GEOSTest(unittest.TestCase, TestDataMixin): def test_intersection(self): "Testing intersects() and intersection()." - for i in xrange(len(self.geometries.topology_geoms)): + for i in range(len(self.geometries.topology_geoms)): a = fromstr(self.geometries.topology_geoms[i].wkt_a) b = fromstr(self.geometries.topology_geoms[i].wkt_b) i1 = fromstr(self.geometries.intersect_geoms[i].wkt) @@ -542,7 +542,7 @@ class GEOSTest(unittest.TestCase, TestDataMixin): def test_union(self): "Testing union()." - for i in xrange(len(self.geometries.topology_geoms)): + for i in range(len(self.geometries.topology_geoms)): a = fromstr(self.geometries.topology_geoms[i].wkt_a) b = fromstr(self.geometries.topology_geoms[i].wkt_b) u1 = fromstr(self.geometries.union_geoms[i].wkt) @@ -554,7 +554,7 @@ class GEOSTest(unittest.TestCase, TestDataMixin): def test_difference(self): "Testing difference()." - for i in xrange(len(self.geometries.topology_geoms)): + for i in range(len(self.geometries.topology_geoms)): a = fromstr(self.geometries.topology_geoms[i].wkt_a) b = fromstr(self.geometries.topology_geoms[i].wkt_b) d1 = fromstr(self.geometries.diff_geoms[i].wkt) @@ -566,7 +566,7 @@ class GEOSTest(unittest.TestCase, TestDataMixin): def test_symdifference(self): "Testing sym_difference()." - for i in xrange(len(self.geometries.topology_geoms)): + for i in range(len(self.geometries.topology_geoms)): a = fromstr(self.geometries.topology_geoms[i].wkt_a) b = fromstr(self.geometries.topology_geoms[i].wkt_b) d1 = fromstr(self.geometries.sdiff_geoms[i].wkt) @@ -595,11 +595,11 @@ class GEOSTest(unittest.TestCase, TestDataMixin): self.assertEqual(len(exp_buf), len(buf)) # Now assuring that each point in the buffer is almost equal - for j in xrange(len(exp_buf)): + for j in range(len(exp_buf)): exp_ring = exp_buf[j] buf_ring = buf[j] self.assertEqual(len(exp_ring), len(buf_ring)) - for k in xrange(len(exp_ring)): + for k in range(len(exp_ring)): # Asserting the X, Y of each point are almost equal (due to floating point imprecision) self.assertAlmostEqual(exp_ring[k][0], buf_ring[k][0], 9) self.assertAlmostEqual(exp_ring[k][1], buf_ring[k][1], 9) @@ -699,13 +699,13 @@ class GEOSTest(unittest.TestCase, TestDataMixin): # Polygon w/in the collection has its own rings. for tg in self.geometries.multipolygons: mpoly = fromstr(tg.wkt) - for i in xrange(len(mpoly)): + for i in range(len(mpoly)): poly = mpoly[i] old_poly = mpoly[i] # Offsetting the each ring in the polygon by 500. - for j in xrange(len(poly)): + for j in range(len(poly)): r = poly[j] - for k in xrange(len(r)): + for k in range(len(r)): r[k] = (r[k][0] + 500., r[k][1] + 500.) poly[j] = r diff --git a/django/contrib/gis/maps/google/gmap.py b/django/contrib/gis/maps/google/gmap.py index 4694996283b..845b39a806e 100644 --- a/django/contrib/gis/maps/google/gmap.py +++ b/django/contrib/gis/maps/google/gmap.py @@ -4,7 +4,7 @@ from django.conf import settings from django.template.loader import render_to_string from django.utils.html import format_html from django.utils.safestring import mark_safe -from django.utils.six.moves import xrange +from django.utils.six.moves import range from django.contrib.gis.maps.google.overlays import GPolygon, GPolyline, GMarker @@ -192,7 +192,7 @@ class GoogleMapSet(GoogleMap): self.maps = args # Generating DOM ids for each of the maps in the set. - self.dom_ids = ['map%d' % i for i in xrange(len(self.maps))] + self.dom_ids = ['map%d' % i for i in range(len(self.maps))] def load_map_js(self): """ diff --git a/django/contrib/gis/maps/google/zoom.py b/django/contrib/gis/maps/google/zoom.py index c4f1ad85d56..a34748bb8e3 100644 --- a/django/contrib/gis/maps/google/zoom.py +++ b/django/contrib/gis/maps/google/zoom.py @@ -2,7 +2,7 @@ from __future__ import unicode_literals from django.contrib.gis.geos import GEOSGeometry, LinearRing, Polygon, Point from django.contrib.gis.maps.google.gmap import GoogleMapException -from django.utils.six.moves import xrange +from django.utils.six.moves import range from math import pi, sin, log, exp, atan # Constants used for degree to radian conversion, and vice-versa. @@ -41,7 +41,7 @@ class GoogleZoom(object): # Incrementing through the zoom levels and populating the parameter arrays. z = tilesize # The number of pixels per zoom level. - for i in xrange(num_zoom): + for i in range(num_zoom): # Getting the degrees and radians per pixel, and the 1/2 the number of # for every zoom level. self._degpp.append(z / 360.) # degrees per pixel @@ -136,7 +136,7 @@ class GoogleZoom(object): env_w, env_h = self.get_width_height(env.extent) center = env.centroid - for z in xrange(self._nzoom): + for z in range(self._nzoom): # Getting the tile at the zoom level. tile_w, tile_h = self.get_width_height(self.tile(center, z).extent) diff --git a/django/contrib/sessions/backends/cache.py b/django/contrib/sessions/backends/cache.py index b1058b32943..2cac8296d5b 100644 --- a/django/contrib/sessions/backends/cache.py +++ b/django/contrib/sessions/backends/cache.py @@ -1,7 +1,7 @@ from django.conf import settings from django.contrib.sessions.backends.base import SessionBase, CreateError from django.core.cache import caches -from django.utils.six.moves import xrange +from django.utils.six.moves import range KEY_PREFIX = "django.contrib.sessions.cache" @@ -36,7 +36,7 @@ class SessionStore(SessionBase): # because the cache is missing. So we try for a (large) number of times # and then raise an exception. That's the risk you shoulder if using # cache backing. - for i in xrange(10000): + for i in range(10000): self._session_key = self._get_new_session_key() try: self.save(must_create=True) diff --git a/django/db/models/lookups.py b/django/db/models/lookups.py index 9ba5791a150..aea2820a104 100644 --- a/django/db/models/lookups.py +++ b/django/db/models/lookups.py @@ -4,7 +4,7 @@ import inspect from django.conf import settings from django.utils import timezone from django.utils.functional import cached_property -from django.utils.six.moves import xrange +from django.utils.six.moves import range from .query_utils import QueryWrapper @@ -275,7 +275,7 @@ class In(BuiltinLookup): rhs, rhs_params = self.batch_process_rhs(compiler, connection) in_clause_elements = ['('] params = [] - for offset in xrange(0, len(rhs_params), max_in_list_size): + for offset in range(0, len(rhs_params), max_in_list_size): if offset > 0: in_clause_elements.append(' OR ') in_clause_elements.append('%s IN (' % lhs) diff --git a/django/db/models/sql/where.py b/django/db/models/sql/where.py index ea53f71f861..10445555e00 100644 --- a/django/db/models/sql/where.py +++ b/django/db/models/sql/where.py @@ -11,7 +11,7 @@ from django.conf import settings from django.db.models.fields import DateTimeField, Field from django.db.models.sql.datastructures import EmptyResultSet, Empty from django.utils.deprecation import RemovedInDjango19Warning -from django.utils.six.moves import xrange +from django.utils.six.moves import range from django.utils import timezone from django.utils import tree @@ -228,7 +228,7 @@ class WhereNode(tree.Node): if max_in_list_size and len(params) > max_in_list_size: # Break up the params list into an OR of manageable chunks. in_clause_elements = ['('] - for offset in xrange(0, len(params), max_in_list_size): + for offset in range(0, len(params), max_in_list_size): if offset > 0: in_clause_elements.append(' OR ') in_clause_elements.append('%s IN (' % field_sql) diff --git a/django/dispatch/dispatcher.py b/django/dispatch/dispatcher.py index 3f00cab0f1c..907f7fb2116 100644 --- a/django/dispatch/dispatcher.py +++ b/django/dispatch/dispatcher.py @@ -2,7 +2,7 @@ import sys import threading import weakref -from django.utils.six.moves import xrange +from django.utils.six.moves import range if sys.version_info < (3, 4): from .weakref_backports import WeakMethod @@ -162,7 +162,7 @@ class Signal(object): with self.lock: self._clear_dead_receivers() - for index in xrange(len(self.receivers)): + for index in range(len(self.receivers)): (r_key, _) = self.receivers[index] if r_key == lookup_key: del self.receivers[index] diff --git a/django/forms/formsets.py b/django/forms/formsets.py index 07cbb414095..566269beb5e 100644 --- a/django/forms/formsets.py +++ b/django/forms/formsets.py @@ -9,7 +9,7 @@ from django.utils.encoding import python_2_unicode_compatible from django.utils.functional import cached_property from django.utils.safestring import mark_safe from django.utils import six -from django.utils.six.moves import xrange +from django.utils.six.moves import range from django.utils.translation import ungettext, ugettext as _ @@ -138,7 +138,7 @@ class BaseFormSet(object): Instantiate forms at first property access. """ # DoS protection is included in total_form_count() - forms = [self._construct_form(i) for i in xrange(self.total_form_count())] + forms = [self._construct_form(i) for i in range(self.total_form_count())] return forms def _construct_form(self, i, **kwargs): diff --git a/django/utils/crypto.py b/django/utils/crypto.py index b3823a015d9..a2a64052b75 100644 --- a/django/utils/crypto.py +++ b/django/utils/crypto.py @@ -23,7 +23,7 @@ except NotImplementedError: from django.conf import settings from django.utils.encoding import force_bytes from django.utils import six -from django.utils.six.moves import xrange +from django.utils.six.moves import range def salted_hmac(key_salt, value, secret=None): @@ -179,7 +179,7 @@ else: def F(i): u = salt + struct.pack(b'>I', i) result = 0 - for j in xrange(int(iterations)): + for j in range(int(iterations)): dig1, dig2 = inner.copy(), outer.copy() dig1.update(u) dig2.update(dig1.digest()) diff --git a/django/utils/ipv6.py b/django/utils/ipv6.py index ae179c03975..54ccc73b94b 100644 --- a/django/utils/ipv6.py +++ b/django/utils/ipv6.py @@ -3,7 +3,7 @@ # Licensed under the Apache License, Version 2.0 (the "License"). from django.core.exceptions import ValidationError from django.utils.translation import ugettext_lazy as _ -from django.utils.six.moves import xrange +from django.utils.six.moves import range def clean_ipv6_address(ip_str, unpack_ipv4=False, @@ -239,7 +239,7 @@ def _explode_shorthand_ip_string(ip_str): sep = len(hextet[0].split(':')) + len(hextet[1].split(':')) new_ip = hextet[0].split(':') - for __ in xrange(fill_to - sep): + for __ in range(fill_to - sep): new_ip.append('0000') new_ip += hextet[1].split(':') diff --git a/tests/backends/tests.py b/tests/backends/tests.py index 1c01b4a1ebc..5e2c4477554 100644 --- a/tests/backends/tests.py +++ b/tests/backends/tests.py @@ -26,7 +26,7 @@ from django.test import (TestCase, TransactionTestCase, mock, override_settings, skipUnlessDBFeature, skipIfDBFeature) from django.test.utils import str_prefix, IgnoreAllDeprecationWarningsMixin from django.utils import six -from django.utils.six.moves import xrange +from django.utils.six.moves import range from . import models @@ -76,7 +76,7 @@ class OracleTests(unittest.TestCase): # than 4000 chars and read it properly with connection.cursor() as cursor: cursor.execute('CREATE TABLE ltext ("TEXT" NCLOB)') - long_str = ''.join(six.text_type(x) for x in xrange(4000)) + long_str = ''.join(six.text_type(x) for x in range(4000)) cursor.execute('INSERT INTO ltext VALUES (%s)', [long_str]) cursor.execute('SELECT text FROM ltext') row = cursor.fetchone() diff --git a/tests/delete/tests.py b/tests/delete/tests.py index 370cd7ddde8..2d6c02b9a96 100644 --- a/tests/delete/tests.py +++ b/tests/delete/tests.py @@ -5,7 +5,7 @@ from math import ceil from django.db import models, IntegrityError, connection from django.db.models.sql.constants import GET_ITERATOR_CHUNK_SIZE from django.test import TestCase, skipUnlessDBFeature, skipIfDBFeature -from django.utils.six.moves import xrange +from django.utils.six.moves import range from .models import (R, RChild, S, T, A, M, MR, MRNull, create_a, get_default_r, User, Avatar, HiddenUser, HiddenUserProfile, @@ -169,7 +169,7 @@ class DeletionTests(TestCase): def test_bulk(self): s = S.objects.create(r=R.objects.create()) - for i in xrange(2 * GET_ITERATOR_CHUNK_SIZE): + for i in range(2 * GET_ITERATOR_CHUNK_SIZE): T.objects.create(s=s) # 1 (select related `T` instances) # + 1 (select related `U` instances) @@ -332,10 +332,10 @@ class DeletionTests(TestCase): def test_large_delete_related(self): TEST_SIZE = 2000 s = S.objects.create(r=R.objects.create()) - for i in xrange(TEST_SIZE): + for i in range(TEST_SIZE): T.objects.create(s=s) - batch_size = max(connection.ops.bulk_batch_size(['pk'], xrange(TEST_SIZE)), 1) + batch_size = max(connection.ops.bulk_batch_size(['pk'], range(TEST_SIZE)), 1) # TEST_SIZE // batch_size (select related `T` instances) # + 1 (select related `U` instances) diff --git a/tests/middleware/tests.py b/tests/middleware/tests.py index 6fb5cb42807..c79695f2e0c 100644 --- a/tests/middleware/tests.py +++ b/tests/middleware/tests.py @@ -21,7 +21,7 @@ from django.test import TestCase, RequestFactory, override_settings from django.test.utils import patch_logger from django.utils import six from django.utils.encoding import force_str -from django.utils.six.moves import xrange +from django.utils.six.moves import range @override_settings(ROOT_URLCONF='middleware.urls') @@ -602,7 +602,7 @@ class GZipMiddlewareTest(TestCase): """ short_string = b"This string is too short to be worth compressing." compressible_string = b'a' * 500 - uncompressible_string = b''.join(six.int2byte(random.randint(0, 255)) for _ in xrange(500)) + uncompressible_string = b''.join(six.int2byte(random.randint(0, 255)) for _ in range(500)) sequence = [b'a' * 500, b'b' * 200, b'a' * 300] def setUp(self): diff --git a/tests/model_forms/models.py b/tests/model_forms/models.py index 4ab681d1aef..d2b55c4e108 100644 --- a/tests/model_forms/models.py +++ b/tests/model_forms/models.py @@ -18,6 +18,7 @@ from django.core.files.storage import FileSystemStorage from django.db import models from django.utils import six from django.utils.encoding import python_2_unicode_compatible +from django.utils.six.moves import range from django.utils._os import upath @@ -357,7 +358,7 @@ class Colour(models.Model): name = models.CharField(max_length=50) def __iter__(self): - for number in xrange(5): + for number in range(5): yield number def __str__(self): diff --git a/tests/utils_tests/test_baseconv.py b/tests/utils_tests/test_baseconv.py index 0af1c4e3f03..26ba126eb70 100644 --- a/tests/utils_tests/test_baseconv.py +++ b/tests/utils_tests/test_baseconv.py @@ -1,13 +1,13 @@ from unittest import TestCase from django.utils.baseconv import base2, base16, base36, base56, base62, base64, BaseConverter -from django.utils.six.moves import xrange +from django.utils.six.moves import range class TestBaseConv(TestCase): def test_baseconv(self): - nums = [-10 ** 10, 10 ** 10] + list(xrange(-100, 100)) + nums = [-10 ** 10, 10 ** 10] + list(range(-100, 100)) for converter in [base2, base16, base36, base56, base62, base64]: for i in nums: self.assertEqual(i, converter.decode(converter.encode(i)))