Fixed #23812 -- Changed django.utils.six.moves.xrange imports to range

This commit is contained in:
Michael Hall 2014-12-13 06:04:36 -07:00 committed by Tim Graham
parent a5499b0916
commit 895dc880eb
27 changed files with 95 additions and 94 deletions

View File

@ -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.encoding import force_bytes, force_text
from django.utils import six 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: # For more information, see the OGR C API source code:
@ -98,7 +98,7 @@ class DataSource(GDALBase):
def __iter__(self): def __iter__(self):
"Allows for iteration over the layers in a data source." "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] yield self[i]
def __getitem__(self, index): def __getitem__(self, index):

View File

@ -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.encoding import force_bytes, force_text
from django.utils import six 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: # For more information, see the OGR C API source code:
@ -54,7 +54,7 @@ class Feature(GDALBase):
def __iter__(self): def __iter__(self):
"Iterates over each field in the Feature." "Iterates over each field in the Feature."
for i in xrange(self.num_fields): for i in range(self.num_fields):
yield self[i] yield self[i]
def __len__(self): def __len__(self):
@ -94,7 +94,7 @@ class Feature(GDALBase):
def fields(self): def fields(self):
"Returns a list of fields in the Feature." "Returns a list of fields in the Feature."
return [capi.get_field_name(capi.get_field_defn(self._layer._ldefn, i)) 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 @property
def geom(self): def geom(self):

View File

@ -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.contrib.gis.geometry.regex import hex_regex, wkt_regex, json_regex
from django.utils import six 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: # For more information, see the OGR C API source code:
# http://www.gdal.org/ogr/ogr__api_8h.html # http://www.gdal.org/ogr/ogr__api_8h.html
@ -546,7 +546,7 @@ class LineString(OGRGeometry):
def __iter__(self): def __iter__(self):
"Iterates over each point in the LineString." "Iterates over each point in the LineString."
for i in xrange(self.point_count): for i in range(self.point_count):
yield self[i] yield self[i]
def __len__(self): def __len__(self):
@ -556,7 +556,7 @@ class LineString(OGRGeometry):
@property @property
def tuple(self): def tuple(self):
"Returns the tuple representation of this LineString." "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 coords = tuple
def _listarr(self, func): def _listarr(self, func):
@ -564,7 +564,7 @@ class LineString(OGRGeometry):
Internal routine that returns a sequence (list) corresponding with Internal routine that returns a sequence (list) corresponding with
the given function. 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 @property
def x(self): def x(self):
@ -596,7 +596,7 @@ class Polygon(OGRGeometry):
def __iter__(self): def __iter__(self):
"Iterates through each ring in the Polygon." "Iterates through each ring in the Polygon."
for i in xrange(self.geom_count): for i in range(self.geom_count):
yield self[i] yield self[i]
def __getitem__(self, index): def __getitem__(self, index):
@ -616,14 +616,14 @@ class Polygon(OGRGeometry):
@property @property
def tuple(self): def tuple(self):
"Returns a tuple of LinearRing coordinate tuples." "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 coords = tuple
@property @property
def point_count(self): def point_count(self):
"The number of Points in this Polygon." "The number of Points in this Polygon."
# Summing up the number of points in each ring of the 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 @property
def centroid(self): def centroid(self):
@ -647,7 +647,7 @@ class GeometryCollection(OGRGeometry):
def __iter__(self): def __iter__(self):
"Iterates over each Geometry." "Iterates over each Geometry."
for i in xrange(self.geom_count): for i in range(self.geom_count):
yield self[i] yield self[i]
def __len__(self): def __len__(self):
@ -672,12 +672,12 @@ class GeometryCollection(OGRGeometry):
def point_count(self): def point_count(self):
"The number of Points in this Geometry Collection." "The number of Points in this Geometry Collection."
# Summing up the number of points in each geometry in this 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 @property
def tuple(self): def tuple(self):
"Returns a tuple representation of this Geometry Collection." "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 coords = tuple

View File

@ -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.encoding import force_bytes, force_text
from django.utils import six 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: # For more information, see the OGR C API source code:
@ -54,7 +54,7 @@ class Layer(GDALBase):
elif isinstance(index, slice): elif isinstance(index, slice):
# A slice was given # A slice was given
start, stop, stride = index.indices(self.num_feat) 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: else:
raise TypeError('Integers and slices may only be used when indexing OGR Layers.') 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." "Iterates over each Feature in the Layer."
# ResetReading() must be called before iteration is to begin. # ResetReading() must be called before iteration is to begin.
capi.reset_reading(self._ptr) 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) yield Feature(capi.get_next_feature(self._ptr), self)
def __len__(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)), return [force_text(capi.get_field_name(capi.get_field_defn(self._ldefn, i)),
self._ds.encoding, strings_only=True) self._ds.encoding, strings_only=True)
for i in xrange(self.num_fields)] for i in range(self.num_fields)]
@property @property
def field_types(self): def field_types(self):
@ -152,19 +152,19 @@ class Layer(GDALBase):
fields. fields.
""" """
return [OGRFieldTypes[capi.get_field_type(capi.get_field_defn(self._ldefn, i))] 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 @property
def field_widths(self): def field_widths(self):
"Returns a list of the maximum field widths for the features." "Returns a list of the maximum field widths for the features."
return [capi.get_field_width(capi.get_field_defn(self._ldefn, i)) 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 @property
def field_precisions(self): def field_precisions(self):
"Returns the field precisions for the features." "Returns the field precisions for the features."
return [capi.get_field_precision(capi.get_field_defn(self._ldefn, i)) 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): def _get_spatial_filter(self):
try: try:

View File

@ -9,7 +9,7 @@ from unittest import skipUnless
from django.contrib.gis.gdal import HAS_GDAL from django.contrib.gis.gdal import HAS_GDAL
from django.contrib.gis.geometry.test_data import TestDataMixin 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: if HAS_GDAL:
from django.contrib.gis.gdal import (OGRGeometry, OGRGeomType, from django.contrib.gis.gdal import (OGRGeometry, OGRGeomType,
@ -355,7 +355,7 @@ class OGRGeomTest(unittest.TestCase, TestDataMixin):
def test10_difference(self): def test10_difference(self):
"Testing difference()." "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) a = OGRGeometry(self.geometries.topology_geoms[i].wkt_a)
b = OGRGeometry(self.geometries.topology_geoms[i].wkt_b) b = OGRGeometry(self.geometries.topology_geoms[i].wkt_b)
d1 = OGRGeometry(self.geometries.diff_geoms[i].wkt) d1 = OGRGeometry(self.geometries.diff_geoms[i].wkt)
@ -367,7 +367,7 @@ class OGRGeomTest(unittest.TestCase, TestDataMixin):
def test11_intersection(self): def test11_intersection(self):
"Testing intersects() and intersection()." "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) a = OGRGeometry(self.geometries.topology_geoms[i].wkt_a)
b = OGRGeometry(self.geometries.topology_geoms[i].wkt_b) b = OGRGeometry(self.geometries.topology_geoms[i].wkt_b)
i1 = OGRGeometry(self.geometries.intersect_geoms[i].wkt) i1 = OGRGeometry(self.geometries.intersect_geoms[i].wkt)
@ -380,7 +380,7 @@ class OGRGeomTest(unittest.TestCase, TestDataMixin):
def test12_symdifference(self): def test12_symdifference(self):
"Testing sym_difference()." "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) a = OGRGeometry(self.geometries.topology_geoms[i].wkt_a)
b = OGRGeometry(self.geometries.topology_geoms[i].wkt_b) b = OGRGeometry(self.geometries.topology_geoms[i].wkt_b)
d1 = OGRGeometry(self.geometries.sdiff_geoms[i].wkt) d1 = OGRGeometry(self.geometries.sdiff_geoms[i].wkt)
@ -392,7 +392,7 @@ class OGRGeomTest(unittest.TestCase, TestDataMixin):
def test13_union(self): def test13_union(self):
"Testing union()." "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) a = OGRGeometry(self.geometries.topology_geoms[i].wkt_a)
b = OGRGeometry(self.geometries.topology_geoms[i].wkt_b) b = OGRGeometry(self.geometries.topology_geoms[i].wkt_b)
u1 = OGRGeometry(self.geometries.union_geoms[i].wkt) u1 = OGRGeometry(self.geometries.union_geoms[i].wkt)

View File

@ -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.point import Point
from django.contrib.gis.geos.polygon import Polygon from django.contrib.gis.geos.polygon import Polygon
from django.contrib.gis.geos import prototypes as capi 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): class GeometryCollection(GEOSGeometry):
@ -42,7 +42,7 @@ class GeometryCollection(GEOSGeometry):
def __iter__(self): def __iter__(self):
"Iterates over each Geometry in the Collection." "Iterates over each Geometry in the Collection."
for i in xrange(len(self)): for i in range(len(self)):
yield self[i] yield self[i]
def __len__(self): def __len__(self):

View File

@ -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.error import GEOSException, GEOSIndexError
from django.contrib.gis.geos.libgeos import CS_PTR from django.contrib.gis.geos.libgeos import CS_PTR
from django.contrib.gis.geos import prototypes as capi 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): class GEOSCoordSeq(GEOSBase):
@ -26,7 +26,7 @@ class GEOSCoordSeq(GEOSBase):
def __iter__(self): def __iter__(self):
"Iterates over each point in the coordinate sequence." "Iterates over each point in the coordinate sequence."
for i in xrange(self.size): for i in range(self.size):
yield self[i] yield self[i]
def __len__(self): def __len__(self):
@ -151,7 +151,7 @@ class GEOSCoordSeq(GEOSBase):
else: else:
substr = '%s,%s,0 ' substr = '%s,%s,0 '
return '<coordinates>%s</coordinates>' % \ return '<coordinates>%s</coordinates>' % \
''.join(substr % self[i] for i in xrange(len(self))).strip() ''.join(substr % self[i] for i in range(len(self))).strip()
@property @property
def tuple(self): def tuple(self):
@ -160,4 +160,4 @@ class GEOSCoordSeq(GEOSBase):
if n == 1: if n == 1:
return self[0] return self[0]
else: else:
return tuple(self[i] for i in xrange(n)) return tuple(self[i] for i in range(n))

View File

@ -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.geometry import GEOSGeometry
from django.contrib.gis.geos.point import Point from django.contrib.gis.geos.point import Point
from django.contrib.gis.geos import prototypes as capi 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): class LineString(GEOSGeometry):
@ -40,7 +40,7 @@ class LineString(GEOSGeometry):
raise TypeError('Cannot initialize on empty sequence.') raise TypeError('Cannot initialize on empty sequence.')
self._checkdim(ndim) self._checkdim(ndim)
# Incrementing through each of the coordinates and verifying # 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)): if not isinstance(coords[i], (tuple, list, Point)):
raise TypeError('each coordinate should be a sequence (list or tuple)') raise TypeError('each coordinate should be a sequence (list or tuple)')
if len(coords[i]) != ndim: if len(coords[i]) != ndim:
@ -61,7 +61,7 @@ class LineString(GEOSGeometry):
# set the points using GEOSCoordSeq.__setitem__(). # set the points using GEOSCoordSeq.__setitem__().
cs = GEOSCoordSeq(capi.create_cs(ncoords, ndim), z=bool(ndim == 3)) cs = GEOSCoordSeq(capi.create_cs(ncoords, ndim), z=bool(ndim == 3))
for i in xrange(ncoords): for i in range(ncoords):
if numpy_coords: if numpy_coords:
cs[i] = coords[i, :] cs[i] = coords[i, :]
elif isinstance(coords[i], Point): elif isinstance(coords[i], Point):
@ -78,7 +78,7 @@ class LineString(GEOSGeometry):
def __iter__(self): def __iter__(self):
"Allows iteration over this LineString." "Allows iteration over this LineString."
for i in xrange(len(self)): for i in range(len(self)):
yield self[i] yield self[i]
def __len__(self): def __len__(self):
@ -128,7 +128,7 @@ class LineString(GEOSGeometry):
Internal routine that returns a sequence (list) corresponding with Internal routine that returns a sequence (list) corresponding with
the given function. Will return a numpy array if possible. 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: if numpy:
return numpy.array(lst) # ARRRR! return numpy.array(lst) # ARRRR!
else: else:

View File

@ -10,7 +10,7 @@ Author: Aryeh Leib Taurog.
""" """
from django.utils.functional import total_ordering from django.utils.functional import total_ordering
from django.utils import six from django.utils import six
from django.utils.six.moves import xrange from django.utils.six.moves import range
@total_ordering @total_ordering
@ -78,7 +78,7 @@ class ListMixin(object):
def __getitem__(self, index): def __getitem__(self, index):
"Get the item(s) at the specified index/slice." "Get the item(s) at the specified index/slice."
if isinstance(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: else:
index = self._checkindex(index) index = self._checkindex(index)
return self._get_single_external(index) return self._get_single_external(index)
@ -98,7 +98,7 @@ class ListMixin(object):
newLen = origLen - len(indexRange) newLen = origLen - len(indexRange)
newItems = (self._get_single_internal(i) newItems = (self._get_single_internal(i)
for i in xrange(origLen) for i in range(origLen)
if i not in indexRange) if i not in indexRange)
self._rebuild(newLen, newItems) self._rebuild(newLen, newItems)
@ -114,7 +114,7 @@ class ListMixin(object):
def __iter__(self): def __iter__(self):
"Iterate over the items in the list" "Iterate over the items in the list"
for i in xrange(len(self)): for i in range(len(self)):
yield self[i] yield self[i]
### Special methods for arithmetic operations ### ### Special methods for arithmetic operations ###
@ -187,7 +187,7 @@ class ListMixin(object):
def index(self, val): def index(self, val):
"Standard list index method" "Standard list index method"
for i in xrange(0, len(self)): for i in range(0, len(self)):
if self[i] == val: if self[i] == val:
return i return i
raise ValueError('%s not found in object' % str(val)) raise ValueError('%s not found in object' % str(val))
@ -294,7 +294,7 @@ class ListMixin(object):
newVals = dict(zip(indexList, valueList)) newVals = dict(zip(indexList, valueList))
def newItems(): def newItems():
for i in xrange(newLen): for i in range(newLen):
if i in newVals: if i in newVals:
yield newVals[i] yield newVals[i]
else: else:
@ -321,7 +321,7 @@ class ListMixin(object):
newLen = origLen - stop + start + len(valueList) newLen = origLen - stop + start + len(valueList)
def newItems(): def newItems():
for i in xrange(origLen + 1): for i in range(origLen + 1):
if i == start: if i == start:
for val in valueList: for val in valueList:
yield val yield val

View File

@ -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.geometry import GEOSGeometry
from django.contrib.gis.geos import prototypes as capi from django.contrib.gis.geos import prototypes as capi
from django.utils import six from django.utils import six
from django.utils.six.moves import xrange from django.utils.six.moves import range
class Point(GEOSGeometry): class Point(GEOSGeometry):
@ -71,7 +71,7 @@ class Point(GEOSGeometry):
def __iter__(self): def __iter__(self):
"Allows iteration over coordinates of this Point." "Allows iteration over coordinates of this Point."
for i in xrange(len(self)): for i in range(len(self)):
yield self[i] yield self[i]
def __len__(self): def __len__(self):

View File

@ -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.linestring import LinearRing
from django.contrib.gis.geos import prototypes as capi from django.contrib.gis.geos import prototypes as capi
from django.utils import six from django.utils import six
from django.utils.six.moves import xrange from django.utils.six.moves import range
class Polygon(GEOSGeometry): class Polygon(GEOSGeometry):
@ -49,7 +49,7 @@ class Polygon(GEOSGeometry):
def __iter__(self): def __iter__(self):
"Iterates over each ring in the polygon." "Iterates over each ring in the polygon."
for i in xrange(len(self)): for i in range(len(self)):
yield self[i] yield self[i]
def __len__(self): def __len__(self):
@ -165,12 +165,12 @@ class Polygon(GEOSGeometry):
@property @property
def tuple(self): def tuple(self):
"Gets the tuple for each ring in this Polygon." "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 coords = tuple
@property @property
def kml(self): def kml(self):
"Returns the KML representation of this Polygon." "Returns the KML representation of this Polygon."
inner_kml = ''.join("<innerBoundaryIs>%s</innerBoundaryIs>" % self[i + 1].kml inner_kml = ''.join("<innerBoundaryIs>%s</innerBoundaryIs>" % self[i + 1].kml
for i in xrange(self.num_interior_rings)) for i in range(self.num_interior_rings))
return "<Polygon><outerBoundaryIs>%s</outerBoundaryIs>%s</Polygon>" % (self[0].kml, inner_kml) return "<Polygon><outerBoundaryIs>%s</outerBoundaryIs>%s</Polygon>" % (self[0].kml, inner_kml)

View File

@ -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.errcheck import check_dbl, check_string
from django.contrib.gis.geos.prototypes.geom import geos_char_p from django.contrib.gis.geos.prototypes.geom import geos_char_p
from django.contrib.gis.geos.prototypes.threadsafe import GEOSFunc 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'] __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 Argument is a Geometry, return type is double that is passed
in by reference as the last argument. 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)] argtypes += [POINTER(c_double)]
func.argtypes = argtypes func.argtypes = argtypes
func.restype = c_int # Status code returned func.restype = c_int # Status code returned

