Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

[py3] Made gis.measure Python 3-compatible

  • Loading branch information...
commit 2da3af23aa10af3e06536a46134b1053f80eb8b2 1 parent fa4cb34
Claude Paroz authored August 08, 2012

Showing 1 changed file with 8 additions and 4 deletions. Show diff stats Hide diff stats

  1. 12  django/contrib/gis/measure.py
12  django/contrib/gis/measure.py
@@ -143,7 +143,7 @@ def __imul__(self, other):
143 143
     def __rmul__(self, other):
144 144
         return self * other
145 145
 
146  
-    def __div__(self, other):
  146
+    def __truediv__(self, other):
147 147
         if isinstance(other, self.__class__):
148 148
             return self.standard / other.standard
149 149
         if isinstance(other, NUMERIC_TYPES):
@@ -151,16 +151,19 @@ def __div__(self, other):
151 151
                 **{self.STANDARD_UNIT: (self.standard / other)})
152 152
         else:
153 153
             raise TypeError('%(class)s must be divided with number or %(class)s' % {"class":pretty_name(self)})
  154
+    __div__ = __truediv__ # Python 2 compatibility
154 155
 
155  
-    def __idiv__(self, other):
  156
+    def __itruediv__(self, other):
156 157
         if isinstance(other, NUMERIC_TYPES):
157 158
             self.standard /= float(other)
158 159
             return self
159 160
         else:
160 161
             raise TypeError('%(class)s must be divided with number' % {"class":pretty_name(self)})
  162
+    __idiv__ = __itruediv__ # Python 2 compatibility
161 163
 
162  
-    def __nonzero__(self):
  164
+    def __bool__(self):
163 165
         return bool(self.standard)
  166
+    __nonzero__ = __bool__ # Python 2 compatibility
164 167
 
165 168
     def default_units(self, kwargs):
166 169
         """
@@ -305,12 +308,13 @@ class Area(MeasureBase):
305 308
     ALIAS = dict([(k, '%s%s' % (AREA_PREFIX, v)) for k, v in Distance.ALIAS.items()])
306 309
     LALIAS = dict([(k.lower(), v) for k, v in ALIAS.items()])
307 310
 
308  
-    def __div__(self, other):
  311
+    def __truediv__(self, other):
309 312
         if isinstance(other, NUMERIC_TYPES):
310 313
             return self.__class__(default_unit=self._default_unit,
311 314
                 **{self.STANDARD_UNIT: (self.standard / other)})
312 315
         else:
313 316
             raise TypeError('%(class)s must be divided by a number' % {"class":pretty_name(self)})
  317
+    __div__ = __truediv__ # Python 2 compatibility
314 318
 
315 319
 
316 320
 # Shortcuts

0 notes on commit 2da3af2

Please sign in to comment.
Something went wrong with that request. Please try again.