Permalink
Browse files

[py3] Added Python 3 compatibility for xrange.

  • Loading branch information...
1 parent ca07fda commit a84d79f572fbe7512b999c6b3cd7667cbe3138ff @aaugustin aaugustin committed Jul 20, 2012
Showing with 77 additions and 53 deletions.
  1. +1 −0 django/contrib/gis/gdal/datasource.py
  2. +1 −0 django/contrib/gis/gdal/feature.py
  3. +1 −0 django/contrib/gis/gdal/geometries.py
  4. +1 −0 django/contrib/gis/gdal/layer.py
  5. +1 −0 django/contrib/gis/gdal/tests/test_geom.py
  6. +5 −4 django/contrib/gis/geos/collections.py
  7. +1 −0 django/contrib/gis/geos/coordseq.py
  8. +2 −1 django/contrib/gis/geos/linestring.py
  9. +1 −0 django/contrib/gis/geos/mutable_list.py
  10. +1 −0 django/contrib/gis/geos/point.py
  11. +1 −0 django/contrib/gis/geos/polygon.py
  12. +1 −0 django/contrib/gis/geos/prototypes/misc.py
  13. +1 −0 django/contrib/gis/geos/tests/test_geos.py
  14. +1 −0 django/contrib/gis/maps/google/gmap.py
  15. +11 −10 django/contrib/gis/maps/google/zoom.py
  16. +2 −2 django/contrib/localflavor/mx/forms.py
  17. +3 −3 django/contrib/localflavor/tr/forms.py
  18. +5 −5 django/contrib/messages/tests/base.py
  19. +1 −1 django/contrib/messages/tests/cookie.py
  20. +1 −0 django/contrib/sessions/backends/cache.py
  21. +1 −0 django/db/models/sql/where.py
  22. +20 −19 django/dispatch/dispatcher.py
  23. +1 −0 django/forms/formsets.py
  24. +1 −0 django/utils/crypto.py
  25. +1 −1 django/utils/importlib.py
  26. +1 −0 django/utils/ipv6.py
  27. +1 −0 tests/modeltests/delete/tests.py
  28. +2 −2 tests/modeltests/many_to_one_null/tests.py
  29. +3 −2 tests/regressiontests/backends/tests.py
  30. +2 −2 tests/regressiontests/dispatch/tests/test_saferef.py
  31. +1 −0 tests/regressiontests/middleware/tests.py
  32. +1 −1 tests/regressiontests/utils/datastructures.py