View File

@ -14,7 +14,7 @@ from django.contrib.gis.geometry.test_data import TestDataMixin
from django.utils.encoding import force_bytes from django.utils.encoding import force_bytes
from django.utils import six from django.utils import six
from django.utils.six.moves import xrange from django.utils.six.moves import range
from .. import HAS_GEOS 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 self.assertEqual(len(p.ext_ring_cs), len(cs)) # Making sure __len__ works
# Checks __getitem__ and __setitem__ # 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 c1 = p.ext_ring_cs[i] # Expected value
c2 = cs[i] # Value from coordseq c2 = cs[i] # Value from coordseq
self.assertEqual(c1, c2) self.assertEqual(c1, c2)
@ -529,7 +529,7 @@ class GEOSTest(unittest.TestCase, TestDataMixin):
def test_intersection(self): def test_intersection(self):
"Testing intersects() and intersection()." "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) a = fromstr(self.geometries.topology_geoms[i].wkt_a)
b = fromstr(self.geometries.topology_geoms[i].wkt_b) b = fromstr(self.geometries.topology_geoms[i].wkt_b)
i1 = fromstr(self.geometries.intersect_geoms[i].wkt) i1 = fromstr(self.geometries.intersect_geoms[i].wkt)
@ -542,7 +542,7 @@ class GEOSTest(unittest.TestCase, TestDataMixin):
def test_union(self): def test_union(self):
"Testing union()." "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) a = fromstr(self.geometries.topology_geoms[i].wkt_a)
b = fromstr(self.geometries.topology_geoms[i].wkt_b) b = fromstr(self.geometries.topology_geoms[i].wkt_b)
u1 = fromstr(self.geometries.union_geoms[i].wkt) u1 = fromstr(self.geometries.union_geoms[i].wkt)
@ -554,7 +554,7 @@ class GEOSTest(unittest.TestCase, TestDataMixin):
def test_difference(self): def test_difference(self):
"Testing difference()." "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) a = fromstr(self.geometries.topology_geoms[i].wkt_a)
b = fromstr(self.geometries.topology_geoms[i].wkt_b) b = fromstr(self.geometries.topology_geoms[i].wkt_b)
d1 = fromstr(self.geometries.diff_geoms[i].wkt) d1 = fromstr(self.geometries.diff_geoms[i].wkt)
@ -566,7 +566,7 @@ class GEOSTest(unittest.TestCase, TestDataMixin):
def test_symdifference(self): def test_symdifference(self):
"Testing sym_difference()." "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) a = fromstr(self.geometries.topology_geoms[i].wkt_a)
b = fromstr(self.geometries.topology_geoms[i].wkt_b) b = fromstr(self.geometries.topology_geoms[i].wkt_b)
d1 = fromstr(self.geometries.sdiff_geoms[i].wkt) d1 = fromstr(self.geometries.sdiff_geoms[i].wkt)
@ -595,11 +595,11 @@ class GEOSTest(unittest.TestCase, TestDataMixin):
self.assertEqual(len(exp_buf), len(buf)) self.assertEqual(len(exp_buf), len(buf))
# Now assuring that each point in the buffer is almost equal # 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] exp_ring = exp_buf[j]
buf_ring = buf[j] buf_ring = buf[j]
self.assertEqual(len(exp_ring), len(buf_ring)) 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) # 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][0], buf_ring[k][0], 9)
self.assertAlmostEqual(exp_ring[k][1], buf_ring[k][1], 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. # Polygon w/in the collection has its own rings.
for tg in self.geometries.multipolygons: for tg in self.geometries.multipolygons:
mpoly = fromstr(tg.wkt) mpoly = fromstr(tg.wkt)
for i in xrange(len(mpoly)): for i in range(len(mpoly)):
poly = mpoly[i] poly = mpoly[i]
old_poly = mpoly[i] old_poly = mpoly[i]
# Offsetting the each ring in the polygon by 500. # Offsetting the each ring in the polygon by 500.
for j in xrange(len(poly)): for j in range(len(poly)):
r = poly[j] 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.) r[k] = (r[k][0] + 500., r[k][1] + 500.)
poly[j] = r poly[j] = r

