[py3] Updated bundled version of six

This commit is contained in:
Aymeric Augustin 2012-08-28 23:18:55 +02:00
parent e98eff836d
commit 20012b961e
1 changed files with 31 additions and 19 deletions

View File

@ -5,7 +5,7 @@ import sys
import types import types
__author__ = "Benjamin Peterson <benjamin@python.org>" __author__ = "Benjamin Peterson <benjamin@python.org>"
__version__ = "1.1.0" __version__ = "1.2.0"
# True if we are running on Python 3. # True if we are running on Python 3.
@ -26,19 +26,23 @@ else:
text_type = unicode text_type = unicode
binary_type = str binary_type = str
# It's possible to have sizeof(long) != sizeof(Py_ssize_t). if sys.platform == "java":
class X(object): # Jython always uses 32 bits.
def __len__(self):
return 1 << 31
try:
len(X())
except OverflowError:
# 32-bit
MAXSIZE = int((1 << 31) - 1) MAXSIZE = int((1 << 31) - 1)
else: else:
# 64-bit # It's possible to have sizeof(long) != sizeof(Py_ssize_t).
MAXSIZE = int((1 << 63) - 1) class X(object):
del X def __len__(self):
return 1 << 31
try:
len(X())
except OverflowError:
# 32-bit
MAXSIZE = int((1 << 31) - 1)
else:
# 64-bit
MAXSIZE = int((1 << 63) - 1)
del X
def _add_doc(func, doc): def _add_doc(func, doc):
@ -201,12 +205,19 @@ else:
_iteritems = "iteritems" _iteritems = "iteritems"
try:
advance_iterator = next
except NameError:
def advance_iterator(it):
return it.next()
next = advance_iterator
if PY3: if PY3:
def get_unbound_function(unbound): def get_unbound_function(unbound):
return unbound return unbound
Iterator = object
advance_iterator = next
def callable(obj): def callable(obj):
return any("__call__" in klass.__dict__ for klass in type(obj).__mro__) return any("__call__" in klass.__dict__ for klass in type(obj).__mro__)
@ -214,9 +225,10 @@ else:
def get_unbound_function(unbound): def get_unbound_function(unbound):
return unbound.im_func return unbound.im_func
class Iterator(object):
def advance_iterator(it): def next(self):
return it.next() return type(self).__next__(self)
callable = callable callable = callable
_add_doc(get_unbound_function, _add_doc(get_unbound_function,
@ -231,15 +243,15 @@ get_function_defaults = operator.attrgetter(_func_defaults)
def iterkeys(d): def iterkeys(d):
"""Return an iterator over the keys of a dictionary.""" """Return an iterator over the keys of a dictionary."""
return getattr(d, _iterkeys)() return iter(getattr(d, _iterkeys)())
def itervalues(d): def itervalues(d):
"""Return an iterator over the values of a dictionary.""" """Return an iterator over the values of a dictionary."""
return getattr(d, _itervalues)() return iter(getattr(d, _itervalues)())
def iteritems(d): def iteritems(d):
"""Return an iterator over the (key, value) pairs of a dictionary.""" """Return an iterator over the (key, value) pairs of a dictionary."""
return getattr(d, _iteritems)() return iter(getattr(d, _iteritems)())
if PY3: if PY3: