|
@ -38,15 +38,15 @@ PY3 = sys.version_info[0] == 3 |
|
|
PY34 = sys.version_info[0:2] >= (3, 4) |
|
|
PY34 = sys.version_info[0:2] >= (3, 4) |
|
|
|
|
|
|
|
|
if PY3: |
|
|
if PY3: |
|
|
string_types = str, |
|
|
string_types = (str,) |
|
|
integer_types = int, |
|
|
integer_types = (int,) |
|
|
class_types = type, |
|
|
class_types = (type,) |
|
|
text_type = str |
|
|
text_type = str |
|
|
binary_type = bytes |
|
|
binary_type = bytes |
|
|
|
|
|
|
|
|
MAXSIZE = sys.maxsize |
|
|
MAXSIZE = sys.maxsize |
|
|
else: |
|
|
else: |
|
|
string_types = basestring, |
|
|
string_types = (basestring,) |
|
|
integer_types = (int, long) |
|
|
integer_types = (int, long) |
|
|
class_types = (type, types.ClassType) |
|
|
class_types = (type, types.ClassType) |
|
|
text_type = unicode |
|
|
text_type = unicode |
|
@ -58,9 +58,9 @@ else: |
|
|
else: |
|
|
else: |
|
|
# It's possible to have sizeof(long) != sizeof(Py_ssize_t). |
|
|
# It's possible to have sizeof(long) != sizeof(Py_ssize_t). |
|
|
class X(object): |
|
|
class X(object): |
|
|
|
|
|
|
|
|
def __len__(self): |
|
|
def __len__(self): |
|
|
return 1 << 31 |
|
|
return 1 << 31 |
|
|
|
|
|
|
|
|
try: |
|
|
try: |
|
|
len(X()) |
|
|
len(X()) |
|
|
except OverflowError: |
|
|
except OverflowError: |
|
@ -84,7 +84,6 @@ def _import_module(name): |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
class _LazyDescr(object): |
|
|
class _LazyDescr(object): |
|
|
|
|
|
|
|
|
def __init__(self, name): |
|
|
def __init__(self, name): |
|
|
self.name = name |
|
|
self.name = name |
|
|
|
|
|
|
|
@ -101,7 +100,6 @@ class _LazyDescr(object): |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
class MovedModule(_LazyDescr): |
|
|
class MovedModule(_LazyDescr): |
|
|
|
|
|
|
|
|
def __init__(self, name, old, new=None): |
|
|
def __init__(self, name, old, new=None): |
|
|
super(MovedModule, self).__init__(name) |
|
|
super(MovedModule, self).__init__(name) |
|
|
if PY3: |
|
|
if PY3: |
|
@ -122,7 +120,6 @@ class MovedModule(_LazyDescr): |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
class _LazyModule(types.ModuleType): |
|
|
class _LazyModule(types.ModuleType): |
|
|
|
|
|
|
|
|
def __init__(self, name): |
|
|
def __init__(self, name): |
|
|
super(_LazyModule, self).__init__(name) |
|
|
super(_LazyModule, self).__init__(name) |
|
|
self.__doc__ = self.__class__.__doc__ |
|
|
self.__doc__ = self.__class__.__doc__ |
|
@ -137,7 +134,6 @@ class _LazyModule(types.ModuleType): |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
class MovedAttribute(_LazyDescr): |
|
|
class MovedAttribute(_LazyDescr): |
|
|
|
|
|
|
|
|
def __init__(self, name, old_mod, new_mod, old_attr=None, new_attr=None): |
|
|
def __init__(self, name, old_mod, new_mod, old_attr=None, new_attr=None): |
|
|
super(MovedAttribute, self).__init__(name) |
|
|
super(MovedAttribute, self).__init__(name) |
|
|
if PY3: |
|
|
if PY3: |
|
@ -221,28 +217,35 @@ class _SixMetaPathImporter(object): |
|
|
Required, if is_package is implemented""" |
|
|
Required, if is_package is implemented""" |
|
|
self.__get_module(fullname) # eventually raises ImportError |
|
|
self.__get_module(fullname) # eventually raises ImportError |
|
|
return None |
|
|
return None |
|
|
|
|
|
|
|
|
get_source = get_code # same as get_code |
|
|
get_source = get_code # same as get_code |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
_importer = _SixMetaPathImporter(__name__) |
|
|
_importer = _SixMetaPathImporter(__name__) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
class _MovedItems(_LazyModule): |
|
|
class _MovedItems(_LazyModule): |
|
|
|
|
|
|
|
|
"""Lazy loading of moved objects""" |
|
|
"""Lazy loading of moved objects""" |
|
|
|
|
|
|
|
|
__path__ = [] # mark as package |
|
|
__path__ = [] # mark as package |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
_moved_attributes = [ |
|
|
_moved_attributes = [ |
|
|
MovedAttribute("cStringIO", "cStringIO", "io", "StringIO"), |
|
|
MovedAttribute("cStringIO", "cStringIO", "io", "StringIO"), |
|
|
MovedAttribute("filter", "itertools", "builtins", "ifilter", "filter"), |
|
|
MovedAttribute("filter", "itertools", "builtins", "ifilter", "filter"), |
|
|
MovedAttribute("filterfalse", "itertools", "itertools", "ifilterfalse", "filterfalse"), |
|
|
MovedAttribute( |
|
|
|
|
|
"filterfalse", "itertools", "itertools", "ifilterfalse", "filterfalse" |
|
|
|
|
|
), |
|
|
MovedAttribute("input", "__builtin__", "builtins", "raw_input", "input"), |
|
|
MovedAttribute("input", "__builtin__", "builtins", "raw_input", "input"), |
|
|
MovedAttribute("intern", "__builtin__", "sys"), |
|
|
MovedAttribute("intern", "__builtin__", "sys"), |
|
|
MovedAttribute("map", "itertools", "builtins", "imap", "map"), |
|
|
MovedAttribute("map", "itertools", "builtins", "imap", "map"), |
|
|
MovedAttribute("getcwd", "os", "os", "getcwdu", "getcwd"), |
|
|
MovedAttribute("getcwd", "os", "os", "getcwdu", "getcwd"), |
|
|
MovedAttribute("getcwdb", "os", "os", "getcwd", "getcwdb"), |
|
|
MovedAttribute("getcwdb", "os", "os", "getcwd", "getcwdb"), |
|
|
MovedAttribute("range", "__builtin__", "builtins", "xrange", "range"), |
|
|
MovedAttribute("range", "__builtin__", "builtins", "xrange", "range"), |
|
|
MovedAttribute("reload_module", "__builtin__", "importlib" if PY34 else "imp", "reload"), |
|
|
MovedAttribute( |
|
|
|
|
|
"reload_module", "__builtin__", "importlib" if PY34 else "imp", "reload" |
|
|
|
|
|
), |
|
|
MovedAttribute("reduce", "__builtin__", "functools"), |
|
|
MovedAttribute("reduce", "__builtin__", "functools"), |
|
|
MovedAttribute("shlex_quote", "pipes", "shlex", "quote"), |
|
|
MovedAttribute("shlex_quote", "pipes", "shlex", "quote"), |
|
|
MovedAttribute("StringIO", "StringIO", "io"), |
|
|
MovedAttribute("StringIO", "StringIO", "io"), |
|
@ -251,7 +254,9 @@ _moved_attributes = [ |
|
|
MovedAttribute("UserString", "UserString", "collections"), |
|
|
MovedAttribute("UserString", "UserString", "collections"), |
|
|
MovedAttribute("xrange", "__builtin__", "builtins", "xrange", "range"), |
|
|
MovedAttribute("xrange", "__builtin__", "builtins", "xrange", "range"), |
|
|
MovedAttribute("zip", "itertools", "builtins", "izip", "zip"), |
|
|
MovedAttribute("zip", "itertools", "builtins", "izip", "zip"), |
|
|
MovedAttribute("zip_longest", "itertools", "itertools", "izip_longest", "zip_longest"), |
|
|
MovedAttribute( |
|
|
|
|
|
"zip_longest", "itertools", "itertools", "izip_longest", "zip_longest" |
|
|
|
|
|
), |
|
|
MovedModule("builtins", "__builtin__"), |
|
|
MovedModule("builtins", "__builtin__"), |
|
|
MovedModule("configparser", "ConfigParser"), |
|
|
MovedModule("configparser", "ConfigParser"), |
|
|
MovedModule("copyreg", "copy_reg"), |
|
|
MovedModule("copyreg", "copy_reg"), |
|
@ -263,7 +268,9 @@ _moved_attributes = [ |
|
|
MovedModule("html_parser", "HTMLParser", "html.parser"), |
|
|
MovedModule("html_parser", "HTMLParser", "html.parser"), |
|
|
MovedModule("http_client", "httplib", "http.client"), |
|
|
MovedModule("http_client", "httplib", "http.client"), |
|
|
MovedModule("email_mime_multipart", "email.MIMEMultipart", "email.mime.multipart"), |
|
|
MovedModule("email_mime_multipart", "email.MIMEMultipart", "email.mime.multipart"), |
|
|
MovedModule("email_mime_nonmultipart", "email.MIMENonMultipart", "email.mime.nonmultipart"), |
|
|
MovedModule( |
|
|
|
|
|
"email_mime_nonmultipart", "email.MIMENonMultipart", "email.mime.nonmultipart" |
|
|
|
|
|
), |
|
|
MovedModule("email_mime_text", "email.MIMEText", "email.mime.text"), |
|
|
MovedModule("email_mime_text", "email.MIMEText", "email.mime.text"), |
|
|
MovedModule("email_mime_base", "email.MIMEBase", "email.mime.base"), |
|
|
MovedModule("email_mime_base", "email.MIMEBase", "email.mime.base"), |
|
|
MovedModule("BaseHTTPServer", "BaseHTTPServer", "http.server"), |
|
|
MovedModule("BaseHTTPServer", "BaseHTTPServer", "http.server"), |
|
@ -283,15 +290,12 @@ _moved_attributes = [ |
|
|
MovedModule("tkinter_ttk", "ttk", "tkinter.ttk"), |
|
|
MovedModule("tkinter_ttk", "ttk", "tkinter.ttk"), |
|
|
MovedModule("tkinter_constants", "Tkconstants", "tkinter.constants"), |
|
|
MovedModule("tkinter_constants", "Tkconstants", "tkinter.constants"), |
|
|
MovedModule("tkinter_dnd", "Tkdnd", "tkinter.dnd"), |
|
|
MovedModule("tkinter_dnd", "Tkdnd", "tkinter.dnd"), |
|
|
MovedModule("tkinter_colorchooser", "tkColorChooser", |
|
|
MovedModule("tkinter_colorchooser", "tkColorChooser", "tkinter.colorchooser"), |
|
|
"tkinter.colorchooser"), |
|
|
MovedModule("tkinter_commondialog", "tkCommonDialog", "tkinter.commondialog"), |
|
|
MovedModule("tkinter_commondialog", "tkCommonDialog", |
|
|
|
|
|
"tkinter.commondialog"), |
|
|
|
|
|
MovedModule("tkinter_tkfiledialog", "tkFileDialog", "tkinter.filedialog"), |
|
|
MovedModule("tkinter_tkfiledialog", "tkFileDialog", "tkinter.filedialog"), |
|
|
MovedModule("tkinter_font", "tkFont", "tkinter.font"), |
|
|
MovedModule("tkinter_font", "tkFont", "tkinter.font"), |
|
|
MovedModule("tkinter_messagebox", "tkMessageBox", "tkinter.messagebox"), |
|
|
MovedModule("tkinter_messagebox", "tkMessageBox", "tkinter.messagebox"), |
|
|
MovedModule("tkinter_tksimpledialog", "tkSimpleDialog", |
|
|
MovedModule("tkinter_tksimpledialog", "tkSimpleDialog", "tkinter.simpledialog"), |
|
|
"tkinter.simpledialog"), |
|
|
|
|
|
MovedModule("urllib_parse", __name__ + ".moves.urllib_parse", "urllib.parse"), |
|
|
MovedModule("urllib_parse", __name__ + ".moves.urllib_parse", "urllib.parse"), |
|
|
MovedModule("urllib_error", __name__ + ".moves.urllib_error", "urllib.error"), |
|
|
MovedModule("urllib_error", __name__ + ".moves.urllib_error", "urllib.error"), |
|
|
MovedModule("urllib", __name__ + ".moves.urllib", __name__ + ".moves.urllib"), |
|
|
MovedModule("urllib", __name__ + ".moves.urllib", __name__ + ".moves.urllib"), |
|
@ -301,9 +305,7 @@ _moved_attributes = [ |
|
|
] |
|
|
] |
|
|
# Add windows specific modules. |
|
|
# Add windows specific modules. |
|
|
if sys.platform == "win32": |
|
|
if sys.platform == "win32": |
|
|
_moved_attributes += [ |
|
|
_moved_attributes += [MovedModule("winreg", "_winreg")] |
|
|
MovedModule("winreg", "_winreg"), |
|
|
|
|
|
] |
|
|
|
|
|
|
|
|
|
|
|
for attr in _moved_attributes: |
|
|
for attr in _moved_attributes: |
|
|
setattr(_MovedItems, attr.name, attr) |
|
|
setattr(_MovedItems, attr.name, attr) |
|
@ -353,8 +355,11 @@ del attr |
|
|
|
|
|
|
|
|
Module_six_moves_urllib_parse._moved_attributes = _urllib_parse_moved_attributes |
|
|
Module_six_moves_urllib_parse._moved_attributes = _urllib_parse_moved_attributes |
|
|
|
|
|
|
|
|
_importer._add_module(Module_six_moves_urllib_parse(__name__ + ".moves.urllib_parse"), |
|
|
_importer._add_module( |
|
|
"moves.urllib_parse", "moves.urllib.parse") |
|
|
Module_six_moves_urllib_parse(__name__ + ".moves.urllib_parse"), |
|
|
|
|
|
"moves.urllib_parse", |
|
|
|
|
|
"moves.urllib.parse", |
|
|
|
|
|
) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
class Module_six_moves_urllib_error(_LazyModule): |
|
|
class Module_six_moves_urllib_error(_LazyModule): |
|
@ -373,8 +378,11 @@ del attr |
|
|
|
|
|
|
|
|
Module_six_moves_urllib_error._moved_attributes = _urllib_error_moved_attributes |
|
|
Module_six_moves_urllib_error._moved_attributes = _urllib_error_moved_attributes |
|
|
|
|
|
|
|
|
_importer._add_module(Module_six_moves_urllib_error(__name__ + ".moves.urllib.error"), |
|
|
_importer._add_module( |
|
|
"moves.urllib_error", "moves.urllib.error") |
|
|
Module_six_moves_urllib_error(__name__ + ".moves.urllib.error"), |
|
|
|
|
|
"moves.urllib_error", |
|
|
|
|
|
"moves.urllib.error", |
|
|
|
|
|
) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
class Module_six_moves_urllib_request(_LazyModule): |
|
|
class Module_six_moves_urllib_request(_LazyModule): |
|
@ -423,8 +431,11 @@ del attr |
|
|
|
|
|
|
|
|
Module_six_moves_urllib_request._moved_attributes = _urllib_request_moved_attributes |
|
|
Module_six_moves_urllib_request._moved_attributes = _urllib_request_moved_attributes |
|
|
|
|
|
|
|
|
_importer._add_module(Module_six_moves_urllib_request(__name__ + ".moves.urllib.request"), |
|
|
_importer._add_module( |
|
|
"moves.urllib_request", "moves.urllib.request") |
|
|
Module_six_moves_urllib_request(__name__ + ".moves.urllib.request"), |
|
|
|
|
|
"moves.urllib_request", |
|
|
|
|
|
"moves.urllib.request", |
|
|
|
|
|
) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
class Module_six_moves_urllib_response(_LazyModule): |
|
|
class Module_six_moves_urllib_response(_LazyModule): |
|
@ -444,8 +455,11 @@ del attr |
|
|
|
|
|
|
|
|
Module_six_moves_urllib_response._moved_attributes = _urllib_response_moved_attributes |
|
|
Module_six_moves_urllib_response._moved_attributes = _urllib_response_moved_attributes |
|
|
|
|
|
|
|
|
_importer._add_module(Module_six_moves_urllib_response(__name__ + ".moves.urllib.response"), |
|
|
_importer._add_module( |
|
|
"moves.urllib_response", "moves.urllib.response") |
|
|
Module_six_moves_urllib_response(__name__ + ".moves.urllib.response"), |
|
|
|
|
|
"moves.urllib_response", |
|
|
|
|
|
"moves.urllib.response", |
|
|
|
|
|
) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
class Module_six_moves_urllib_robotparser(_LazyModule): |
|
|
class Module_six_moves_urllib_robotparser(_LazyModule): |
|
@ -454,21 +468,27 @@ class Module_six_moves_urllib_robotparser(_LazyModule): |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
_urllib_robotparser_moved_attributes = [ |
|
|
_urllib_robotparser_moved_attributes = [ |
|
|
MovedAttribute("RobotFileParser", "robotparser", "urllib.robotparser"), |
|
|
MovedAttribute("RobotFileParser", "robotparser", "urllib.robotparser") |
|
|
] |
|
|
] |
|
|
for attr in _urllib_robotparser_moved_attributes: |
|
|
for attr in _urllib_robotparser_moved_attributes: |
|
|
setattr(Module_six_moves_urllib_robotparser, attr.name, attr) |
|
|
setattr(Module_six_moves_urllib_robotparser, attr.name, attr) |
|
|
del attr |
|
|
del attr |
|
|
|
|
|
|
|
|
Module_six_moves_urllib_robotparser._moved_attributes = _urllib_robotparser_moved_attributes |
|
|
Module_six_moves_urllib_robotparser._moved_attributes = ( |
|
|
|
|
|
_urllib_robotparser_moved_attributes |
|
|
|
|
|
) |
|
|
|
|
|
|
|
|
_importer._add_module(Module_six_moves_urllib_robotparser(__name__ + ".moves.urllib.robotparser"), |
|
|
_importer._add_module( |
|
|
"moves.urllib_robotparser", "moves.urllib.robotparser") |
|
|
Module_six_moves_urllib_robotparser(__name__ + ".moves.urllib.robotparser"), |
|
|
|
|
|
"moves.urllib_robotparser", |
|
|
|
|
|
"moves.urllib.robotparser", |
|
|
|
|
|
) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
class Module_six_moves_urllib(types.ModuleType): |
|
|
class Module_six_moves_urllib(types.ModuleType): |
|
|
|
|
|
|
|
|
"""Create a six.moves.urllib namespace that resembles the Python 3 namespace""" |
|
|
"""Create a six.moves.urllib namespace that resembles the Python 3 namespace""" |
|
|
|
|
|
|
|
|
__path__ = [] # mark as package |
|
|
__path__ = [] # mark as package |
|
|
parse = _importer._get_module("moves.urllib_parse") |
|
|
parse = _importer._get_module("moves.urllib_parse") |
|
|
error = _importer._get_module("moves.urllib_error") |
|
|
error = _importer._get_module("moves.urllib_error") |
|
@ -477,10 +497,12 @@ class Module_six_moves_urllib(types.ModuleType): |
|
|
robotparser = _importer._get_module("moves.urllib_robotparser") |
|
|
robotparser = _importer._get_module("moves.urllib_robotparser") |
|
|
|
|
|
|
|
|
def __dir__(self): |
|
|
def __dir__(self): |
|
|
return ['parse', 'error', 'request', 'response', 'robotparser'] |
|
|
return ["parse", "error", "request", "response", "robotparser"] |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
_importer._add_module(Module_six_moves_urllib(__name__ + ".moves.urllib"), |
|
|
_importer._add_module( |
|
|
"moves.urllib") |
|
|
Module_six_moves_urllib(__name__ + ".moves.urllib"), "moves.urllib" |
|
|
|
|
|
) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def add_move(move): |
|
|
def add_move(move): |
|
@ -520,19 +542,24 @@ else: |
|
|
try: |
|
|
try: |
|
|
advance_iterator = next |
|
|
advance_iterator = next |
|
|
except NameError: |
|
|
except NameError: |
|
|
|
|
|
|
|
|
def advance_iterator(it): |
|
|
def advance_iterator(it): |
|
|
return it.next() |
|
|
return it.next() |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
next = advance_iterator |
|
|
next = advance_iterator |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
try: |
|
|
try: |
|
|
callable = callable |
|
|
callable = callable |
|
|
except NameError: |
|
|
except NameError: |
|
|
|
|
|
|
|
|
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__) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if PY3: |
|
|
if PY3: |
|
|
|
|
|
|
|
|
def get_unbound_function(unbound): |
|
|
def get_unbound_function(unbound): |
|
|
return unbound |
|
|
return unbound |
|
|
|
|
|
|
|
@ -543,6 +570,7 @@ if PY3: |
|
|
|
|
|
|
|
|
Iterator = object |
|
|
Iterator = object |
|
|
else: |
|
|
else: |
|
|
|
|
|
|
|
|
def get_unbound_function(unbound): |
|
|
def get_unbound_function(unbound): |
|
|
return unbound.im_func |
|
|
return unbound.im_func |
|
|
|
|
|
|
|
@ -553,13 +581,13 @@ else: |
|
|
return types.MethodType(func, None, cls) |
|
|
return types.MethodType(func, None, cls) |
|
|
|
|
|
|
|
|
class Iterator(object): |
|
|
class Iterator(object): |
|
|
|
|
|
|
|
|
def next(self): |
|
|
def next(self): |
|
|
return type(self).__next__(self) |
|
|
return type(self).__next__(self) |
|
|
|
|
|
|
|
|
callable = callable |
|
|
callable = callable |
|
|
_add_doc(get_unbound_function, |
|
|
_add_doc( |
|
|
"""Get the function out of a possibly unbound function""") |
|
|
get_unbound_function, """Get the function out of a possibly unbound function""" |
|
|
|
|
|
) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
get_method_function = operator.attrgetter(_meth_func) |
|
|
get_method_function = operator.attrgetter(_meth_func) |
|
@ -571,6 +599,7 @@ get_function_globals = operator.attrgetter(_func_globals) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if PY3: |
|
|
if PY3: |
|
|
|
|
|
|
|
|
def iterkeys(d, **kw): |
|
|
def iterkeys(d, **kw): |
|
|
return iter(d.keys(**kw)) |
|
|
return iter(d.keys(**kw)) |
|
|
|
|
|
|
|
@ -589,6 +618,7 @@ if PY3: |
|
|
|
|
|
|
|
|
viewitems = operator.methodcaller("items") |
|
|
viewitems = operator.methodcaller("items") |
|
|
else: |
|
|
else: |
|
|
|
|
|
|
|
|
def iterkeys(d, **kw): |
|
|
def iterkeys(d, **kw): |
|
|
return d.iterkeys(**kw) |
|
|
return d.iterkeys(**kw) |
|
|
|
|
|
|
|
@ -609,26 +639,30 @@ else: |
|
|
|
|
|
|
|
|
_add_doc(iterkeys, "Return an iterator over the keys of a dictionary.") |
|
|
_add_doc(iterkeys, "Return an iterator over the keys of a dictionary.") |
|
|
_add_doc(itervalues, "Return an iterator over the values of a dictionary.") |
|
|
_add_doc(itervalues, "Return an iterator over the values of a dictionary.") |
|
|
_add_doc(iteritems, |
|
|
_add_doc(iteritems, "Return an iterator over the (key, value) pairs of a dictionary.") |
|
|
"Return an iterator over the (key, value) pairs of a dictionary.") |
|
|
_add_doc( |
|
|
_add_doc(iterlists, |
|
|
iterlists, "Return an iterator over the (key, [values]) pairs of a dictionary." |
|
|
"Return an iterator over the (key, [values]) pairs of a dictionary.") |
|
|
) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if PY3: |
|
|
if PY3: |
|
|
|
|
|
|
|
|
def b(s): |
|
|
def b(s): |
|
|
return s.encode("latin-1") |
|
|
return s.encode("latin-1") |
|
|
|
|
|
|
|
|
def u(s): |
|
|
def u(s): |
|
|
return s |
|
|
return s |
|
|
|
|
|
|
|
|
unichr = chr |
|
|
unichr = chr |
|
|
import struct |
|
|
import struct |
|
|
|
|
|
|
|
|
int2byte = struct.Struct(">B").pack |
|
|
int2byte = struct.Struct(">B").pack |
|
|
del struct |
|
|
del struct |
|
|
byte2int = operator.itemgetter(0) |
|
|
byte2int = operator.itemgetter(0) |
|
|
indexbytes = operator.getitem |
|
|
indexbytes = operator.getitem |
|
|
iterbytes = iter |
|
|
iterbytes = iter |
|
|
import io |
|
|
import io |
|
|
|
|
|
|
|
|
StringIO = io.StringIO |
|
|
StringIO = io.StringIO |
|
|
BytesIO = io.BytesIO |
|
|
BytesIO = io.BytesIO |
|
|
_assertCountEqual = "assertCountEqual" |
|
|
_assertCountEqual = "assertCountEqual" |
|
@ -639,12 +673,15 @@ if PY3: |
|
|
_assertRaisesRegex = "assertRaisesRegex" |
|
|
_assertRaisesRegex = "assertRaisesRegex" |
|
|
_assertRegex = "assertRegex" |
|
|
_assertRegex = "assertRegex" |
|
|
else: |
|
|
else: |
|
|
|
|
|
|
|
|
def b(s): |
|
|
def b(s): |
|
|
return s |
|
|
return s |
|
|
|
|
|
|
|
|
# Workaround for standalone backslash |
|
|
# Workaround for standalone backslash |
|
|
|
|
|
|
|
|
def u(s): |
|
|
def u(s): |
|
|
return unicode(s.replace(r'\\', r'\\\\'), "unicode_escape") |
|
|
return unicode(s.replace(r"\\", r"\\\\"), "unicode_escape") |
|
|
|
|
|
|
|
|
unichr = unichr |
|
|
unichr = unichr |
|
|
int2byte = chr |
|
|
int2byte = chr |
|
|
|
|
|
|
|
@ -653,8 +690,10 @@ else: |
|
|
|
|
|
|
|
|
def indexbytes(buf, i): |
|
|
def indexbytes(buf, i): |
|
|
return ord(buf[i]) |
|
|
return ord(buf[i]) |
|
|
|
|
|
|
|
|
iterbytes = functools.partial(itertools.imap, ord) |
|
|
iterbytes = functools.partial(itertools.imap, ord) |
|
|
import StringIO |
|
|
import StringIO |
|
|
|
|
|
|
|
|
StringIO = BytesIO = StringIO.StringIO |
|
|
StringIO = BytesIO = StringIO.StringIO |
|
|
_assertCountEqual = "assertItemsEqual" |
|
|
_assertCountEqual = "assertItemsEqual" |
|
|
_assertRaisesRegex = "assertRaisesRegexp" |
|
|
_assertRaisesRegex = "assertRaisesRegexp" |
|
@ -685,7 +724,9 @@ if PY3: |
|
|
raise value.with_traceback(tb) |
|
|
raise value.with_traceback(tb) |
|
|
raise value |
|
|
raise value |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
else: |
|
|
else: |
|
|
|
|
|
|
|
|
def exec_(_code_, _globs_=None, _locs_=None): |
|
|
def exec_(_code_, _globs_=None, _locs_=None): |
|
|
"""Execute code in a namespace.""" |
|
|
"""Execute code in a namespace.""" |
|
|
if _globs_ is None: |
|
|
if _globs_ is None: |
|
@ -698,28 +739,36 @@ else: |
|
|
_locs_ = _globs_ |
|
|
_locs_ = _globs_ |
|
|
exec("""exec _code_ in _globs_, _locs_""") |
|
|
exec("""exec _code_ in _globs_, _locs_""") |
|
|
|
|
|
|
|
|
exec_("""def reraise(tp, value, tb=None): |
|
|
exec_( |
|
|
|
|
|
"""def reraise(tp, value, tb=None): |
|
|
raise tp, value, tb |
|
|
raise tp, value, tb |
|
|
""") |
|
|
""" |
|
|
|
|
|
) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if sys.version_info[:2] == (3, 2): |
|
|
if sys.version_info[:2] == (3, 2): |
|
|
exec_("""def raise_from(value, from_value): |
|
|
exec_( |
|
|
|
|
|
"""def raise_from(value, from_value): |
|
|
if from_value is None: |
|
|
if from_value is None: |
|
|
raise value |
|
|
raise value |
|
|
raise value from from_value |
|
|
raise value from from_value |
|
|
""") |
|
|
""" |
|
|
|
|
|
) |
|
|
elif sys.version_info[:2] > (3, 2): |
|
|
elif sys.version_info[:2] > (3, 2): |
|
|
exec_("""def raise_from(value, from_value): |
|
|
exec_( |
|
|
|
|
|
"""def raise_from(value, from_value): |
|
|
raise value from from_value |
|
|
raise value from from_value |
|
|
""") |
|
|
""" |
|
|
|
|
|
) |
|
|
else: |
|
|
else: |
|
|
|
|
|
|
|
|
def raise_from(value, from_value): |
|
|
def raise_from(value, from_value): |
|
|
raise value |
|
|
raise value |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
print_ = getattr(moves.builtins, "print", None) |
|
|
print_ = getattr(moves.builtins, "print", None) |
|
|
if print_ is None: |
|
|
if print_ is None: |
|
|
|
|
|
|
|
|
def print_(*args, **kwargs): |
|
|
def print_(*args, **kwargs): |
|
|
"""The new-style print function for Python 2.4 and 2.5.""" |
|
|
"""The new-style print function for Python 2.4 and 2.5.""" |
|
|
fp = kwargs.pop("file", sys.stdout) |
|
|
fp = kwargs.pop("file", sys.stdout) |
|
@ -730,14 +779,17 @@ if print_ is None: |
|
|
if not isinstance(data, basestring): |
|
|
if not isinstance(data, basestring): |
|
|
data = str(data) |
|
|
data = str(data) |
|
|
# If the file has an encoding, encode unicode with it. |
|
|
# If the file has an encoding, encode unicode with it. |
|
|
if (isinstance(fp, file) and |
|
|
if ( |
|
|
isinstance(data, unicode) and |
|
|
isinstance(fp, file) |
|
|
fp.encoding is not None): |
|
|
and isinstance(data, unicode) |
|
|
|
|
|
and fp.encoding is not None |
|
|
|
|
|
): |
|
|
errors = getattr(fp, "errors", None) |
|
|
errors = getattr(fp, "errors", None) |
|
|
if errors is None: |
|
|
if errors is None: |
|
|
errors = "strict" |
|
|
errors = "strict" |
|
|
data = data.encode(fp.encoding, errors) |
|
|
data = data.encode(fp.encoding, errors) |
|
|
fp.write(data) |
|
|
fp.write(data) |
|
|
|
|
|
|
|
|
want_unicode = False |
|
|
want_unicode = False |
|
|
sep = kwargs.pop("sep", None) |
|
|
sep = kwargs.pop("sep", None) |
|
|
if sep is not None: |
|
|
if sep is not None: |
|
@ -773,6 +825,8 @@ if print_ is None: |
|
|
write(sep) |
|
|
write(sep) |
|
|
write(arg) |
|
|
write(arg) |
|
|
write(end) |
|
|
write(end) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if sys.version_info[:2] < (3, 3): |
|
|
if sys.version_info[:2] < (3, 3): |
|
|
_print = print_ |
|
|
_print = print_ |
|
|
|
|
|
|
|
@ -783,16 +837,24 @@ if sys.version_info[:2] < (3, 3): |
|
|
if flush and fp is not None: |
|
|
if flush and fp is not None: |
|
|
fp.flush() |
|
|
fp.flush() |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
_add_doc(reraise, """Reraise an exception.""") |
|
|
_add_doc(reraise, """Reraise an exception.""") |
|
|
|
|
|
|
|
|
if sys.version_info[0:2] < (3, 4): |
|
|
if sys.version_info[0:2] < (3, 4): |
|
|
def wraps(wrapped, assigned=functools.WRAPPER_ASSIGNMENTS, |
|
|
|
|
|
updated=functools.WRAPPER_UPDATES): |
|
|
def wraps( |
|
|
|
|
|
wrapped, |
|
|
|
|
|
assigned=functools.WRAPPER_ASSIGNMENTS, |
|
|
|
|
|
updated=functools.WRAPPER_UPDATES, |
|
|
|
|
|
): |
|
|
def wrapper(f): |
|
|
def wrapper(f): |
|
|
f = functools.wraps(wrapped, assigned, updated)(f) |
|
|
f = functools.wraps(wrapped, assigned, updated)(f) |
|
|
f.__wrapped__ = wrapped |
|
|
f.__wrapped__ = wrapped |
|
|
return f |
|
|
return f |
|
|
|
|
|
|
|
|
return wrapper |
|
|
return wrapper |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
else: |
|
|
else: |
|
|
wraps = functools.wraps |
|
|
wraps = functools.wraps |
|
|
|
|
|
|
|
@ -803,25 +865,27 @@ def with_metaclass(meta, *bases): |
|
|
# metaclass for one level of class instantiation that replaces itself with |
|
|
# metaclass for one level of class instantiation that replaces itself with |
|
|
# the actual metaclass. |
|
|
# the actual metaclass. |
|
|
class metaclass(meta): |
|
|
class metaclass(meta): |
|
|
|
|
|
|
|
|
def __new__(cls, name, this_bases, d): |
|
|
def __new__(cls, name, this_bases, d): |
|
|
return meta(name, bases, d) |
|
|
return meta(name, bases, d) |
|
|
return type.__new__(metaclass, 'temporary_class', (), {}) |
|
|
|
|
|
|
|
|
return type.__new__(metaclass, "temporary_class", (), {}) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def add_metaclass(metaclass): |
|
|
def add_metaclass(metaclass): |
|
|
"""Class decorator for creating a class with a metaclass.""" |
|
|
"""Class decorator for creating a class with a metaclass.""" |
|
|
|
|
|
|
|
|
def wrapper(cls): |
|
|
def wrapper(cls): |
|
|
orig_vars = cls.__dict__.copy() |
|
|
orig_vars = cls.__dict__.copy() |
|
|
slots = orig_vars.get('__slots__') |
|
|
slots = orig_vars.get("__slots__") |
|
|
if slots is not None: |
|
|
if slots is not None: |
|
|
if isinstance(slots, str): |
|
|
if isinstance(slots, str): |
|
|
slots = [slots] |
|
|
slots = [slots] |
|
|
for slots_var in slots: |
|
|
for slots_var in slots: |
|
|
orig_vars.pop(slots_var) |
|
|
orig_vars.pop(slots_var) |
|
|
orig_vars.pop('__dict__', None) |
|
|
orig_vars.pop("__dict__", None) |
|
|
orig_vars.pop('__weakref__', None) |
|
|
orig_vars.pop("__weakref__", None) |
|
|
return metaclass(cls.__name__, cls.__bases__, orig_vars) |
|
|
return metaclass(cls.__name__, cls.__bases__, orig_vars) |
|
|
|
|
|
|
|
|
return wrapper |
|
|
return wrapper |
|
|
|
|
|
|
|
|
|
|
|
|
|
@ -834,12 +898,13 @@ def python_2_unicode_compatible(klass): |
|
|
returning text and apply this decorator to the class. |
|
|
returning text and apply this decorator to the class. |
|
|
""" |
|
|
""" |
|
|
if PY2: |
|
|
if PY2: |
|
|
if '__str__' not in klass.__dict__: |
|
|
if "__str__" not in klass.__dict__: |
|
|
raise ValueError("@python_2_unicode_compatible cannot be applied " |
|
|
raise ValueError( |
|
|
"to %s because it doesn't define __str__()." % |
|
|
"@python_2_unicode_compatible cannot be applied " |
|
|
klass.__name__) |
|
|
"to %s because it doesn't define __str__()." % klass.__name__ |
|
|
|
|
|
) |
|
|
klass.__unicode__ = klass.__str__ |
|
|
klass.__unicode__ = klass.__str__ |
|
|
klass.__str__ = lambda self: self.__unicode__().encode('utf-8') |
|
|
klass.__str__ = lambda self: self.__unicode__().encode("utf-8") |
|
|
return klass |
|
|
return klass |
|
|
|
|
|
|
|
|
|
|
|
|
|
@ -859,8 +924,10 @@ if sys.meta_path: |
|
|
# be floating around. Therefore, we can't use isinstance() to check for |
|
|
# be floating around. Therefore, we can't use isinstance() to check for |
|
|
# the six meta path importer, since the other six instance will have |
|
|
# the six meta path importer, since the other six instance will have |
|
|
# inserted an importer with different class. |
|
|
# inserted an importer with different class. |
|
|
if (type(importer).__name__ == "_SixMetaPathImporter" and |
|
|
if ( |
|
|
importer.name == __name__): |
|
|
type(importer).__name__ == "_SixMetaPathImporter" |
|
|
|
|
|
and importer.name == __name__ |
|
|
|
|
|
): |
|
|
del sys.meta_path[i] |
|
|
del sys.meta_path[i] |
|
|
break |
|
|
break |
|
|
del i, importer |
|
|
del i, importer |
|
|