summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorClaude Paroz <claude@2xlibre.net>2012-08-08 13:43:21 +0200
committerClaude Paroz <claude@2xlibre.net>2012-08-08 14:43:16 +0200
commit2da3af23aa10af3e06536a46134b1053f80eb8b2 (patch)
tree8c8420f3b8455eca654d53b2499d3a397558189c
parentfa4cb348170134fce7e99eedf497ee8f5e0fe165 (diff)
[py3] Made gis.measure Python 3-compatible
-rw-r--r--django/contrib/gis/measure.py12
1 files changed, 8 insertions, 4 deletions
diff --git a/django/contrib/gis/measure.py b/django/contrib/gis/measure.py
index fa8bab1340..6e074be355 100644
--- a/django/contrib/gis/measure.py
+++ b/django/contrib/gis/measure.py
@@ -143,7 +143,7 @@ class MeasureBase(object):
def __rmul__(self, other):
return self * other
- def __div__(self, other):
+ def __truediv__(self, other):
if isinstance(other, self.__class__):
return self.standard / other.standard
if isinstance(other, NUMERIC_TYPES):
@@ -151,16 +151,19 @@ class MeasureBase(object):
**{self.STANDARD_UNIT: (self.standard / other)})
else:
raise TypeError('%(class)s must be divided with number or %(class)s' % {"class":pretty_name(self)})
+ __div__ = __truediv__ # Python 2 compatibility
- def __idiv__(self, other):
+ def __itruediv__(self, other):
if isinstance(other, NUMERIC_TYPES):
self.standard /= float(other)
return self
else:
raise TypeError('%(class)s must be divided with number' % {"class":pretty_name(self)})
+ __idiv__ = __itruediv__ # Python 2 compatibility
- def __nonzero__(self):
+ def __bool__(self):
return bool(self.standard)
+ __nonzero__ = __bool__ # Python 2 compatibility
def default_units(self, kwargs):
"""
@@ -305,12 +308,13 @@ class Area(MeasureBase):
ALIAS = dict([(k, '%s%s' % (AREA_PREFIX, v)) for k, v in Distance.ALIAS.items()])
LALIAS = dict([(k.lower(), v) for k, v in ALIAS.items()])
- def __div__(self, other):
+ def __truediv__(self, other):
if isinstance(other, NUMERIC_TYPES):
return self.__class__(default_unit=self._default_unit,
**{self.STANDARD_UNIT: (self.standard / other)})
else:
raise TypeError('%(class)s must be divided by a number' % {"class":pretty_name(self)})
+ __div__ = __truediv__ # Python 2 compatibility
# Shortcuts