Skip to content

Commit 56dbe92

Browse files
committed
[py3] Removed longs.
1 parent f1d5dc8 commit 56dbe92

File tree

26 files changed

+100
-79
lines changed

26 files changed

+100
-79
lines changed

django/contrib/admin/util.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
from django.utils.text import capfirst
1414
from django.utils import timezone
1515
from django.utils.encoding import force_unicode, smart_unicode, smart_str
16+
from django.utils import six
1617
from django.utils.translation import ungettext
1718
from django.core.urlresolvers import reverse
1819

@@ -349,7 +350,7 @@ def display_for_value(value, boolean=False):
349350
return formats.localize(timezone.template_localtime(value))
350351
elif isinstance(value, (datetime.date, datetime.time)):
351352
return formats.localize(value)
352-
elif isinstance(value, (decimal.Decimal, float, int, long)):
353+
elif isinstance(value, six.integer_types + (decimal.Decimal, float)):
353354
return formats.number_format(value)
354355
else:
355356
return smart_unicode(value)

django/contrib/gis/db/backends/oracle/operations.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
from django.contrib.gis.db.backends.util import SpatialFunction
1717
from django.contrib.gis.geometry.backend import Geometry
1818
from django.contrib.gis.measure import Distance
19+
from django.utils import six
1920

2021
class SDOOperation(SpatialFunction):
2122
"Base class for SDO* Oracle operations."
@@ -65,7 +66,7 @@ def __init__(self, mask):
6566
super(SDORelate, self).__init__(self.relate_func, mask=mask)
6667

6768
# Valid distance types and substitutions
68-
dtypes = (Decimal, Distance, float, int, long)
69+
dtypes = (Decimal, Distance, float) + six.integer_types
6970

7071
class OracleOperations(DatabaseOperations, BaseSpatialOperations):
7172
compiler_module = "django.contrib.gis.db.backends.oracle.compiler"

django/contrib/gis/db/backends/postgis/operations.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
from django.core.exceptions import ImproperlyConfigured
1111
from django.db.backends.postgresql_psycopg2.base import DatabaseOperations
1212
from django.db.utils import DatabaseError
13+
from django.utils import six
1314

1415
#### Classes used in constructing PostGIS spatial SQL ####
1516
class PostGISOperator(SpatialOperation):
@@ -165,7 +166,7 @@ def __init__(self, connection):
165166
}
166167

