Permalink
Browse files

[py3] Made gis.measure Python 3-compatible

  • Loading branch information...
1 parent fa4cb34 commit 2da3af23aa10af3e06536a46134b1053f80eb8b2 @claudep claudep committed Aug 8, 2012
Showing with 8 additions and 4 deletions.
  1. +8 −4 django/contrib/gis/measure.py
View
12 django/contrib/gis/measure.py
@@ -143,24 +143,27 @@ def __imul__(self, other):
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):
return self.__class__(default_unit=self._default_unit,
**{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

0 comments on commit 2da3af2

Please sign in to comment.