View File

@ -4,7 +4,7 @@ from django.conf import settings
from django.template.loader import render_to_string from django.template.loader import render_to_string
from django.utils.html import format_html from django.utils.html import format_html
from django.utils.safestring import mark_safe 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 from django.contrib.gis.maps.google.overlays import GPolygon, GPolyline, GMarker
@ -192,7 +192,7 @@ class GoogleMapSet(GoogleMap):
self.maps = args self.maps = args
# Generating DOM ids for each of the maps in the set. # 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): def load_map_js(self):
""" """

View File

@ -2,7 +2,7 @@ from __future__ import unicode_literals
from django.contrib.gis.geos import GEOSGeometry, LinearRing, Polygon, Point from django.contrib.gis.geos import GEOSGeometry, LinearRing, Polygon, Point
from django.contrib.gis.maps.google.gmap import GoogleMapException 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 from math import pi, sin, log, exp, atan
# Constants used for degree to radian conversion, and vice-versa. # 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. # Incrementing through the zoom levels and populating the parameter arrays.
z = tilesize # The number of pixels per zoom level. 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 # Getting the degrees and radians per pixel, and the 1/2 the number of
# for every zoom level. # for every zoom level.
self._degpp.append(z / 360.) # degrees per pixel 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) env_w, env_h = self.get_width_height(env.extent)
center = env.centroid center = env.centroid
for z in xrange(self._nzoom): for z in range(self._nzoom):
# Getting the tile at the zoom level. # Getting the tile at the zoom level.
tile_w, tile_h = self.get_width_height(self.tile(center, z).extent) tile_w, tile_h = self.get_width_height(self.tile(center, z).extent)