167168
# Valid distance types and substitutions
168-
dtypes = (Decimal, Distance, float, int, long)
169+
dtypes = (Decimal, Distance, float) + six.integer_types
169170
def get_dist_ops(operator):
170171
"Returns operations for both regular and spherical distances."
171172
return {'cartesian' : PostGISDistance(prefix, operator),

django/contrib/gis/db/backends/spatialite/operations.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
from django.core.exceptions import ImproperlyConfigured
1010
from django.db.backends.sqlite3.base import DatabaseOperations
1111
from django.db.utils import DatabaseError
12+
from django.utils import six
1213

1314
class SpatiaLiteOperator(SpatialOperation):
1415
"For SpatiaLite operators (e.g. `&&`, `~`)."
@@ -42,7 +43,7 @@ def __init__(self, pattern):
4243
super(SpatiaLiteRelate, self).__init__('Relate')
4344

4445
# Valid distance types and substitutions
45-
dtypes = (Decimal, Distance, float, int, long)
46+
dtypes = (Decimal, Distance, float) + six.integer_types
4647
def get_dist_ops(operator):
4748
"Returns operations for regular distances; spherical distances are not currently supported."
4849
return (SpatiaLiteDistance(operator),)

django/contrib/gis/db/models/query.py

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
from django.contrib.gis.db.models.sql import AreaField, DistanceField, GeomField, GeoQuery
77
from django.contrib.gis.geometry.backend import Geometry
88
from django.contrib.gis.measure import Area, Distance
9+
from django.utils import six
910

1011
class GeoQuerySet(QuerySet):
1112
"The Geographic QuerySet."
@@ -144,7 +145,7 @@ def geojson(self, precision=8, crs=False, bbox=False, **kwargs):
144145
if not backend.geojson:
145146
raise NotImplementedError('Only PostGIS 1.3.4+ supports GeoJSON serialization.')
146147

147-
if not isinstance(precision, (int, long)):
148+
if not isinstance(precision, six.integer_types):
148149
raise TypeError('Precision keyword must be set with an integer.')
149150

150151
# Setting the options flag -- which depends on which version of
@@ -173,7 +174,7 @@ def geohash(self, precision=20, **kwargs):
173174
The `precision` keyword may be used to custom the number of
174175
_characters_ used in the output GeoHash, the default is 20.
175176
"""
176-
s = {'desc' : 'GeoHash',
177+
s = {'desc' : 'GeoHash',
177178
'procedure_args': {'precision': precision},
178179
'procedure_fmt': '%(geo_col)s,%(precision)s',
179180
}
@@ -309,7 +310,7 @@ def snap_to_grid(self, *args, **kwargs):
309310
- 2 arguments: X and Y sizes to snap the grid to.
310311
- 4 arguments: X, Y sizes and the X, Y origins.
311312
"""
312-
if False in [isinstance(arg, (float, int, long)) for arg in args]:
313+
if False in [isinstance(arg, (float,) + six.integer_types) for arg in args]:
313314
raise TypeError('Size argument(s) for the grid must be a float or integer values.')
314315

315316
nargs = len(args)
@@ -349,7 +350,7 @@ def svg(self, relative=False, precision=8, **kwargs):
349350
digits used in output (defaults to 8).
350351
"""
351352
relative = int(bool(relative))
352-
if not isinstance(precision, (int, long)):
353+
if not isinstance(precision, six.integer_types):
353354
raise TypeError('SVG precision keyword argument must be an integer.')
354355
s = {'desc' : 'SVG',
355356
'procedure_fmt' : '%(geo_col)s,%(rel)s,%(precision)s',
@@ -390,7 +391,7 @@ def transform(self, srid=4326, **kwargs):
390391
Transforms the given geometry field to the given SRID. If no SRID is
391392
provided, the transformation will default to using 4326 (WGS84).
392393
"""
393-
if not isinstance(srid, (int, long)):
394+
if not isinstance(srid, six.integer_types):
394395
raise TypeError('An integer SRID must be provided.')
395396
field_name = kwargs.get('field_name', None)
396397
tmp, geo_field = self._spatial_setup('transform', field_name=field_name)

django/contrib/gis/gdal/base.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
from ctypes import c_void_p
22

33
from django.contrib.gis.gdal.error import GDALException
4+
from django.utils import six
45

56
class GDALBase(object):
67
"""
@@ -24,7 +25,7 @@ def _get_ptr(self):
2425
def _set_ptr(self, ptr):
2526
# Only allow the pointer to be set with pointers of the
2627
# compatible type or None (NULL).
27-
if isinstance(ptr, (int, long)):
28+
if isinstance(ptr, six.integer_types):
2829
self._ptr = self.ptr_type(ptr)
2930
elif ptr is None or isinstance(ptr, self.ptr_type):
3031
self._ptr = ptr

django/contrib/gis/gdal/geometries.py

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,8 @@
5757
# For recognizing geometry input.
5858
from django.contrib.gis.geometry.regex import hex_regex, wkt_regex, json_regex
5959

60+
from django.utils import six
61+
6062
# For more information, see the OGR C API source code:
6163
# http://www.gdal.org/ogr/ogr__api_8h.html
6264
#
@@ -281,7 +283,7 @@ def _set_srs(self, srs):
281283
# (decremented) when this geometry's destructor is called.
282284
if isinstance(srs, SpatialReference):
283285
srs_ptr = srs.ptr
284-
elif isinstance(srs, (int, long, basestring)):
286+
elif isinstance(srs, six.integer_types + (basestring,)):
285287
sr = SpatialReference(srs)
286288
srs_ptr = sr.ptr
287289
else:
@@ -297,7 +299,7 @@ def _get_srid(self):
297299
return None
298300

299301
def _set_srid(self, srid):
300-
if isinstance(srid, (int, long)):
302+
if isinstance(srid, six.integer_types):
301303
self.srs = srid
302304
else:
303305
raise TypeError('SRID must be set with an integer.')
@@ -410,7 +412,7 @@ def transform(self, coord_trans, clone=False):
410412
capi.geom_transform(self.ptr, coord_trans.ptr)
411413
elif isinstance(coord_trans, SpatialReference):
412414
capi.geom_transform_to(self.ptr, coord_trans.ptr)
413-
elif isinstance(coord_trans, (int, long, basestring)):
415+
elif isinstance(coord_trans, six.integer_types + (basestring,)):
414416
sr = SpatialReference(coord_trans)
415417
capi.geom_transform_to(self.ptr, sr.ptr)
416418
else:

django/contrib/gis/gdal/layer.py

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,8 @@
1414
# GDAL ctypes function prototypes.
1515
from django.contrib.gis.gdal.prototypes import ds as capi, geom as geom_api, srs as srs_api
1616

17+
from django.utils import six
18+
1719
# For more information, see the OGR C API source code:
1820
# http://www.gdal.org/ogr/ogr__api_8h.html
1921
#
@@ -25,8 +27,8 @@ class Layer(GDALBase):
2527
def __init__(self, layer_ptr, ds):
2628
"""
2729
Initializes on an OGR C pointer to the Layer and the `DataSource` object
28-
that owns this layer. The `DataSource` object is required so that a
29-
reference to it is kept with this Layer. This prevents garbage
30+
that owns this layer. The `DataSource` object is required so that a
31+
reference to it is kept with this Layer. This prevents garbage
3032
collection of the `DataSource` while this Layer is still active.
3133
"""
3234
if not layer_ptr:
@@ -39,7 +41,7 @@ def __init__(self, layer_ptr, ds):
3941

4042
def __getitem__(self, index):
4143
"Gets the Feature at the specified index."
42-
if isinstance(index, (int, long)):
44+
if isinstance(index, six.integer_types):
4345
# An integer index was given -- we cannot do a check based on the
4446
# number of features because the beginning and ending feature IDs
4547
# are not guaranteed to be 0 and len(layer)-1, respectively.
@@ -85,7 +87,7 @@ def _make_feature(self, feat_id):
8587
# each feature until the given feature ID is encountered.
8688
for feat in self:
8789
if feat.fid == feat_id: return feat
88-
# Should have returned a Feature, raise an OGRIndexError.
90+
# Should have returned a Feature, raise an OGRIndexError.
8991
raise OGRIndexError('Invalid feature id: %s.' % feat_id)
9092

9193
#### Layer properties ####
@@ -131,9 +133,9 @@ def fields(self):
131133
Returns a list of string names corresponding to each of the Fields
132134
available in this Layer.
133135
"""
134-
return [capi.get_field_name(capi.get_field_defn(self._ldefn, i))
136+
return [capi.get_field_name(capi.get_field_defn(self._ldefn, i))
135137
for i in xrange(self.num_fields) ]
136-
138+
137139
@property
138140
def field_types(self):
139141
"""
@@ -145,13 +147,13 @@ def field_types(self):
145147
return [OGRFieldTypes[capi.get_field_type(capi.get_field_defn(self._ldefn, i))]
146148
for i in xrange(self.num_fields)]
147149

148-
@property
150+
@property
149151
def field_widths(self):
150152
"Returns a list of the maximum field widths for the features."
151153
return [capi.get_field_width(capi.get_field_defn(self._ldefn, i))
152154
for i in xrange(self.num_fields)]
153155

154-
@property
156+
@property
155157
def field_precisions(self):
156158
"Returns the field precisions for the features."
157159
return [capi.get_field_precision(capi.get_field_defn(self._ldefn, i))

django/contrib/gis/gdal/prototypes/errcheck.py

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,10 @@
55
from ctypes import c_void_p, string_at
66
from django.contrib.gis.gdal.error import check_err, OGRException, SRSException
77
from django.contrib.gis.gdal.libgdal import lgdal
8+
from django.utils import six
89

9-
# Helper routines for retrieving pointers and/or values from
10-
# arguments passed in by reference.
10+
# Helper routines for retrieving pointers and/or values from
11+
# arguments passed in by reference.
1112
def arg_byref(args, offset=-1):
1213
"Returns the pointer argument's by-refernece value."
1314
return args[offset]._obj.value
@@ -53,7 +54,7 @@ def check_string(result, func, cargs, offset=-1, str_result=False):
5354
ptr = ptr_byref(cargs, offset)
5455
# Getting the string value
5556
s = ptr.value
56-
# Correctly freeing the allocated memory beind GDAL pointer
57+
# Correctly freeing the allocated memory beind GDAL pointer
5758
# w/the VSIFree routine.
5859
if ptr: lgdal.VSIFree(ptr)
5960
return s
@@ -71,9 +72,9 @@ def check_geom(result, func, cargs):
7172
"Checks a function that returns a geometry."
7273
# OGR_G_Clone may return an integer, even though the
7374
# restype is set to c_void_p
74-
if isinstance(result, (int, long)):
75+
if isinstance(result, six.integer_types):
7576
result = c_void_p(result)
76-
if not result:
77+
if not result:
7778
raise OGRException('Invalid geometry pointer returned from "%s".' % func.__name__)
7879
return result
7980

@@ -85,7 +86,7 @@ def check_geom_offset(result, func, cargs, offset=-1):
8586

8687
### Spatial Reference error-checking routines ###
8788
def check_srs(result, func, cargs):
88-
if isinstance(result, (int, long)):
89+
if isinstance(result, six.integer_types):
8990
result = c_void_p(result)
9091
if not result:
9192
raise SRSException('Invalid spatial reference pointer returned from "%s".' % func.__name__)
@@ -109,11 +110,11 @@ def check_errcode(result, func, cargs):
109110

110111
def check_pointer(result, func, cargs):
111112
"Makes sure the result pointer is valid."
112-
if isinstance(result, (int, long)):
113+
if isinstance(result, six.integer_types):
113114
result = c_void_p(result)
114-
if bool(result):
115+
if bool(result):
115116
return result
116-
else:
117+
else:
117118
raise OGRException('Invalid pointer returned from "%s"' % func.__name__)
118119

119120
def check_str_arg(result, func, cargs):

django/contrib/gis/gdal/srs.py

Lines changed: 14 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -33,20 +33,22 @@
3333
from django.contrib.gis.gdal.error import SRSException
3434
from django.contrib.gis.gdal.prototypes import srs as capi
3535

36+
from django.utils import six
37+
3638
#### Spatial Reference class. ####
3739
class SpatialReference(GDALBase):
3840
"""
3941
A wrapper for the OGRSpatialReference object. According to the GDAL Web site,
40-
the SpatialReference object "provide[s] services to represent coordinate
42+
the SpatialReference object "provide[s] services to represent coordinate
4143
systems (projections and datums) and to transform between them."
4244
"""
4345

4446
#### Python 'magic' routines ####
4547
def __init__(self, srs_input=''):
4648
"""
4749
Creates a GDAL OSR Spatial Reference object from the given input.
48-
The input may be string of OGC Well Known Text (WKT), an integer
49-
EPSG code, a PROJ.4 string, and/or a projection "well known" shorthand
50+
The input may be string of OGC Well Known Text (WKT), an integer
51+
EPSG code, a PROJ.4 string, and/or a projection "well known" shorthand
5052
string (one of 'WGS84', 'WGS72', 'NAD27', 'NAD83').
5153
"""
5254
buf = c_char_p('')
@@ -63,7 +65,7 @@ def __init__(self, srs_input=''):
6365
srs_input = 'EPSG:%d' % srid
6466
except ValueError:
6567
pass
66-
elif isinstance(srs_input, (int, long)):
68+
elif isinstance(srs_input, six.integer_types):
6769
# EPSG integer code was input.
6870
srs_type = 'epsg'
6971
elif isinstance(srs_input, self.ptr_type):
@@ -97,8 +99,8 @@ def __del__(self):
9799

98100
def __getitem__(self, target):
99101
"""
100-
Returns the value of the given string attribute node, None if the node
101-
doesn't exist. Can also take a tuple as a parameter, (target, child),
102+
Returns the value of the given string attribute node, None if the node
103+
doesn't exist. Can also take a tuple as a parameter, (target, child),
102104
where child is the index of the attribute in the WKT. For example:
103105
104106
>>> wkt = 'GEOGCS["WGS 84", DATUM["WGS_1984, ... AUTHORITY["EPSG","4326"]]')
@@ -140,7 +142,7 @@ def attr_value(self, target, index=0):
140142
def auth_name(self, target):
141143
"Returns the authority name for the given string target node."
142144
return capi.get_auth_name(self.ptr, target)
143-
145+
144146
def auth_code(self, target):
145147
"Returns the authority code for the given string target node."
146148
return capi.get_auth_code(self.ptr, target)
@@ -167,7 +169,7 @@ def to_esri(self):
167169
def validate(self):
168170
"Checks to see if the given spatial reference is valid."
169171
capi.srs_validate(self.ptr)
170-
172+
171173
#### Name & SRID properties ####
172174
@property
173175
def name(self):
@@ -184,7 +186,7 @@ def srid(self):
184186
return int(self.attr_value('AUTHORITY', 1))
185187
except (TypeError, ValueError):
186188
return None
187-
189+
188190
#### Unit Properties ####
189191
@property
190192
def linear_name(self):
@@ -213,7 +215,7 @@ def angular_units(self):
213215
@property
214216
def units(self):
215217
"""
216-
Returns a 2-tuple of the units value and the units name,
218+
Returns a 2-tuple of the units value and the units name,
217219
and will automatically determines whether to return the linear
218220
or angular units.
219221
"""
@@ -252,7 +254,7 @@ def inverse_flattening(self):
252254
@property
253255
def geographic(self):
254256
"""
255-
Returns True if this SpatialReference is geographic
257+
Returns True if this SpatialReference is geographic
256258
(root node is GEOGCS).
257259
"""
258260
return bool(capi.isgeographic(self.ptr))
@@ -265,7 +267,7 @@ def local(self):
265267
@property
266268
def projected(self):
267269
"""
268-
Returns True if this SpatialReference is a projected coordinate system
270+
Returns True if this SpatialReference is a projected coordinate system
269271
(root node is PROJCS).
270272
"""
271273
return bool(capi.isprojected(self.ptr))

0 commit comments

Comments
 (0)