Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

[py3] Updated bundled version of six

  • Loading branch information...
commit 20012b961ea5306e1a381a3a2880627dd5af0d15 1 parent e98eff8
Aymeric Augustin authored August 28, 2012

Showing 1 changed file with 31 additions and 19 deletions. Show diff stats Hide diff stats

  1. 50  django/utils/six.py
50  django/utils/six.py
@@ -5,7 +5,7 @@
5 5
 import types
6 6
 
7 7
 __author__ = "Benjamin Peterson <benjamin@python.org>"
8  
-__version__ = "1.1.0"
  8
+__version__ = "1.2.0"
9 9
 
10 10
 
11 11
 # True if we are running on Python 3.
@@ -26,19 +26,23 @@
26 26
     text_type = unicode
27 27
     binary_type = str
28 28
 
29  
-    # It's possible to have sizeof(long) != sizeof(Py_ssize_t).
30  
-    class X(object):
31  
-        def __len__(self):
32  
-            return 1 << 31
33  
-    try:
34  
-        len(X())
35  
-    except OverflowError:
36  
-        # 32-bit
  29
+    if sys.platform == "java":
  30
+        # Jython always uses 32 bits.
37 31
         MAXSIZE = int((1 << 31) - 1)
38 32
     else:
39  
-        # 64-bit
40  
-        MAXSIZE = int((1 << 63) - 1)
41  
-    del X
  33
+        # It's possible to have sizeof(long) != sizeof(Py_ssize_t).
  34
+        class X(object):
  35
+            def __len__(self):
  36
+                return 1 << 31
  37
+        try:
  38
+            len(X())
  39
+        except OverflowError:
  40
+            # 32-bit
  41
+            MAXSIZE = int((1 << 31) - 1)
  42
+        else:
  43
+            # 64-bit
  44
+            MAXSIZE = int((1 << 63) - 1)
  45
+            del X
42 46
 
43 47
 
44 48
 def _add_doc(func, doc):
@@ -201,12 +205,19 @@ def remove_move(name):
201 205
     _iteritems = "iteritems"
202 206
 
203 207
 
  208
+try:
  209
+    advance_iterator = next
  210
+except NameError:
  211
+    def advance_iterator(it):
  212
+        return it.next()
  213
+next = advance_iterator
  214
+
  215
+
204 216
 if PY3:
205 217
     def get_unbound_function(unbound):
206 218
         return unbound
207 219
 
208  
-
209  
-    advance_iterator = next
  220
+    Iterator = object
210 221
 
211 222
     def callable(obj):
212 223
         return any("__call__" in klass.__dict__ for klass in type(obj).__mro__)
@@ -214,9 +225,10 @@ def callable(obj):
214 225
     def get_unbound_function(unbound):
215 226
         return unbound.im_func
216 227
 
  228
+    class Iterator(object):
217 229
 
218  
-    def advance_iterator(it):
219  
-        return it.next()
  230
+        def next(self):
  231
+            return type(self).__next__(self)
220 232
 
221 233
     callable = callable
222 234
 _add_doc(get_unbound_function,
@@ -231,15 +243,15 @@ def advance_iterator(it):
231 243
 
232 244
 def iterkeys(d):
233 245
     """Return an iterator over the keys of a dictionary."""
234  
-    return getattr(d, _iterkeys)()
  246
+    return iter(getattr(d, _iterkeys)())
235 247
 
236 248
 def itervalues(d):
237 249
     """Return an iterator over the values of a dictionary."""
238  
-    return getattr(d, _itervalues)()
  250
+    return iter(getattr(d, _itervalues)())
239 251
 
240 252
 def iteritems(d):
241 253
     """Return an iterator over the (key, value) pairs of a dictionary."""
242  
-    return getattr(d, _iteritems)()
  254
+    return iter(getattr(d, _iteritems)())
243 255
 
244 256
 
245 257
 if PY3:

0 notes on commit 20012b9

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