Skip to content

Commit

Permalink
Update six to 1.10.0
Browse files Browse the repository at this point in the history
  • Loading branch information
labrys committed Apr 24, 2016
1 parent 39650a9 commit 1fc0802
Showing 1 changed file with 52 additions and 22 deletions.
74 changes: 52 additions & 22 deletions lib/six.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,12 +29,13 @@
import types

__author__ = "Benjamin Peterson <benjamin@python.org>"
__version__ = "1.9.0"
__version__ = "1.10.0"


# Useful for very coarse version differentiation.
PY2 = sys.version_info[0] == 2
PY3 = sys.version_info[0] == 3
PY34 = sys.version_info[0:2] >= (3, 4)

if PY3:
string_types = str,
Expand All @@ -57,6 +58,7 @@
else:
# It's possible to have sizeof(long) != sizeof(Py_ssize_t).
class X(object):

def __len__(self):
return 1 << 31
try:
Expand Down Expand Up @@ -88,7 +90,7 @@ def __init__(self, name):

def __get__(self, obj, tp):
result = self._resolve()
setattr(obj, self.name, result) # Invokes __set__.
setattr(obj, self.name, result) # Invokes __set__.
try:
# This is a bit ugly, but it avoids running this again by
# removing this descriptor.
Expand Down Expand Up @@ -160,12 +162,14 @@ def _resolve(self):


class _SixMetaPathImporter(object):

"""
A meta path importer to import six.moves and its submodules.
This class implements a PEP302 finder and loader. It should be compatible
with Python 2.5 and all existing versions of Python3
"""

def __init__(self, six_module_name):
self.name = six_module_name
self.known_modules = {}
Expand Down Expand Up @@ -223,6 +227,7 @@ def get_code(self, fullname):


class _MovedItems(_LazyModule):

"""Lazy loading of moved objects"""
__path__ = [] # mark as package

Expand All @@ -234,8 +239,10 @@ class _MovedItems(_LazyModule):
MovedAttribute("input", "__builtin__", "builtins", "raw_input", "input"),
MovedAttribute("intern", "__builtin__", "sys"),
MovedAttribute("map", "itertools", "builtins", "imap", "map"),
MovedAttribute("getcwd", "os", "os", "getcwdu", "getcwd"),
MovedAttribute("getcwdb", "os", "os", "getcwd", "getcwdb"),
MovedAttribute("range", "__builtin__", "builtins", "xrange", "range"),
MovedAttribute("reload_module", "__builtin__", "imp", "reload"),
MovedAttribute("reload_module", "__builtin__", "importlib" if PY34 else "imp", "reload"),
MovedAttribute("reduce", "__builtin__", "functools"),
MovedAttribute("shlex_quote", "pipes", "shlex", "quote"),
MovedAttribute("StringIO", "StringIO", "io"),
Expand All @@ -245,7 +252,6 @@ class _MovedItems(_LazyModule):
MovedAttribute("xrange", "__builtin__", "builtins", "xrange", "range"),
MovedAttribute("zip", "itertools", "builtins", "izip", "zip"),
MovedAttribute("zip_longest", "itertools", "itertools", "izip_longest", "zip_longest"),

MovedModule("builtins", "__builtin__"),
MovedModule("configparser", "ConfigParser"),
MovedModule("copyreg", "copy_reg"),
Expand Down Expand Up @@ -292,8 +298,13 @@ class _MovedItems(_LazyModule):
MovedModule("urllib_robotparser", "robotparser", "urllib.robotparser"),
MovedModule("xmlrpc_client", "xmlrpclib", "xmlrpc.client"),
MovedModule("xmlrpc_server", "SimpleXMLRPCServer", "xmlrpc.server"),
MovedModule("winreg", "_winreg"),
]
# Add windows specific modules.
if sys.platform == "win32":
_moved_attributes += [
MovedModule("winreg", "_winreg"),
]

for attr in _moved_attributes:
setattr(_MovedItems, attr.name, attr)
if isinstance(attr, MovedModule):
Expand All @@ -307,6 +318,7 @@ class _MovedItems(_LazyModule):


class Module_six_moves_urllib_parse(_LazyModule):

"""Lazy loading of moved objects in six.moves.urllib_parse"""


Expand Down Expand Up @@ -346,6 +358,7 @@ class Module_six_moves_urllib_parse(_LazyModule):


class Module_six_moves_urllib_error(_LazyModule):

"""Lazy loading of moved objects in six.moves.urllib_error"""


Expand All @@ -365,6 +378,7 @@ class Module_six_moves_urllib_error(_LazyModule):


class Module_six_moves_urllib_request(_LazyModule):

"""Lazy loading of moved objects in six.moves.urllib_request"""


Expand Down Expand Up @@ -414,6 +428,7 @@ class Module_six_moves_urllib_request(_LazyModule):


class Module_six_moves_urllib_response(_LazyModule):

"""Lazy loading of moved objects in six.moves.urllib_response"""


Expand All @@ -434,6 +449,7 @@ class Module_six_moves_urllib_response(_LazyModule):


class Module_six_moves_urllib_robotparser(_LazyModule):

"""Lazy loading of moved objects in six.moves.urllib_robotparser"""


