[py3] Added Python 3 compatibility for xrange.
This commit is contained in:
parent
ca07fda2ef
commit
a84d79f572
|
@ -46,6 +46,7 @@ from django.contrib.gis.gdal.layer import Layer
|
|||
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.geometries import OGRGeometry, OGRGeomType
|
|||
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.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
|
||||
|
||||
# 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.srs import SpatialReference
|
|||
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 @@ except ImportError:
|
|||
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.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
|
||||
|
||||
class GeometryCollection(GEOSGeometry):
|
||||
_typeid = 7
|
||||
|
|
|
@ -8,6 +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
|
||||
|
||||
class GEOSCoordSeq(GEOSBase):
|
||||
"The internal representation of a list of coordinates inside a Geometry."
|
||||
|
|
|
@ -4,6 +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
|
||||
|
||||
class LineString(GEOSGeometry):
|
||||
_init_func = capi.create_linestring
|
||||
|
|
|
@ -10,6 +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
|
||||
|
||||
@total_ordering
|
||||
class ListMixin(object):
|
||||
|
|
|
@ -3,6 +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
|
||||
|
||||
class Point(GEOSGeometry):
|
||||
_minlength = 2
|
||||
|
|
|
@ -4,6 +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
|
||||
|
||||
class Polygon(GEOSGeometry):
|
||||
_minlength = 1
|
||||
|
|
|
@ -7,6 +7,7 @@ from django.contrib.gis.geos.libgeos import GEOM_PTR, GEOS_PREPARE
|
|||
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.geos.libgeos import GEOS_PREPARE
|
|||
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.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.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.
|
||||
|
|
|
@ -148,7 +148,7 @@ class MXRFCField(RegexField):
|
|||
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 @@ class MXCURPField(RegexField):
|
|||
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 @@ class TRIdentificationNumberField(Field):
|
|||
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 @@ class BaseTest(TestCase):
|
|||
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 @@ class BaseTest(TestCase):
|
|||
@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 @@ class BaseTest(TestCase):
|
|||
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 @@ class BaseTest(TestCase):
|
|||
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 @@ class BaseTest(TestCase):
|
|||
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 @@ class CookieTest(BaseTest):
|
|||
{
|
||||
'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.utils import tree
|
|||
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'
|
||||
|
|
|
@ -2,6 +2,7 @@ import weakref
|
|||
import threading
|
||||
|
||||
from django.dispatch import saferef
|
||||
from django.utils.six.moves import xrange
|
||||
|
||||
WEAKREF_TYPES = (weakref.ReferenceType, saferef.BoundMethodWeakref)
|
||||
|
||||
|
|
|
@ -8,6 +8,7 @@ from django.forms.widgets import Media, HiddenInput
|
|||
from django.utils.encoding import StrAndUnicode
|
||||
from django.utils.safestring import mark_safe
|
||||
from django.utils import six
|
||||
from django.utils.six.moves import xrange
|
||||
from django.utils.translation import ugettext as _
|
||||
|
||||
|
||||
|
|
|
@ -24,6 +24,7 @@ except NotImplementedError:
|
|||
|
||||
from django.conf import settings
|
||||
from django.utils.encoding import smart_str
|
||||
from django.utils.six.moves import xrange
|
||||
|
||||
|
||||
_trans_5c = b"".join([chr(x ^ 0x5C) for x in xrange(256)])
|
||||
|
|
|
@ -6,7 +6,7 @@ def _resolve_name(name, package, level):
|
|||
if not hasattr(package, 'rindex'):
|
||||
raise ValueError("'package' not set to a string")
|
||||
dot = len(package)
|
||||
for x in xrange(level, 1, -1):
|
||||
for x in range(level, 1, -1):
|
||||
try:
|
||||
dot = package.rindex('.', 0, dot)
|
||||
except ValueError:
|
||||
|
|
|
@ -2,6 +2,7 @@
|
|||
# Copyright 2007 Google Inc. http://code.google.com/p/ipaddr-py/
|
||||
# Licensed under the Apache License, Version 2.0 (the "License").
|
||||
from django.core.exceptions import ValidationError
|
||||
from django.utils.six.moves import xrange
|
||||
|
||||
def clean_ipv6_address(ip_str, unpack_ipv4=False,
|
||||
error_message="This is not a valid IPv6 address"):
|
||||
|
|
|
@ -2,6 +2,7 @@ from __future__ import absolute_import
|
|||
|
||||
from django.db import models, IntegrityError
|
||||
from django.test import TestCase, skipUnlessDBFeature, skipIfDBFeature
|
||||
from django.utils.six.moves import xrange
|
||||
|
||||
from .models import (R, RChild, S, T, U, A, M, MR, MRNull,
|
||||
create_a, get_default_r, User, Avatar, HiddenUser, HiddenUserProfile)
|
||||
|
|
|
@ -88,7 +88,7 @@ class ManyToOneNullTests(TestCase):
|
|||
|
||||
def test_clear_efficiency(self):
|
||||
r = Reporter.objects.create()
|
||||
for _ in xrange(3):
|
||||
for _ in range(3):
|
||||
r.article_set.create()
|
||||
with self.assertNumQueries(1):
|
||||
r.article_set.clear()
|
||||
|
|
|
@ -17,6 +17,7 @@ from django.test import (TestCase, skipUnlessDBFeature, skipIfDBFeature,
|
|||
TransactionTestCase)
|
||||
from django.test.utils import override_settings
|
||||
from django.utils import six
|
||||
from django.utils.six.moves import xrange
|
||||
from django.utils import unittest
|
||||
|
||||
from . import models
|
||||
|
@ -531,7 +532,7 @@ class ThreadTests(TestCase):
|
|||
from django.db import connection
|
||||
connection.cursor()
|
||||
connections_set.add(connection.connection)
|
||||
for x in xrange(2):
|
||||
for x in range(2):
|
||||
t = threading.Thread(target=runner)
|
||||
t.start()
|
||||
t.join()
|
||||
|
@ -558,7 +559,7 @@ class ThreadTests(TestCase):
|
|||
# main thread.
|
||||
conn.allow_thread_sharing = True
|
||||
connections_set.add(conn)
|
||||
for x in xrange(2):
|
||||
for x in range(2):
|
||||
t = threading.Thread(target=runner)
|
||||
t.start()
|
||||
t.join()
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
from django.dispatch.saferef import safeRef
|
||||
from django.utils.six.moves import xrange
|
||||
from django.utils import unittest
|
||||
|
||||
|
||||
class Test1(object):
|
||||
def x(self):
|
||||
pass
|
||||
|
|
|
@ -15,6 +15,7 @@ from django.middleware.http import ConditionalGetMiddleware
|
|||
from django.middleware.gzip import GZipMiddleware
|
||||
from django.test import TestCase, RequestFactory
|
||||
from django.test.utils import override_settings
|
||||
from django.utils.six.moves import xrange
|
||||
|
||||
class CommonMiddlewareTest(TestCase):
|
||||
def setUp(self):
|
||||
|
|
|
@ -98,7 +98,7 @@ class SortedDictTests(SimpleTestCase):
|
|||
self.assertEqual(l - len(self.d1), 1)
|
||||
|
||||
def test_dict_equality(self):
|
||||
d = SortedDict((i, i) for i in xrange(3))
|
||||
d = SortedDict((i, i) for i in range(3))
|
||||
self.assertEqual(d, {0: 0, 1: 1, 2: 2})
|
||||
|
||||
def test_tuple_init(self):
|
||||
|
|
Loading…
Reference in New Issue