View File

@ -1,7 +1,7 @@
from django.conf import settings from django.conf import settings
from django.contrib.sessions.backends.base import SessionBase, CreateError from django.contrib.sessions.backends.base import SessionBase, CreateError
from django.core.cache import caches 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" 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 # 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 # and then raise an exception. That's the risk you shoulder if using
# cache backing. # cache backing.
for i in xrange(10000): for i in range(10000):
self._session_key = self._get_new_session_key() self._session_key = self._get_new_session_key()
try: try:
self.save(must_create=True) self.save(must_create=True)

View File

@ -4,7 +4,7 @@ import inspect
from django.conf import settings from django.conf import settings
from django.utils import timezone from django.utils import timezone
from django.utils.functional import cached_property 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 from .query_utils import QueryWrapper
@ -275,7 +275,7 @@ class In(BuiltinLookup):
rhs, rhs_params = self.batch_process_rhs(compiler, connection) rhs, rhs_params = self.batch_process_rhs(compiler, connection)
in_clause_elements = ['('] in_clause_elements = ['(']
params = [] 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: if offset > 0:
in_clause_elements.append(' OR ') in_clause_elements.append(' OR ')
in_clause_elements.append('%s IN (' % lhs) in_clause_elements.append('%s IN (' % lhs)

View File

