Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 0a8a110

Browse files
cgohlkemdboom
authored andcommitted
Update six.py to version 1.2
1 parent a64f450 commit 0a8a110

File tree

1 file changed

+32
-19
lines changed

1 file changed

+32
-19
lines changed

lib/six.py

Lines changed: 32 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
import types
66

77
__author__ = "Benjamin Peterson <[email protected]>"
8-
__version__ = "1.1.0-mpl"
8+
__version__ = "1.2.0-mpl"
99

1010

1111
# True if we are running on Python 3.
@@ -26,19 +26,23 @@
2626
text_type = unicode
2727
binary_type = str
2828

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.
3731
MAXSIZE = int((1 << 31) - 1)
3832
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
4246

4347

4448
def _add_doc(func, doc):
@@ -113,6 +117,7 @@ class _MovedItems(types.ModuleType):
113117
_moved_attributes = [
114118
MovedAttribute("cStringIO", "cStringIO", "io", "StringIO"),
115119
MovedAttribute("filter", "itertools", "builtins", "ifilter", "filter"),
120+
MovedAttribute("input", "__builtin__", "builtins", "raw_input", "input"),
116121
MovedAttribute("map", "itertools", "builtins", "imap", "map"),
117122
MovedAttribute("reload_module", "__builtin__", "imp", "reload"),
118123
MovedAttribute("reduce", "__builtin__", "functools"),
@@ -200,22 +205,30 @@ def remove_move(name):
200205
_iteritems = "iteritems"
201206

202207

208+
try:
209+
advance_iterator = next
210+
except NameError:
211+
def advance_iterator(it):
212+
return it.next()
213+
next = advance_iterator
214+
215+
203216
if PY3:
204217
def get_unbound_function(unbound):
205218
return unbound
206219

207-
208-
advance_iterator = next
220+
Iterator = object
209221

210222
def callable(obj):
211223
return any("__call__" in klass.__dict__ for klass in type(obj).__mro__)
212224
else:
213225
def get_unbound_function(unbound):
214226
return unbound.im_func
215227

228+
class Iterator(object):
216229

217-
def advance_iterator(it):
218-
return it.next()
230+
def next(self):
231+
return type(self).__next__(self)
219232

220233
callable = callable
221234
_add_doc(get_unbound_function,
@@ -230,15 +243,15 @@ def advance_iterator(it):
230243

231244
def iterkeys(d):
232245
"""Return an iterator over the keys of a dictionary."""
233-
return getattr(d, _iterkeys)()
246+
return iter(getattr(d, _iterkeys)())
234247

235248
def itervalues(d):
236249
"""Return an iterator over the values of a dictionary."""
237-
return getattr(d, _itervalues)()
250+
return iter(getattr(d, _itervalues)())
238251

239252
def iteritems(d):
240253
"""Return an iterator over the (key, value) pairs of a dictionary."""
241-
return getattr(d, _iteritems)()
254+
return iter(getattr(d, _iteritems)())
242255

243256

244257
if PY3:

0 commit comments

Comments
 (0)