Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update six.py to version 1.2 #1261

Merged
merged 1 commit into from
Sep 17, 2012
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
51 changes: 32 additions & 19 deletions lib/six.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
import types

__author__ = "Benjamin Peterson <benjamin@python.org>"
__version__ = "1.1.0-mpl"
__version__ = "1.2.0-mpl"


# True if we are running on Python 3.
Expand All @@ -26,19 +26,23 @@
text_type = unicode
binary_type = str

# It's possible to have sizeof(long) != sizeof(Py_ssize_t).
class X(object):
def __len__(self):
return 1 << 31
try:
len(X())
except OverflowError:
# 32-bit
if sys.platform == "java":
# Jython always uses 32 bits.
MAXSIZE = int((1 << 31) - 1)
else:
# 64-bit
MAXSIZE = int((1 << 63) - 1)
del X
# It's possible to have sizeof(long) != sizeof(Py_ssize_t).
class X(object):
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):
Expand Down Expand Up @@ -113,6 +117,7 @@ class _MovedItems(types.ModuleType):
_moved_attributes = [
MovedAttribute("cStringIO", "cStringIO", "io", "StringIO"),
MovedAttribute("filter", "itertools", "builtins", "ifilter", "filter"),
MovedAttribute("input", "__builtin__", "builtins", "raw_input", "input"),
MovedAttribute("map", "itertools", "builtins", "imap", "map"),
MovedAttribute("reload_module", "__builtin__", "imp", "reload"),
MovedAttribute("reduce", "__builtin__", "functools"),
Expand Down Expand Up @@ -200,22 +205,30 @@ def remove_move(name):
_iteritems = "iteritems"


try:
advance_iterator = next
except NameError:
def advance_iterator(it):
return it.next()
next = advance_iterator


if PY3:
def get_unbound_function(unbound):
return unbound


advance_iterator = next
Iterator = object

def callable(obj):
return any("__call__" in klass.__dict__ for klass in type(obj).__mro__)
else:
def get_unbound_function(unbound):
return unbound.im_func

class Iterator(object):

def advance_iterator(it):
return it.next()
def next(self):
return type(self).__next__(self)

callable = callable
_add_doc(get_unbound_function,
Expand All @@ -230,15 +243,15 @@ def advance_iterator(it):

def iterkeys(d):
"""Return an iterator over the keys of a dictionary."""
return getattr(d, _iterkeys)()
return iter(getattr(d, _iterkeys)())

def itervalues(d):
"""Return an iterator over the values of a dictionary."""
return getattr(d, _itervalues)()
return iter(getattr(d, _itervalues)())

def iteritems(d):
"""Return an iterator over the (key, value) pairs of a dictionary."""
return getattr(d, _iteritems)()
return iter(getattr(d, _iteritems)())


if PY3:
Expand Down