@ -11,7 +11,7 @@ from django.conf import settings
from django.db.models.fields import DateTimeField, Field from django.db.models.fields import DateTimeField, Field
from django.db.models.sql.datastructures import EmptyResultSet, Empty from django.db.models.sql.datastructures import EmptyResultSet, Empty
from django.utils.deprecation import RemovedInDjango19Warning 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 timezone
from django.utils import tree 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: if max_in_list_size and len(params) > max_in_list_size:
# Break up the params list into an OR of manageable chunks. # Break up the params list into an OR of manageable chunks.
in_clause_elements = ['('] 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: if offset > 0:
in_clause_elements.append(' OR ') in_clause_elements.append(' OR ')
in_clause_elements.append('%s IN (' % field_sql) in_clause_elements.append('%s IN (' % field_sql)

View File

@ -2,7 +2,7 @@ import sys
import threading import threading
import weakref import weakref
from django.utils.six.moves import xrange from django.utils.six.moves import range
if sys.version_info < (3, 4): if sys.version_info < (3, 4):
from .weakref_backports import WeakMethod from .weakref_backports import WeakMethod
@ -162,7 +162,7 @@ class Signal(object):
with self.lock: with self.lock:
self._clear_dead_receivers() self._clear_dead_receivers()
for index in xrange(len(self.receivers)): for index in range(len(self.receivers)):
(r_key, _) = self.receivers[index] (r_key, _) = self.receivers[index]
if r_key == lookup_key: if r_key == lookup_key:
del self.receivers[index] del self.receivers[index]