Expand All @@ -451,6 +467,7 @@ class Module_six_moves_urllib_robotparser(_LazyModule):


class Module_six_moves_urllib(types.ModuleType):

"""Create a six.moves.urllib namespace that resembles the Python 3 namespace"""
__path__ = [] # mark as package
parse = _importer._get_module("moves.urllib_parse")
Expand Down Expand Up @@ -521,6 +538,9 @@ def get_unbound_function(unbound):

create_bound_method = types.MethodType

def create_unbound_method(func, cls):
return func

Iterator = object
else:
def get_unbound_function(unbound):
Expand All @@ -529,6 +549,9 @@ def get_unbound_function(unbound):
def create_bound_method(func, obj):
return types.MethodType(func, obj, obj.__class__)

def create_unbound_method(func, cls):
return types.MethodType(func, None, cls)

class Iterator(object):

def next(self):
Expand Down Expand Up @@ -567,16 +590,16 @@ def iterlists(d, **kw):
viewitems = operator.methodcaller("items")
else:
def iterkeys(d, **kw):
return iter(d.iterkeys(**kw))
return d.iterkeys(**kw)

def itervalues(d, **kw):
return iter(d.itervalues(**kw))
return d.itervalues(**kw)

def iteritems(d, **kw):
return iter(d.iteritems(**kw))
return d.iteritems(**kw)

def iterlists(d, **kw):
return iter(d.iterlists(**kw))
return d.iterlists(**kw)

viewkeys = operator.methodcaller("viewkeys")

Expand All @@ -595,34 +618,39 @@ def iterlists(d, **kw):
if PY3:
def b(s):
return s.encode("latin-1")

def u(s):
return s
unichr = chr
if sys.version_info[1] <= 1:
def int2byte(i):
return bytes((i,))
else:
# This is about 2x faster than the implementation above on 3.2+
int2byte = operator.methodcaller("to_bytes", 1, "big")
import struct
int2byte = struct.Struct(">B").pack
del struct
byte2int = operator.itemgetter(0)
indexbytes = operator.getitem
iterbytes = iter
import io
StringIO = io.StringIO
BytesIO = io.BytesIO
_assertCountEqual = "assertCountEqual"
_assertRaisesRegex = "assertRaisesRegex"
_assertRegex = "assertRegex"
if sys.version_info[1] <= 1:
_assertRaisesRegex = "assertRaisesRegexp"
_assertRegex = "assertRegexpMatches"
else:
_assertRaisesRegex = "assertRaisesRegex"
_assertRegex = "assertRegex"
else:
def b(s):
return s
# Workaround for standalone backslash

def u(s):
return unicode(s.replace(r'\\', r'\\\\'), "unicode_escape")
unichr = unichr
int2byte = chr

def byte2int(bs):
return ord(bs[0])

def indexbytes(buf, i):
return ord(buf[i])
iterbytes = functools.partial(itertools.imap, ord)
Expand Down Expand Up @@ -650,7 +678,6 @@ def assertRegex(self, *args, **kwargs):
if PY3:
exec_ = getattr(moves.builtins, "exec")


def reraise(tp, value, tb=None):
if value is None:
value = tp()
Expand All @@ -671,7 +698,6 @@ def exec_(_code_, _globs_=None, _locs_=None):
_locs_ = _globs_
exec("""exec _code_ in _globs_, _locs_""")


exec_("""def reraise(tp, value, tb=None):
raise tp, value, tb
""")
Expand Down Expand Up @@ -699,13 +725,14 @@ def print_(*args, **kwargs):
fp = kwargs.pop("file", sys.stdout)
if fp is None:
return

def write(data):
if not isinstance(data, basestring):
data = str(data)
# If the file has an encoding, encode unicode with it.
if (isinstance(fp, file) and
isinstance(data, unicode) and
fp.encoding is not None):
isinstance(data, unicode) and
fp.encoding is not None):
errors = getattr(fp, "errors", None)
if errors is None:
errors = "strict"
Expand Down Expand Up @@ -748,6 +775,7 @@ def write(data):
write(end)
if sys.version_info[:2] < (3, 3):
_print = print_

def print_(*args, **kwargs):
fp = kwargs.get("file", sys.stdout)
flush = kwargs.pop("flush", False)
Expand All @@ -768,12 +796,14 @@ def wrapper(f):
else:
wraps = functools.wraps


def with_metaclass(meta, *bases):
"""Create a base class with a metaclass."""
# This requires a bit of explanation: the basic idea is to make a dummy
# metaclass for one level of class instantiation that replaces itself with
# the actual metaclass.
class metaclass(meta):

def __new__(cls, name, this_bases, d):
return meta(name, bases, d)
return type.__new__(metaclass, 'temporary_class', (), {})
Expand Down Expand Up @@ -830,7 +860,7 @@ def python_2_unicode_compatible(klass):
# the six meta path importer, since the other six instance will have
# inserted an importer with different class.
if (type(importer).__name__ == "_SixMetaPathImporter" and
importer.name == __name__):
importer.name == __name__):
del sys.meta_path[i]
break
del i, importer
Expand Down

0 comments on commit 1fc0802

Please sign in to comment.