@@ -46,6 +46,7 @@
from django.contrib.gis.gdal.prototypes import ds as capi
from django.utils import six
+from django.utils.six.moves import xrange
# For more information, see the OGR C API source code:
# http://www.gdal.org/ogr/ogr__api_8h.html
@@ -8,6 +8,7 @@
from django.contrib.gis.gdal.prototypes import ds as capi, geom as geom_api
from django.utils import six
+from django.utils.six.moves import xrange
# For more information, see the OGR C API source code:
# http://www.gdal.org/ogr/ogr__api_8h.html
@@ -58,6 +58,7 @@
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
# For more information, see the OGR C API source code:
# http://www.gdal.org/ogr/ogr__api_8h.html
@@ -15,6 +15,7 @@
from django.contrib.gis.gdal.prototypes import ds as capi, geom as geom_api, srs as srs_api
from django.utils import six
+from django.utils.six.moves import xrange
# For more information, see the OGR C API source code:
# http://www.gdal.org/ogr/ogr__api_8h.html
@@ -7,6 +7,7 @@
from django.contrib.gis.gdal import (OGRGeometry, OGRGeomType, OGRException,
OGRIndexError, SpatialReference, CoordTransform, GDAL_VERSION)
from django.contrib.gis.geometry.test_data import TestDataMixin
+from django.utils.six.moves import xrange
from django.utils import unittest
class OGRGeomTest(unittest.TestCase, TestDataMixin):
@@ -10,6 +10,7 @@
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
class GeometryCollection(GEOSGeometry):
_typeid = 7
@@ -100,11 +101,11 @@ class MultiLineString(GeometryCollection):
@property
def merged(self):
- """
- Returns a LineString representing the line merge of this
+ """
+ Returns a LineString representing the line merge of this
MultiLineString.
- """
- return self._topology(capi.geos_linemerge(self.ptr))
+ """
+ return self._topology(capi.geos_linemerge(self.ptr))
class MultiPolygon(GeometryCollection):
_allowed = Polygon
@@ -8,6 +8,7 @@
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
class GEOSCoordSeq(GEOSBase):
"The internal representation of a list of coordinates inside a Geometry."
@@ -4,6 +4,7 @@
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
class LineString(GEOSGeometry):
_init_func = capi.create_linestring
@@ -128,7 +129,7 @@ def array(self):
@property
def merged(self):
"Returns the line merge of this LineString."
- return self._topology(capi.geos_linemerge(self.ptr))
+ return self._topology(capi.geos_linemerge(self.ptr))
@property
def x(self):
@@ -10,6 +10,7 @@
"""
from django.utils.functional import total_ordering
from django.utils import six
+from django.utils.six.moves import xrange
@total_ordering
class ListMixin(object):
@@ -3,6 +3,7 @@
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
class Point(GEOSGeometry):
_minlength = 2
@@ -4,6 +4,7 @@
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
class Polygon(GEOSGeometry):
_minlength = 1
@@ -7,6 +7,7 @@
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
__all__ = ['geos_area', 'geos_distance', 'geos_length']
@@ -9,6 +9,7 @@
from django.contrib.gis.geometry.test_data import TestDataMixin
from django.utils import six
+from django.utils.six.moves import xrange
from django.utils import unittest
@@ -2,6 +2,7 @@
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.contrib.gis.maps.google.overlays import GPolygon, GPolyline, GMarker
@@ -1,5 +1,6 @@
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 math import pi, sin, log, exp, atan
# Constants used for degree to radian conversion, and vice-versa.
@@ -20,21 +21,21 @@ class GoogleZoom(object):
"Google Maps Hacks" may be found at http://safari.oreilly.com/0596101619
"""
-
+
def __init__(self, num_zoom=19, tilesize=256):
"Initializes the Google Zoom object."
# Google's tilesize is 256x256, square tiles are assumed.
self._tilesize = tilesize
-
+
# The number of zoom levels
self._nzoom = num_zoom
- # Initializing arrays to hold the parameters for each one of the
+ # Initializing arrays to hold the parameters for each one of the
# zoom levels.
self._degpp = [] # Degrees per pixel
self._radpp = [] # Radians per pixel
self._npix = [] # 1/2 the number of pixels for a tile at the given zoom level
-
+
# 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):
@@ -70,9 +71,9 @@ def lonlat_to_pixel(self, lonlat, zoom):
# with with the number of degrees/pixel at the given zoom level.
px_x = round(npix + (lon * self._degpp[zoom]))
- # Creating the factor, and ensuring that 1 or -1 is not passed in as the
+ # Creating the factor, and ensuring that 1 or -1 is not passed in as the
# base to the logarithm. Here's why:
- # if fac = -1, we'll get log(0) which is undefined;
+ # if fac = -1, we'll get log(0) which is undefined;
# if fac = 1, our logarithm base will be divided by 0, also undefined.
fac = min(max(sin(DTOR * lat), -0.9999), 0.9999)
@@ -98,7 +99,7 @@ def pixel_to_lonlat(self, px, zoom):
# Returning the longitude, latitude coordinate pair.
return (lon, lat)
-
+
def tile(self, lonlat, zoom):
"""
Returns a Polygon corresponding to the region represented by a fictional
@@ -119,7 +120,7 @@ def tile(self, lonlat, zoom):
# Constructing the Polygon, representing the tile and returning.
return Polygon(LinearRing(ll, (ll[0], ur[1]), ur, (ur[0], ll[1]), ll), srid=4326)
-
+
def get_zoom(self, geom):
"Returns the optimal Zoom level for the given geometry."
# Checking the input type.
@@ -139,10 +140,10 @@ def get_zoom(self, geom):
# When we span more than one tile, this is an approximately good
# zoom level.
if (env_w > tile_w) or (env_h > tile_h):
- if z == 0:
+ if z == 0:
raise GoogleMapException('Geometry width and height should not exceed that of the Earth.')
return z-1
-
+
# Otherwise, we've zoomed in to the max.
return self._nzoom-1
@@ -148,7 +148,7 @@ def _checksum(self, rfc):
if len(rfc) == 11:
rfc = '-' + rfc
- sum_ = sum(i * chars.index(c) for i, c in zip(reversed(xrange(14)), rfc))
+ sum_ = sum(i * chars.index(c) for i, c in zip(reversed(range(14)), rfc))
checksum = 11 - sum_ % 11
if checksum == 10:
@@ -215,7 +215,7 @@ def clean(self, value):
def _checksum(self, value):
chars = '0123456789ABCDEFGHIJKLMN&OPQRSTUVWXYZ'
- s = sum(i * chars.index(c) for i, c in zip(reversed(xrange(19)), value))
+ s = sum(i * chars.index(c) for i, c in zip(reversed(range(19)), value))
checksum = 10 - s % 10
if checksum == 10:
@@ -80,10 +80,10 @@ def clean(self, value):
raise ValidationError(self.error_messages['invalid'])
if int(value[0]) == 0:
raise ValidationError(self.error_messages['invalid'])
- chksum = (sum([int(value[i]) for i in xrange(0,9,2)])*7-
- sum([int(value[i]) for i in xrange(1,9,2)])) % 10
+ chksum = (sum([int(value[i]) for i in range(0, 9, 2)]) * 7 -
+ sum([int(value[i]) for i in range(1, 9, 2)])) % 10
if chksum != int(value[9]) or \
- (sum([int(value[i]) for i in xrange(10)]) % 10) != int(value[10]):
+ (sum([int(value[i]) for i in range(10)]) % 10) != int(value[10]):
raise ValidationError(self.error_messages['invalid'])
return value
@@ -152,7 +152,7 @@ def test_full_request_response_cycle(self):
cycle.
"""
data = {
- 'messages': ['Test message %d' % x for x in xrange(10)],
+ 'messages': ['Test message %d' % x for x in range(10)],
}
show_url = reverse('django.contrib.messages.tests.urls.show')
for level in ('debug', 'info', 'success', 'warning', 'error'):
@@ -170,7 +170,7 @@ def test_full_request_response_cycle(self):
@override_settings(MESSAGE_LEVEL=constants.DEBUG)
def test_with_template_response(self):
data = {
- 'messages': ['Test message %d' % x for x in xrange(10)],
+ 'messages': ['Test message %d' % x for x in range(10)],
}
show_url = reverse('django.contrib.messages.tests.urls.show_template_response')
for level in self.levels.keys():
@@ -194,7 +194,7 @@ def test_multiple_posts(self):
before a GET.
"""
data = {
- 'messages': ['Test message %d' % x for x in xrange(10)],
+ 'messages': ['Test message %d' % x for x in range(10)],
}
show_url = reverse('django.contrib.messages.tests.urls.show')
messages = []
@@ -226,7 +226,7 @@ def test_middleware_disabled(self):
when one attempts to store a message.
"""
data = {
- 'messages': ['Test message %d' % x for x in xrange(10)],
+ 'messages': ['Test message %d' % x for x in range(10)],
}
show_url = reverse('django.contrib.messages.tests.urls.show')
for level in ('debug', 'info', 'success', 'warning', 'error'):
@@ -251,7 +251,7 @@ def test_middleware_disabled_fail_silently(self):
raised if 'fail_silently' = True
"""
data = {
- 'messages': ['Test message %d' % x for x in xrange(10)],
+ 'messages': ['Test message %d' % x for x in range(10)],
'fail_silently': True,
}
show_url = reverse('django.contrib.messages.tests.urls.show')
@@ -123,7 +123,7 @@ def test_json_encoder_decoder(self):
{
'message': Message(constants.INFO, 'Test message'),
'message_list': [Message(constants.INFO, 'message %s') \
- for x in xrange(5)] + [{'another-message': \
+ for x in range(5)] + [{'another-message': \
Message(constants.ERROR, 'error')}],
},
Message(constants.INFO, 'message %s'),
@@ -1,5 +1,6 @@
from django.contrib.sessions.backends.base import SessionBase, CreateError
from django.core.cache import cache
+from django.utils.six.moves import xrange
KEY_PREFIX = "django.contrib.sessions.cache"
@@ -12,6 +12,7 @@
from django.db.models.fields import Field
from django.db.models.sql.datastructures import EmptyResultSet
from django.db.models.sql.aggregates import Aggregate
+from django.utils.six.moves import xrange
# Connection types
AND = 'AND'
Oops, something went wrong. Retry.

0 comments on commit a84d79f

Please sign in to comment.