View File

@ -9,7 +9,7 @@ from django.utils.encoding import python_2_unicode_compatible
from django.utils.functional import cached_property from django.utils.functional import cached_property
from django.utils.safestring import mark_safe from django.utils.safestring import mark_safe
from django.utils import six 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 _ from django.utils.translation import ungettext, ugettext as _
@ -138,7 +138,7 @@ class BaseFormSet(object):
Instantiate forms at first property access. Instantiate forms at first property access.
""" """
# DoS protection is included in total_form_count() # 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 return forms
def _construct_form(self, i, **kwargs): def _construct_form(self, i, **kwargs):

View File

@ -23,7 +23,7 @@ except NotImplementedError:
from django.conf import settings from django.conf import settings
from django.utils.encoding import force_bytes from django.utils.encoding import force_bytes
from django.utils import six 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): def salted_hmac(key_salt, value, secret=None):
@ -179,7 +179,7 @@ else:
def F(i): def F(i):
u = salt + struct.pack(b'>I', i) u = salt + struct.pack(b'>I', i)
result = 0 result = 0
for j in xrange(int(iterations)): for j in range(int(iterations)):
dig1, dig2 = inner.copy(), outer.copy() dig1, dig2 = inner.copy(), outer.copy()
dig1.update(u) dig1.update(u)
dig2.update(dig1.digest()) dig2.update(dig1.digest())

