mirror of https://github.com/django/django.git
[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.contrib.gis.gdal.prototypes import ds as capi
|
||||||
|
|
||||||
from django.utils import six
|
from django.utils import six
|
||||||
|
from django.utils.six.moves import xrange
|
||||||
|
|
||||||
# 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
|
||||||
|
|
|
@ -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.contrib.gis.gdal.prototypes import ds as capi, geom as geom_api
|
||||||
|
|
||||||
from django.utils import six
|
from django.utils import six
|
||||||
|
from django.utils.six.moves import xrange
|
||||||
|
|
||||||
# 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
|
||||||
|
|
|
@ -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.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
|
||||||
|
|
||||||
# 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
|
||||||
|
|
|
@ -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.contrib.gis.gdal.prototypes import ds as capi, geom as geom_api, srs as srs_api
|
||||||
|
|
||||||
from django.utils import six
|
from django.utils import six
|
||||||
|
from django.utils.six.moves import xrange
|
||||||
|
|
||||||
# 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
|
||||||
|
|
|
@ -7,6 +7,7 @@ except ImportError:
|
||||||
from django.contrib.gis.gdal import (OGRGeometry, OGRGeomType, OGRException,
|
from django.contrib.gis.gdal import (OGRGeometry, OGRGeomType, OGRException,
|
||||||
OGRIndexError, SpatialReference, CoordTransform, GDAL_VERSION)
|
OGRIndexError, SpatialReference, CoordTransform, GDAL_VERSION)
|
||||||
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 import unittest
|
from django.utils import unittest
|
||||||
|
|
||||||
class OGRGeomTest(unittest.TestCase, TestDataMixin):
|
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.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
|
||||||
|
|
||||||
class GeometryCollection(GEOSGeometry):
|
class GeometryCollection(GEOSGeometry):
|
||||||
_typeid = 7
|
_typeid = 7
|
||||||
|
@ -100,11 +101,11 @@ class MultiLineString(GeometryCollection):
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def merged(self):
|
def merged(self):
|
||||||
"""
|
"""
|
||||||
Returns a LineString representing the line merge of this
|
Returns a LineString representing the line merge of this
|
||||||
MultiLineString.
|
MultiLineString.
|
||||||
"""
|
"""
|
||||||
return self._topology(capi.geos_linemerge(self.ptr))
|
return self._topology(capi.geos_linemerge(self.ptr))
|
||||||
|
|
||||||
class MultiPolygon(GeometryCollection):
|
class MultiPolygon(GeometryCollection):
|
||||||
_allowed = Polygon
|
_allowed = Polygon
|
||||||
|
|
|
@ -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.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
|
||||||
|
|
||||||
class GEOSCoordSeq(GEOSBase):
|
class GEOSCoordSeq(GEOSBase):
|
||||||
"The internal representation of a list of coordinates inside a Geometry."
|
"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.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
|
||||||
|
|
||||||
class LineString(GEOSGeometry):
|
class LineString(GEOSGeometry):
|
||||||
_init_func = capi.create_linestring
|
_init_func = capi.create_linestring
|
||||||
|
@ -128,7 +129,7 @@ class LineString(GEOSGeometry):
|
||||||
@property
|
@property
|
||||||
def merged(self):
|
def merged(self):
|
||||||
"Returns the line merge of this LineString."
|
"Returns the line merge of this LineString."
|
||||||
return self._topology(capi.geos_linemerge(self.ptr))
|
return self._topology(capi.geos_linemerge(self.ptr))
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def x(self):
|
def x(self):
|
||||||
|
|
|
@ -10,6 +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
|
||||||
|
|
||||||
@total_ordering
|
@total_ordering
|
||||||
class ListMixin(object):
|
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.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
|
||||||
|
|
||||||
class Point(GEOSGeometry):
|
class Point(GEOSGeometry):
|
||||||
_minlength = 2
|
_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.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
|
||||||
|
|
||||||
class Polygon(GEOSGeometry):
|
class Polygon(GEOSGeometry):
|
||||||
_minlength = 1
|
_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.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
|
||||||
|
|
||||||
__all__ = ['geos_area', 'geos_distance', 'geos_length']
|
__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.contrib.gis.geometry.test_data import TestDataMixin
|
||||||
|
|
||||||
from django.utils import six
|
from django.utils import six
|
||||||
|
from django.utils.six.moves import xrange
|
||||||
from django.utils import unittest
|
from django.utils import unittest
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -2,6 +2,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.contrib.gis.maps.google.overlays import GPolygon, GPolyline, GMarker
|
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.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 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.
|
||||||
|
@ -20,21 +21,21 @@ class GoogleZoom(object):
|
||||||
|
|
||||||
"Google Maps Hacks" may be found at http://safari.oreilly.com/0596101619
|
"Google Maps Hacks" may be found at http://safari.oreilly.com/0596101619
|
||||||
"""
|
"""
|
||||||
|
|
||||||
def __init__(self, num_zoom=19, tilesize=256):
|
def __init__(self, num_zoom=19, tilesize=256):
|
||||||
"Initializes the Google Zoom object."
|
"Initializes the Google Zoom object."
|
||||||
# Google's tilesize is 256x256, square tiles are assumed.
|
# Google's tilesize is 256x256, square tiles are assumed.
|
||||||
self._tilesize = tilesize
|
self._tilesize = tilesize
|
||||||
|
|
||||||
# The number of zoom levels
|
# The number of zoom levels
|
||||||
self._nzoom = num_zoom
|
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.
|
# zoom levels.
|
||||||
self._degpp = [] # Degrees per pixel
|
self._degpp = [] # Degrees per pixel
|
||||||
self._radpp = [] # Radians per pixel
|
self._radpp = [] # Radians per pixel
|
||||||
self._npix = [] # 1/2 the number of pixels for a tile at the given zoom level
|
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.
|
# 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 xrange(num_zoom):
|
||||||
|
@ -70,9 +71,9 @@ class GoogleZoom(object):
|
||||||
# with with the number of degrees/pixel at the given zoom level.
|
# with with the number of degrees/pixel at the given zoom level.
|
||||||
px_x = round(npix + (lon * self._degpp[zoom]))
|
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:
|
# 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.
|
# if fac = 1, our logarithm base will be divided by 0, also undefined.
|
||||||
fac = min(max(sin(DTOR * lat), -0.9999), 0.9999)
|
fac = min(max(sin(DTOR * lat), -0.9999), 0.9999)
|
||||||
|
|
||||||
|
@ -98,7 +99,7 @@ class GoogleZoom(object):
|
||||||
|
|
||||||
# Returning the longitude, latitude coordinate pair.
|
# Returning the longitude, latitude coordinate pair.
|
||||||
return (lon, lat)
|
return (lon, lat)
|
||||||
|
|
||||||
def tile(self, lonlat, zoom):
|
def tile(self, lonlat, zoom):
|
||||||
"""
|
"""
|
||||||
Returns a Polygon corresponding to the region represented by a fictional
|
Returns a Polygon corresponding to the region represented by a fictional
|
||||||
|
@ -119,7 +120,7 @@ class GoogleZoom(object):
|
||||||
|
|
||||||
# Constructing the Polygon, representing the tile and returning.
|
# Constructing the Polygon, representing the tile and returning.
|
||||||
return Polygon(LinearRing(ll, (ll[0], ur[1]), ur, (ur[0], ll[1]), ll), srid=4326)
|
return Polygon(LinearRing(ll, (ll[0], ur[1]), ur, (ur[0], ll[1]), ll), srid=4326)
|
||||||
|
|
||||||
def get_zoom(self, geom):
|
def get_zoom(self, geom):
|
||||||
"Returns the optimal Zoom level for the given geometry."
|
"Returns the optimal Zoom level for the given geometry."
|
||||||
# Checking the input type.
|
# Checking the input type.
|
||||||
|
@ -139,10 +140,10 @@ class GoogleZoom(object):
|
||||||
# When we span more than one tile, this is an approximately good
|
# When we span more than one tile, this is an approximately good
|
||||||
# zoom level.
|
# zoom level.
|
||||||
if (env_w > tile_w) or (env_h > tile_h):
|
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.')
|
raise GoogleMapException('Geometry width and height should not exceed that of the Earth.')
|
||||||
return z-1
|
return z-1
|
||||||
|
|
||||||
# Otherwise, we've zoomed in to the max.
|
# Otherwise, we've zoomed in to the max.
|
||||||
return self._nzoom-1
|
return self._nzoom-1
|
||||||
|
|
||||||
|
|
|
@ -148,7 +148,7 @@ class MXRFCField(RegexField):
|
||||||
if len(rfc) == 11:
|
if len(rfc) == 11:
|
||||||
rfc = '-' + rfc
|
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
|
checksum = 11 - sum_ % 11
|
||||||
|
|
||||||
if checksum == 10:
|
if checksum == 10:
|
||||||
|
@ -215,7 +215,7 @@ class MXCURPField(RegexField):
|
||||||
def _checksum(self, value):
|
def _checksum(self, value):
|
||||||
chars = '0123456789ABCDEFGHIJKLMN&OPQRSTUVWXYZ'
|
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
|
checksum = 10 - s % 10
|
||||||
|
|
||||||
if checksum == 10:
|
if checksum == 10:
|
||||||
|
|
|
@ -80,10 +80,10 @@ class TRIdentificationNumberField(Field):
|
||||||
raise ValidationError(self.error_messages['invalid'])
|
raise ValidationError(self.error_messages['invalid'])
|
||||||
if int(value[0]) == 0:
|
if int(value[0]) == 0:
|
||||||
raise ValidationError(self.error_messages['invalid'])
|
raise ValidationError(self.error_messages['invalid'])
|
||||||
chksum = (sum([int(value[i]) for i in xrange(0,9,2)])*7-
|
chksum = (sum([int(value[i]) for i in range(0, 9, 2)]) * 7 -
|
||||||
sum([int(value[i]) for i in xrange(1,9,2)])) % 10
|
sum([int(value[i]) for i in range(1, 9, 2)])) % 10
|
||||||
if chksum != int(value[9]) or \
|
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'])
|
raise ValidationError(self.error_messages['invalid'])
|
||||||
return value
|
return value
|
||||||
|
|
||||||
|
|
|
@ -152,7 +152,7 @@ class BaseTest(TestCase):
|
||||||
cycle.
|
cycle.
|
||||||
"""
|
"""
|
||||||
data = {
|
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')
|
show_url = reverse('django.contrib.messages.tests.urls.show')
|
||||||
for level in ('debug', 'info', 'success', 'warning', 'error'):
|
for level in ('debug', 'info', 'success', 'warning', 'error'):
|
||||||
|
@ -170,7 +170,7 @@ class BaseTest(TestCase):
|
||||||
@override_settings(MESSAGE_LEVEL=constants.DEBUG)
|
@override_settings(MESSAGE_LEVEL=constants.DEBUG)
|
||||||
def test_with_template_response(self):
|
def test_with_template_response(self):
|
||||||
data = {
|
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')
|
show_url = reverse('django.contrib.messages.tests.urls.show_template_response')
|
||||||
for level in self.levels.keys():
|
for level in self.levels.keys():
|
||||||
|
@ -194,7 +194,7 @@ class BaseTest(TestCase):
|
||||||
before a GET.
|
before a GET.
|
||||||
"""
|
"""
|
||||||
data = {
|
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')
|
show_url = reverse('django.contrib.messages.tests.urls.show')
|
||||||
messages = []
|
messages = []
|
||||||
|
@ -226,7 +226,7 @@ class BaseTest(TestCase):
|
||||||
when one attempts to store a message.
|
when one attempts to store a message.
|
||||||
"""
|
"""
|
||||||
data = {
|
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')
|
show_url = reverse('django.contrib.messages.tests.urls.show')
|
||||||
for level in ('debug', 'info', 'success', 'warning', 'error'):
|
for level in ('debug', 'info', 'success', 'warning', 'error'):
|
||||||
|
@ -251,7 +251,7 @@ class BaseTest(TestCase):
|
||||||
raised if 'fail_silently' = True
|
raised if 'fail_silently' = True
|
||||||
"""
|
"""
|
||||||
data = {
|
data = {
|
||||||
'messages': ['Test message %d' % x for x in xrange(10)],
|
'messages': ['Test message %d' % x for x in range(10)],
|
||||||
'fail_silently': True,
|
'fail_silently': True,
|
||||||
}
|
}
|
||||||
show_url = reverse('django.contrib.messages.tests.urls.show')
|
show_url = reverse('django.contrib.messages.tests.urls.show')
|
||||||
|
|
|
@ -123,7 +123,7 @@ class CookieTest(BaseTest):
|
||||||
{
|
{
|
||||||
'message': Message(constants.INFO, 'Test message'),
|
'message': Message(constants.INFO, 'Test message'),
|
||||||
'message_list': [Message(constants.INFO, 'message %s') \
|
'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.ERROR, 'error')}],
|
||||||
},
|
},
|
||||||
Message(constants.INFO, 'message %s'),
|
Message(constants.INFO, 'message %s'),
|
||||||
|
|
|
@ -1,5 +1,6 @@
|
||||||
from django.contrib.sessions.backends.base import SessionBase, CreateError
|
from django.contrib.sessions.backends.base import SessionBase, CreateError
|
||||||
from django.core.cache import cache
|
from django.core.cache import cache
|
||||||
|
from django.utils.six.moves import xrange
|
||||||
|
|
||||||
KEY_PREFIX = "django.contrib.sessions.cache"
|
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.fields import Field
|
||||||
from django.db.models.sql.datastructures import EmptyResultSet
|
from django.db.models.sql.datastructures import EmptyResultSet
|
||||||
from django.db.models.sql.aggregates import Aggregate
|
from django.db.models.sql.aggregates import Aggregate
|
||||||
|
from django.utils.six.moves import xrange
|
||||||
|
|
||||||
# Connection types
|
# Connection types
|
||||||
AND = 'AND'
|
AND = 'AND'
|
||||||
|
|
|
@ -2,6 +2,7 @@ import weakref
|
||||||
import threading
|
import threading
|
||||||
|
|
||||||
from django.dispatch import saferef
|
from django.dispatch import saferef
|
||||||
|
from django.utils.six.moves import xrange
|
||||||
|
|
||||||
WEAKREF_TYPES = (weakref.ReferenceType, saferef.BoundMethodWeakref)
|
WEAKREF_TYPES = (weakref.ReferenceType, saferef.BoundMethodWeakref)
|
||||||
|
|
||||||
|
@ -13,17 +14,17 @@ def _make_id(target):
|
||||||
class Signal(object):
|
class Signal(object):
|
||||||
"""
|
"""
|
||||||
Base class for all signals
|
Base class for all signals
|
||||||
|
|
||||||
Internal attributes:
|
Internal attributes:
|
||||||
|
|
||||||
receivers
|
receivers
|
||||||
{ receriverkey (id) : weakref(receiver) }
|
{ receriverkey (id) : weakref(receiver) }
|
||||||
"""
|
"""
|
||||||
|
|
||||||
def __init__(self, providing_args=None):
|
def __init__(self, providing_args=None):
|
||||||
"""
|
"""
|
||||||
Create a new signal.
|
Create a new signal.
|
||||||
|
|
||||||
providing_args
|
providing_args
|
||||||
A list of the arguments this signal can pass along in a send() call.
|
A list of the arguments this signal can pass along in a send() call.
|
||||||
"""
|
"""
|
||||||
|
@ -36,9 +37,9 @@ class Signal(object):
|
||||||
def connect(self, receiver, sender=None, weak=True, dispatch_uid=None):
|
def connect(self, receiver, sender=None, weak=True, dispatch_uid=None):
|
||||||
"""
|
"""
|
||||||
Connect receiver to sender for signal.
|
Connect receiver to sender for signal.
|
||||||
|
|
||||||
Arguments:
|
Arguments:
|
||||||
|
|
||||||
receiver
|
receiver
|
||||||
A function or an instance method which is to receive signals.
|
A function or an instance method which is to receive signals.
|
||||||
Receivers must be hashable objects.
|
Receivers must be hashable objects.
|
||||||
|
@ -46,7 +47,7 @@ class Signal(object):
|
||||||
If weak is True, then receiver must be weak-referencable (more
|
If weak is True, then receiver must be weak-referencable (more
|
||||||
precisely saferef.safeRef() must be able to create a reference
|
precisely saferef.safeRef() must be able to create a reference
|
||||||
to the receiver).
|
to the receiver).
|
||||||
|
|
||||||
Receivers must be able to accept keyword arguments.
|
Receivers must be able to accept keyword arguments.
|
||||||
|
|
||||||
If receivers have a dispatch_uid attribute, the receiver will
|
If receivers have a dispatch_uid attribute, the receiver will
|
||||||
|
@ -62,19 +63,19 @@ class Signal(object):
|
||||||
module will attempt to use weak references to the receiver
|
module will attempt to use weak references to the receiver
|
||||||
objects. If this parameter is false, then strong references will
|
objects. If this parameter is false, then strong references will
|
||||||
be used.
|
be used.
|
||||||
|
|
||||||
dispatch_uid
|
dispatch_uid
|
||||||
An identifier used to uniquely identify a particular instance of
|
An identifier used to uniquely identify a particular instance of
|
||||||
a receiver. This will usually be a string, though it may be
|
a receiver. This will usually be a string, though it may be
|
||||||
anything hashable.
|
anything hashable.
|
||||||
"""
|
"""
|
||||||
from django.conf import settings
|
from django.conf import settings
|
||||||
|
|
||||||
# If DEBUG is on, check that we got a good receiver
|
# If DEBUG is on, check that we got a good receiver
|
||||||
if settings.DEBUG:
|
if settings.DEBUG:
|
||||||
import inspect
|
import inspect
|
||||||
assert callable(receiver), "Signal receivers must be callable."
|
assert callable(receiver), "Signal receivers must be callable."
|
||||||
|
|
||||||
# Check for **kwargs
|
# Check for **kwargs
|
||||||
# Not all callables are inspectable with getargspec, so we'll
|
# Not all callables are inspectable with getargspec, so we'll
|
||||||
# try a couple different ways but in the end fall back on assuming
|
# try a couple different ways but in the end fall back on assuming
|
||||||
|
@ -90,7 +91,7 @@ class Signal(object):
|
||||||
if argspec:
|
if argspec:
|
||||||
assert argspec[2] is not None, \
|
assert argspec[2] is not None, \
|
||||||
"Signal receivers must accept keyword arguments (**kwargs)."
|
"Signal receivers must accept keyword arguments (**kwargs)."
|
||||||
|
|
||||||
if dispatch_uid:
|
if dispatch_uid:
|
||||||
lookup_key = (dispatch_uid, _make_id(sender))
|
lookup_key = (dispatch_uid, _make_id(sender))
|
||||||
else:
|
else:
|
||||||
|
@ -112,19 +113,19 @@ class Signal(object):
|
||||||
|
|
||||||
If weak references are used, disconnect need not be called. The receiver
|
If weak references are used, disconnect need not be called. The receiver
|
||||||
will be remove from dispatch automatically.
|
will be remove from dispatch automatically.
|
||||||
|
|
||||||
Arguments:
|
Arguments:
|
||||||
|
|
||||||
receiver
|
receiver
|
||||||
The registered receiver to disconnect. May be none if
|
The registered receiver to disconnect. May be none if
|
||||||
dispatch_uid is specified.
|
dispatch_uid is specified.
|
||||||
|
|
||||||
sender
|
sender
|
||||||
The registered sender to disconnect
|
The registered sender to disconnect
|
||||||
|
|
||||||
weak
|
weak
|
||||||
The weakref state to disconnect
|
The weakref state to disconnect
|
||||||
|
|
||||||
dispatch_uid
|
dispatch_uid
|
||||||
the unique identifier of the receiver to disconnect
|
the unique identifier of the receiver to disconnect
|
||||||
"""
|
"""
|
||||||
|
@ -149,10 +150,10 @@ class Signal(object):
|
||||||
receivers called if a raises an error.
|
receivers called if a raises an error.
|
||||||
|
|
||||||
Arguments:
|
Arguments:
|
||||||
|
|
||||||
sender
|
sender
|
||||||
The sender of the signal Either a specific object or None.
|
The sender of the signal Either a specific object or None.
|
||||||
|
|
||||||
named
|
named
|
||||||
Named arguments which will be passed to receivers.
|
Named arguments which will be passed to receivers.
|
||||||
|
|
||||||
|
@ -172,7 +173,7 @@ class Signal(object):
|
||||||
Send signal from sender to all connected receivers catching errors.
|
Send signal from sender to all connected receivers catching errors.
|
||||||
|
|
||||||
Arguments:
|
Arguments:
|
||||||
|
|
||||||
sender
|
sender
|
||||||
The sender of the signal. Can be any python object (normally one
|
The sender of the signal. Can be any python object (normally one
|
||||||
registered with a connect if you actually want something to
|
registered with a connect if you actually want something to
|
||||||
|
|
|
@ -8,6 +8,7 @@ from django.forms.widgets import Media, HiddenInput
|
||||||
from django.utils.encoding import StrAndUnicode
|
from django.utils.encoding import StrAndUnicode
|
||||||
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.translation import ugettext as _
|
from django.utils.translation import ugettext as _
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -24,6 +24,7 @@ except NotImplementedError:
|
||||||
|
|
||||||
from django.conf import settings
|
from django.conf import settings
|
||||||
from django.utils.encoding import smart_str
|
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)])
|
_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'):
|
if not hasattr(package, 'rindex'):
|
||||||
raise ValueError("'package' not set to a string")
|
raise ValueError("'package' not set to a string")
|
||||||
dot = len(package)
|
dot = len(package)
|
||||||
for x in xrange(level, 1, -1):
|
for x in range(level, 1, -1):
|
||||||
try:
|
try:
|
||||||
dot = package.rindex('.', 0, dot)
|
dot = package.rindex('.', 0, dot)
|
||||||
except ValueError:
|
except ValueError:
|
||||||
|
|
|
@ -2,6 +2,7 @@
|
||||||
# Copyright 2007 Google Inc. http://code.google.com/p/ipaddr-py/
|
# Copyright 2007 Google Inc. http://code.google.com/p/ipaddr-py/
|
||||||
# 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.six.moves import xrange
|
||||||
|
|
||||||
def clean_ipv6_address(ip_str, unpack_ipv4=False,
|
def clean_ipv6_address(ip_str, unpack_ipv4=False,
|
||||||
error_message="This is not a valid IPv6 address"):
|
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.db import models, IntegrityError
|
||||||
from django.test import TestCase, skipUnlessDBFeature, skipIfDBFeature
|
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,
|
from .models import (R, RChild, S, T, U, A, M, MR, MRNull,
|
||||||
create_a, get_default_r, User, Avatar, HiddenUser, HiddenUserProfile)
|
create_a, get_default_r, User, Avatar, HiddenUser, HiddenUserProfile)
|
||||||
|
|
|
@ -88,8 +88,8 @@ class ManyToOneNullTests(TestCase):
|
||||||
|
|
||||||
def test_clear_efficiency(self):
|
def test_clear_efficiency(self):
|
||||||
r = Reporter.objects.create()
|
r = Reporter.objects.create()
|
||||||
for _ in xrange(3):
|
for _ in range(3):
|
||||||
r.article_set.create()
|
r.article_set.create()
|
||||||
with self.assertNumQueries(1):
|
with self.assertNumQueries(1):
|
||||||
r.article_set.clear()
|
r.article_set.clear()
|
||||||
self.assertEqual(r.article_set.count(), 0)
|
self.assertEqual(r.article_set.count(), 0)
|
||||||
|
|
|
@ -17,6 +17,7 @@ from django.test import (TestCase, skipUnlessDBFeature, skipIfDBFeature,
|
||||||
TransactionTestCase)
|
TransactionTestCase)
|
||||||
from django.test.utils import override_settings
|
from django.test.utils import override_settings
|
||||||
from django.utils import six
|
from django.utils import six
|
||||||
|
from django.utils.six.moves import xrange
|
||||||
from django.utils import unittest
|
from django.utils import unittest
|
||||||
|
|
||||||
from . import models
|
from . import models
|
||||||
|
@ -531,7 +532,7 @@ class ThreadTests(TestCase):
|
||||||
from django.db import connection
|
from django.db import connection
|
||||||
connection.cursor()
|
connection.cursor()
|
||||||
connections_set.add(connection.connection)
|
connections_set.add(connection.connection)
|
||||||
for x in xrange(2):
|
for x in range(2):
|
||||||
t = threading.Thread(target=runner)
|
t = threading.Thread(target=runner)
|
||||||
t.start()
|
t.start()
|
||||||
t.join()
|
t.join()
|
||||||
|
@ -558,7 +559,7 @@ class ThreadTests(TestCase):
|
||||||
# main thread.
|
# main thread.
|
||||||
conn.allow_thread_sharing = True
|
conn.allow_thread_sharing = True
|
||||||
connections_set.add(conn)
|
connections_set.add(conn)
|
||||||
for x in xrange(2):
|
for x in range(2):
|
||||||
t = threading.Thread(target=runner)
|
t = threading.Thread(target=runner)
|
||||||
t.start()
|
t.start()
|
||||||
t.join()
|
t.join()
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
from django.dispatch.saferef import safeRef
|
from django.dispatch.saferef import safeRef
|
||||||
|
from django.utils.six.moves import xrange
|
||||||
from django.utils import unittest
|
from django.utils import unittest
|
||||||
|
|
||||||
|
|
||||||
class Test1(object):
|
class Test1(object):
|
||||||
def x(self):
|
def x(self):
|
||||||
pass
|
pass
|
||||||
|
@ -70,4 +70,4 @@ class SaferefTests(unittest.TestCase):
|
||||||
|
|
||||||
def _closure(self, ref):
|
def _closure(self, ref):
|
||||||
"""Dumb utility mechanism to increment deletion counter"""
|
"""Dumb utility mechanism to increment deletion counter"""
|
||||||
self.closureCount +=1
|
self.closureCount +=1
|
||||||
|
|
|
@ -15,6 +15,7 @@ from django.middleware.http import ConditionalGetMiddleware
|
||||||
from django.middleware.gzip import GZipMiddleware
|
from django.middleware.gzip import GZipMiddleware
|
||||||
from django.test import TestCase, RequestFactory
|
from django.test import TestCase, RequestFactory
|
||||||
from django.test.utils import override_settings
|
from django.test.utils import override_settings
|
||||||
|
from django.utils.six.moves import xrange
|
||||||
|
|
||||||
class CommonMiddlewareTest(TestCase):
|
class CommonMiddlewareTest(TestCase):
|
||||||
def setUp(self):
|
def setUp(self):
|
||||||
|
|
|
@ -98,7 +98,7 @@ class SortedDictTests(SimpleTestCase):
|
||||||
self.assertEqual(l - len(self.d1), 1)
|
self.assertEqual(l - len(self.d1), 1)
|
||||||
|
|
||||||
def test_dict_equality(self):
|
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})
|
self.assertEqual(d, {0: 0, 1: 1, 2: 2})
|
||||||
|
|
||||||
def test_tuple_init(self):
|
def test_tuple_init(self):
|
||||||
|
|
Loading…
Reference in New Issue