Permalink
Browse files

[py3] Removed longs.

  • Loading branch information...
1 parent f1d5dc8 commit 56dbe924a6e700cefbfd34f1a5aa6c1ee01478dc @aaugustin aaugustin committed Jul 20, 2012
@@ -13,6 +13,7 @@
from django.utils.text import capfirst
from django.utils import timezone
from django.utils.encoding import force_unicode, smart_unicode, smart_str
+from django.utils import six
from django.utils.translation import ungettext
from django.core.urlresolvers import reverse
@@ -349,7 +350,7 @@ def display_for_value(value, boolean=False):
return formats.localize(timezone.template_localtime(value))
elif isinstance(value, (datetime.date, datetime.time)):
return formats.localize(value)
- elif isinstance(value, (decimal.Decimal, float, int, long)):
+ elif isinstance(value, six.integer_types + (decimal.Decimal, float)):
return formats.number_format(value)
else:
return smart_unicode(value)
@@ -16,6 +16,7 @@
from django.contrib.gis.db.backends.util import SpatialFunction
from django.contrib.gis.geometry.backend import Geometry
from django.contrib.gis.measure import Distance
+from django.utils import six
class SDOOperation(SpatialFunction):
"Base class for SDO* Oracle operations."
@@ -65,7 +66,7 @@ def __init__(self, mask):
super(SDORelate, self).__init__(self.relate_func, mask=mask)
# Valid distance types and substitutions
-dtypes = (Decimal, Distance, float, int, long)
+dtypes = (Decimal, Distance, float) + six.integer_types
class OracleOperations(DatabaseOperations, BaseSpatialOperations):
compiler_module = "django.contrib.gis.db.backends.oracle.compiler"
@@ -10,6 +10,7 @@
from django.core.exceptions import ImproperlyConfigured
from django.db.backends.postgresql_psycopg2.base import DatabaseOperations
from django.db.utils import DatabaseError
+from django.utils import six
#### Classes used in constructing PostGIS spatial SQL ####
class PostGISOperator(SpatialOperation):
@@ -165,7 +166,7 @@ def __init__(self, connection):
}
# Valid distance types and substitutions
- dtypes = (Decimal, Distance, float, int, long)
+ dtypes = (Decimal, Distance, float) + six.integer_types
def get_dist_ops(operator):
"Returns operations for both regular and spherical distances."
return {'cartesian' : PostGISDistance(prefix, operator),
@@ -9,6 +9,7 @@
from django.core.exceptions import ImproperlyConfigured
from django.db.backends.sqlite3.base import DatabaseOperations
from django.db.utils import DatabaseError
+from django.utils import six
class SpatiaLiteOperator(SpatialOperation):
"For SpatiaLite operators (e.g. `&&`, `~`)."
@@ -42,7 +43,7 @@ def __init__(self, pattern):
super(SpatiaLiteRelate, self).__init__('Relate')
# Valid distance types and substitutions
-dtypes = (Decimal, Distance, float, int, long)
+dtypes = (Decimal, Distance, float) + six.integer_types
def get_dist_ops(operator):
"Returns operations for regular distances; spherical distances are not currently supported."
return (SpatiaLiteDistance(operator),)
@@ -6,6 +6,7 @@
from django.contrib.gis.db.models.sql import AreaField, DistanceField, GeomField, GeoQuery
from django.contrib.gis.geometry.backend import Geometry
from django.contrib.gis.measure import Area, Distance
+from django.utils import six
class GeoQuerySet(QuerySet):
"The Geographic QuerySet."
@@ -144,7 +145,7 @@ def geojson(self, precision=8, crs=False, bbox=False, **kwargs):
if not backend.geojson:
raise NotImplementedError('Only PostGIS 1.3.4+ supports GeoJSON serialization.')
- if not isinstance(precision, (int, long)):
+ if not isinstance(precision, six.integer_types):
raise TypeError('Precision keyword must be set with an integer.')
# Setting the options flag -- which depends on which version of
@@ -173,7 +174,7 @@ def geohash(self, precision=20, **kwargs):
The `precision` keyword may be used to custom the number of
_characters_ used in the output GeoHash, the default is 20.
"""
- s = {'desc' : 'GeoHash',
+ s = {'desc' : 'GeoHash',
'procedure_args': {'precision': precision},
'procedure_fmt': '%(geo_col)s,%(precision)s',
}
@@ -309,7 +310,7 @@ def snap_to_grid(self, *args, **kwargs):
- 2 arguments: X and Y sizes to snap the grid to.
- 4 arguments: X, Y sizes and the X, Y origins.
"""
- if False in [isinstance(arg, (float, int, long)) for arg in args]:
+ if False in [isinstance(arg, (float,) + six.integer_types) for arg in args]:
raise TypeError('Size argument(s) for the grid must be a float or integer values.')
nargs = len(args)
@@ -349,7 +350,7 @@ def svg(self, relative=False, precision=8, **kwargs):
digits used in output (defaults to 8).
"""
relative = int(bool(relative))
- if not isinstance(precision, (int, long)):
+ if not isinstance(precision, six.integer_types):
raise TypeError('SVG precision keyword argument must be an integer.')
s = {'desc' : 'SVG',
'procedure_fmt' : '%(geo_col)s,%(rel)s,%(precision)s',
@@ -390,7 +391,7 @@ def transform(self, srid=4326, **kwargs):
Transforms the given geometry field to the given SRID. If no SRID is
provided, the transformation will default to using 4326 (WGS84).
"""
- if not isinstance(srid, (int, long)):
+ if not isinstance(srid, six.integer_types):
raise TypeError('An integer SRID must be provided.')
field_name = kwargs.get('field_name', None)
tmp, geo_field = self._spatial_setup('transform', field_name=field_name)
@@ -1,6 +1,7 @@
from ctypes import c_void_p
from django.contrib.gis.gdal.error import GDALException
+from django.utils import six
class GDALBase(object):
"""
@@ -24,7 +25,7 @@ def _get_ptr(self):
def _set_ptr(self, ptr):
# Only allow the pointer to be set with pointers of the
# compatible type or None (NULL).
- if isinstance(ptr, (int, long)):
+ if isinstance(ptr, six.integer_types):
self._ptr = self.ptr_type(ptr)
elif ptr is None or isinstance(ptr, self.ptr_type):
self._ptr = ptr
@@ -57,6 +57,8 @@
# For recognizing geometry input.
from django.contrib.gis.geometry.regex import hex_regex, wkt_regex, json_regex
+from django.utils import six
+
# For more information, see the OGR C API source code:
# http://www.gdal.org/ogr/ogr__api_8h.html
#
@@ -281,7 +283,7 @@ def _set_srs(self, srs):
# (decremented) when this geometry's destructor is called.
if isinstance(srs, SpatialReference):
srs_ptr = srs.ptr
- elif isinstance(srs, (int, long, basestring)):
+ elif isinstance(srs, six.integer_types + (basestring,)):
sr = SpatialReference(srs)
srs_ptr = sr.ptr
else:
@@ -297,7 +299,7 @@ def _get_srid(self):
return None
def _set_srid(self, srid):
- if isinstance(srid, (int, long)):
+ if isinstance(srid, six.integer_types):
self.srs = srid
else:
raise TypeError('SRID must be set with an integer.')
@@ -410,7 +412,7 @@ def transform(self, coord_trans, clone=False):
capi.geom_transform(self.ptr, coord_trans.ptr)
elif isinstance(coord_trans, SpatialReference):
capi.geom_transform_to(self.ptr, coord_trans.ptr)
- elif isinstance(coord_trans, (int, long, basestring)):
+ elif isinstance(coord_trans, six.integer_types + (basestring,)):
sr = SpatialReference(coord_trans)
capi.geom_transform_to(self.ptr, sr.ptr)
else:
@@ -14,6 +14,8 @@
# GDAL ctypes function prototypes.
from django.contrib.gis.gdal.prototypes import ds as capi, geom as geom_api, srs as srs_api
+from django.utils import six
+
# For more information, see the OGR C API source code:
# http://www.gdal.org/ogr/ogr__api_8h.html
#
@@ -25,8 +27,8 @@ class Layer(GDALBase):
def __init__(self, layer_ptr, ds):
"""
Initializes on an OGR C pointer to the Layer and the `DataSource` object
- that owns this layer. The `DataSource` object is required so that a
- reference to it is kept with this Layer. This prevents garbage
+ that owns this layer. The `DataSource` object is required so that a
+ reference to it is kept with this Layer. This prevents garbage
collection of the `DataSource` while this Layer is still active.
"""
if not layer_ptr:
@@ -39,7 +41,7 @@ def __init__(self, layer_ptr, ds):
def __getitem__(self, index):
"Gets the Feature at the specified index."
- if isinstance(index, (int, long)):
+ if isinstance(index, six.integer_types):
# An integer index was given -- we cannot do a check based on the
# number of features because the beginning and ending feature IDs
# are not guaranteed to be 0 and len(layer)-1, respectively.
@@ -85,7 +87,7 @@ def _make_feature(self, feat_id):
# each feature until the given feature ID is encountered.
for feat in self:
if feat.fid == feat_id: return feat
- # Should have returned a Feature, raise an OGRIndexError.
+ # Should have returned a Feature, raise an OGRIndexError.
raise OGRIndexError('Invalid feature id: %s.' % feat_id)
#### Layer properties ####
@@ -131,9 +133,9 @@ def fields(self):
Returns a list of string names corresponding to each of the Fields
available in this Layer.
"""
- return [capi.get_field_name(capi.get_field_defn(self._ldefn, i))
+ return [capi.get_field_name(capi.get_field_defn(self._ldefn, i))
for i in xrange(self.num_fields) ]
-
+
@property
def field_types(self):
"""
@@ -145,13 +147,13 @@ def field_types(self):
return [OGRFieldTypes[capi.get_field_type(capi.get_field_defn(self._ldefn, i))]
for i in xrange(self.num_fields)]
- @property
+ @property
def field_widths(self):
"Returns a list of the maximum field widths for the features."
return [capi.get_field_width(capi.get_field_defn(self._ldefn, i))
for i in xrange(self.num_fields)]
- @property
+ @property
def field_precisions(self):
"Returns the field precisions for the features."
return [capi.get_field_precision(capi.get_field_defn(self._ldefn, i))
@@ -5,9 +5,10 @@
from ctypes import c_void_p, string_at
from django.contrib.gis.gdal.error import check_err, OGRException, SRSException
from django.contrib.gis.gdal.libgdal import lgdal
+from django.utils import six
-# Helper routines for retrieving pointers and/or values from
-# arguments passed in by reference.
+# Helper routines for retrieving pointers and/or values from
+# arguments passed in by reference.
def arg_byref(args, offset=-1):
"Returns the pointer argument's by-refernece value."
return args[offset]._obj.value
@@ -53,7 +54,7 @@ def check_string(result, func, cargs, offset=-1, str_result=False):
ptr = ptr_byref(cargs, offset)
# Getting the string value
s = ptr.value
- # Correctly freeing the allocated memory beind GDAL pointer
+ # Correctly freeing the allocated memory beind GDAL pointer
# w/the VSIFree routine.
if ptr: lgdal.VSIFree(ptr)
return s
@@ -71,9 +72,9 @@ def check_geom(result, func, cargs):
"Checks a function that returns a geometry."
# OGR_G_Clone may return an integer, even though the
# restype is set to c_void_p
- if isinstance(result, (int, long)):
+ if isinstance(result, six.integer_types):
result = c_void_p(result)
- if not result:
+ if not result:
raise OGRException('Invalid geometry pointer returned from "%s".' % func.__name__)
return result
@@ -85,7 +86,7 @@ def check_geom_offset(result, func, cargs, offset=-1):
### Spatial Reference error-checking routines ###
def check_srs(result, func, cargs):
- if isinstance(result, (int, long)):
+ if isinstance(result, six.integer_types):
result = c_void_p(result)
if not result:
raise SRSException('Invalid spatial reference pointer returned from "%s".' % func.__name__)
@@ -109,11 +110,11 @@ def check_errcode(result, func, cargs):
def check_pointer(result, func, cargs):
"Makes sure the result pointer is valid."
- if isinstance(result, (int, long)):
+ if isinstance(result, six.integer_types):
result = c_void_p(result)
- if bool(result):
+ if bool(result):
return result
- else:
+ else:
raise OGRException('Invalid pointer returned from "%s"' % func.__name__)
def check_str_arg(result, func, cargs):
@@ -33,20 +33,22 @@
from django.contrib.gis.gdal.error import SRSException
from django.contrib.gis.gdal.prototypes import srs as capi
+from django.utils import six
+
#### Spatial Reference class. ####
class SpatialReference(GDALBase):
"""
A wrapper for the OGRSpatialReference object. According to the GDAL Web site,
- the SpatialReference object "provide[s] services to represent coordinate
+ the SpatialReference object "provide[s] services to represent coordinate
systems (projections and datums) and to transform between them."
"""
#### Python 'magic' routines ####
def __init__(self, srs_input=''):
"""
Creates a GDAL OSR Spatial Reference object from the given input.
- The input may be string of OGC Well Known Text (WKT), an integer
- EPSG code, a PROJ.4 string, and/or a projection "well known" shorthand
+ The input may be string of OGC Well Known Text (WKT), an integer
+ EPSG code, a PROJ.4 string, and/or a projection "well known" shorthand
string (one of 'WGS84', 'WGS72', 'NAD27', 'NAD83').
"""
buf = c_char_p('')
@@ -63,7 +65,7 @@ def __init__(self, srs_input=''):
srs_input = 'EPSG:%d' % srid
except ValueError:
pass
- elif isinstance(srs_input, (int, long)):
+ elif isinstance(srs_input, six.integer_types):
# EPSG integer code was input.
srs_type = 'epsg'
elif isinstance(srs_input, self.ptr_type):
@@ -97,8 +99,8 @@ def __del__(self):
def __getitem__(self, target):
"""
- Returns the value of the given string attribute node, None if the node
- doesn't exist. Can also take a tuple as a parameter, (target, child),
+ Returns the value of the given string attribute node, None if the node
+ doesn't exist. Can also take a tuple as a parameter, (target, child),
where child is the index of the attribute in the WKT. For example:
>>> wkt = 'GEOGCS["WGS 84", DATUM["WGS_1984, ... AUTHORITY["EPSG","4326"]]')
@@ -140,7 +142,7 @@ def attr_value(self, target, index=0):
def auth_name(self, target):
"Returns the authority name for the given string target node."
return capi.get_auth_name(self.ptr, target)
-
+
def auth_code(self, target):
"Returns the authority code for the given string target node."
return capi.get_auth_code(self.ptr, target)
@@ -167,7 +169,7 @@ def to_esri(self):
def validate(self):
"Checks to see if the given spatial reference is valid."
capi.srs_validate(self.ptr)
-
+
#### Name & SRID properties ####
@property
def name(self):
@@ -184,7 +186,7 @@ def srid(self):
return int(self.attr_value('AUTHORITY', 1))
except (TypeError, ValueError):
return None
-
+
#### Unit Properties ####
@property
def linear_name(self):
@@ -213,7 +215,7 @@ def angular_units(self):
@property
def units(self):
"""
- Returns a 2-tuple of the units value and the units name,
+ Returns a 2-tuple of the units value and the units name,
and will automatically determines whether to return the linear
or angular units.
"""
@@ -252,7 +254,7 @@ def inverse_flattening(self):
@property
def geographic(self):
"""
- Returns True if this SpatialReference is geographic
+ Returns True if this SpatialReference is geographic
(root node is GEOGCS).
"""
return bool(capi.isgeographic(self.ptr))
@@ -265,7 +267,7 @@ def local(self):
@property
def projected(self):
"""
- Returns True if this SpatialReference is a projected coordinate system
+ Returns True if this SpatialReference is a projected coordinate system
(root node is PROJCS).
"""
return bool(capi.isprojected(self.ptr))
Oops, something went wrong. Retry.

0 comments on commit 56dbe92

Please sign in to comment.