View File

@ -3,7 +3,7 @@
# Licensed under the Apache License, Version 2.0 (the "License"). # Licensed under the Apache License, Version 2.0 (the "License").
from django.core.exceptions import ValidationError from django.core.exceptions import ValidationError
from django.utils.translation import ugettext_lazy as _ 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, 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(':')) sep = len(hextet[0].split(':')) + len(hextet[1].split(':'))
new_ip = hextet[0].split(':') new_ip = hextet[0].split(':')
for __ in xrange(fill_to - sep): for __ in range(fill_to - sep):
new_ip.append('0000') new_ip.append('0000')
new_ip += hextet[1].split(':') new_ip += hextet[1].split(':')

View File

@ -26,7 +26,7 @@ from django.test import (TestCase, TransactionTestCase, mock, override_settings,
skipUnlessDBFeature, skipIfDBFeature) skipUnlessDBFeature, skipIfDBFeature)
from django.test.utils import str_prefix, IgnoreAllDeprecationWarningsMixin from django.test.utils import str_prefix, IgnoreAllDeprecationWarningsMixin
from django.utils import six from django.utils import six
from django.utils.six.moves import xrange from django.utils.six.moves import range
from . import models from . import models
@ -76,7 +76,7 @@ class OracleTests(unittest.TestCase):
# than 4000 chars and read it properly # than 4000 chars and read it properly
with connection.cursor() as cursor: with connection.cursor() as cursor:
cursor.execute('CREATE TABLE ltext ("TEXT" NCLOB)') 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('INSERT INTO ltext VALUES (%s)', [long_str])
cursor.execute('SELECT text FROM ltext') cursor.execute('SELECT text FROM ltext')
row = cursor.fetchone() row = cursor.fetchone()

View File

@ -5,7 +5,7 @@ from math import ceil
from django.db import models, IntegrityError, connection from django.db import models, IntegrityError, connection
from django.db.models.sql.constants import GET_ITERATOR_CHUNK_SIZE from django.db.models.sql.constants import GET_ITERATOR_CHUNK_SIZE
from django.test import TestCase, skipUnlessDBFeature, skipIfDBFeature 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, from .models import (R, RChild, S, T, A, M, MR, MRNull,
create_a, get_default_r, User, Avatar, HiddenUser, HiddenUserProfile, create_a, get_default_r, User, Avatar, HiddenUser, HiddenUserProfile,
@ -169,7 +169,7 @@ class DeletionTests(TestCase):
def test_bulk(self): def test_bulk(self):
s = S.objects.create(r=R.objects.create()) 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) T.objects.create(s=s)
# 1 (select related `T` instances) # 1 (select related `T` instances)
# + 1 (select related `U` instances) # + 1 (select related `U` instances)
@ -332,10 +332,10 @@ class DeletionTests(TestCase):
def test_large_delete_related(self): def test_large_delete_related(self):
TEST_SIZE = 2000 TEST_SIZE = 2000
s = S.objects.create(r=R.objects.create()) 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) 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) # TEST_SIZE // batch_size (select related `T` instances)
# + 1 (select related `U` instances) # + 1 (select related `U` instances)

View File

@ -21,7 +21,7 @@ from django.test import TestCase, RequestFactory, override_settings
from django.test.utils import patch_logger from django.test.utils import patch_logger
from django.utils import six from django.utils import six
from django.utils.encoding import force_str 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') @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." short_string = b"This string is too short to be worth compressing."
compressible_string = b'a' * 500 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] sequence = [b'a' * 500, b'b' * 200, b'a' * 300]
def setUp(self): def setUp(self):

View File

@ -18,6 +18,7 @@ from django.core.files.storage import FileSystemStorage
from django.db import models from django.db import models
from django.utils import six from django.utils import six
from django.utils.encoding import python_2_unicode_compatible from django.utils.encoding import python_2_unicode_compatible
from django.utils.six.moves import range
from django.utils._os import upath from django.utils._os import upath
@ -357,7 +358,7 @@ class Colour(models.Model):
name = models.CharField(max_length=50) name = models.CharField(max_length=50)
def __iter__(self): def __iter__(self):
for number in xrange(5): for number in range(5):
yield number yield number
def __str__(self): def __str__(self):

View File

@ -1,13 +1,13 @@
from unittest import TestCase from unittest import TestCase
from django.utils.baseconv import base2, base16, base36, base56, base62, base64, BaseConverter 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): class TestBaseConv(TestCase):
def test_baseconv(self): 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 converter in [base2, base16, base36, base56, base62, base64]:
for i in nums: for i in nums:
self.assertEqual(i, converter.decode(converter.encode(i))) self.assertEqual(i, converter.decode(converter.encode(i)))