[pre-commit.ci] auto fixes from pre-commit.com hooks

for more information, see https://pre-commit.ci
This commit is contained in:
pre-commit-ci[bot] 2024-04-13 00:00:18 +00:00
parent 72ad6dc953
commit f4cd1ba0d6
813 changed files with 66015 additions and 58839 deletions

View file

@ -17,10 +17,8 @@
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
# SOFTWARE.
"""Utilities for writing code that runs on Python 2 and 3"""
from __future__ import absolute_import
from __future__ import annotations
import functools
import itertools
@ -28,8 +26,8 @@ import operator
import sys
import types
__author__ = "Benjamin Peterson <benjamin@python.org>"
__version__ = "1.16.0"
__author__ = 'Benjamin Peterson <benjamin@python.org>'
__version__ = '1.16.0'
# Useful for very coarse version differentiation.
@ -52,12 +50,12 @@ else:
text_type = unicode
binary_type = str
if sys.platform.startswith("java"):
if sys.platform.startswith('java'):
# Jython always uses 32 bits.
MAXSIZE = int((1 << 31) - 1)
else:
# It's possible to have sizeof(long) != sizeof(Py_ssize_t).
class X(object):
class X:
def __len__(self):
return 1 << 31
@ -88,7 +86,7 @@ def _import_module(name):
return sys.modules[name]
class _LazyDescr(object):
class _LazyDescr:
def __init__(self, name):
self.name = name
@ -108,7 +106,7 @@ class _LazyDescr(object):
class MovedModule(_LazyDescr):
def __init__(self, name, old, new=None):
super(MovedModule, self).__init__(name)
super().__init__(name)
if PY3:
if new is None:
new = name
@ -129,11 +127,11 @@ class MovedModule(_LazyDescr):
class _LazyModule(types.ModuleType):
def __init__(self, name):
super(_LazyModule, self).__init__(name)
super().__init__(name)
self.__doc__ = self.__class__.__doc__
def __dir__(self):
attrs = ["__doc__", "__name__"]
attrs = ['__doc__', '__name__']
attrs += [attr.name for attr in self._moved_attributes]
return attrs
@ -144,7 +142,7 @@ class _LazyModule(types.ModuleType):
class MovedAttribute(_LazyDescr):
def __init__(self, name, old_mod, new_mod, old_attr=None, new_attr=None):
super(MovedAttribute, self).__init__(name)
super().__init__(name)
if PY3:
if new_mod is None:
new_mod = name
@ -166,7 +164,7 @@ class MovedAttribute(_LazyDescr):
return getattr(module, self.attr)
class _SixMetaPathImporter(object):
class _SixMetaPathImporter:
"""
A meta path importer to import six.moves and its submodules.
@ -181,10 +179,10 @@ class _SixMetaPathImporter(object):
def _add_module(self, mod, *fullnames):
for fullname in fullnames:
self.known_modules[self.name + "." + fullname] = mod
self.known_modules[self.name + '.' + fullname] = mod
def _get_module(self, fullname):
return self.known_modules[self.name + "." + fullname]
return self.known_modules[self.name + '.' + fullname]
def find_module(self, fullname, path=None):
if fullname in self.known_modules:
@ -200,7 +198,7 @@ class _SixMetaPathImporter(object):
try:
return self.known_modules[fullname]
except KeyError:
raise ImportError("This loader does not know module " + fullname)
raise ImportError('This loader does not know module ' + fullname)
def load_module(self, fullname):
try:
@ -223,7 +221,7 @@ class _SixMetaPathImporter(object):
We need this method to get correct spec objects with
Python 3.4 (see PEP451)
"""
return hasattr(self.__get_module(fullname), "__path__")
return hasattr(self.__get_module(fullname), '__path__')
def get_code(self, fullname):
"""Return None
@ -239,6 +237,7 @@ class _SixMetaPathImporter(object):
def exec_module(self, module):
pass
_importer = _SixMetaPathImporter(__name__)
@ -249,92 +248,98 @@ class _MovedItems(_LazyModule):
_moved_attributes = [
MovedAttribute("cStringIO", "cStringIO", "io", "StringIO"),
MovedAttribute("filter", "itertools", "builtins", "ifilter", "filter"),
MovedAttribute("filterfalse", "itertools", "itertools", "ifilterfalse", "filterfalse"),
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("getoutput", "commands", "subprocess"),
MovedAttribute("range", "__builtin__", "builtins", "xrange", "range"),
MovedAttribute("reload_module", "__builtin__", "importlib" if PY34 else "imp", "reload"),
MovedAttribute("reduce", "__builtin__", "functools"),
MovedAttribute("shlex_quote", "pipes", "shlex", "quote"),
MovedAttribute("StringIO", "StringIO", "io"),
MovedAttribute("UserDict", "UserDict", "collections"),
MovedAttribute("UserList", "UserList", "collections"),
MovedAttribute("UserString", "UserString", "collections"),
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("collections_abc", "collections", "collections.abc" if sys.version_info >= (3, 3) else "collections"),
MovedModule("copyreg", "copy_reg"),
MovedModule("dbm_gnu", "gdbm", "dbm.gnu"),
MovedModule("dbm_ndbm", "dbm", "dbm.ndbm"),
MovedModule("_dummy_thread", "dummy_thread", "_dummy_thread" if sys.version_info < (3, 9) else "_thread"),
MovedModule("http_cookiejar", "cookielib", "http.cookiejar"),
MovedModule("http_cookies", "Cookie", "http.cookies"),
MovedModule("html_entities", "htmlentitydefs", "html.entities"),
MovedModule("html_parser", "HTMLParser", "html.parser"),
MovedModule("http_client", "httplib", "http.client"),
MovedModule("email_mime_base", "email.MIMEBase", "email.mime.base"),
MovedModule("email_mime_image", "email.MIMEImage", "email.mime.image"),
MovedModule("email_mime_multipart", "email.MIMEMultipart", "email.mime.multipart"),
MovedModule("email_mime_nonmultipart", "email.MIMENonMultipart", "email.mime.nonmultipart"),
MovedModule("email_mime_text", "email.MIMEText", "email.mime.text"),
MovedModule("BaseHTTPServer", "BaseHTTPServer", "http.server"),
MovedModule("CGIHTTPServer", "CGIHTTPServer", "http.server"),
MovedModule("SimpleHTTPServer", "SimpleHTTPServer", "http.server"),
MovedModule("cPickle", "cPickle", "pickle"),
MovedModule("queue", "Queue"),
MovedModule("reprlib", "repr"),
MovedModule("socketserver", "SocketServer"),
MovedModule("_thread", "thread", "_thread"),
MovedModule("tkinter", "Tkinter"),
MovedModule("tkinter_dialog", "Dialog", "tkinter.dialog"),
MovedModule("tkinter_filedialog", "FileDialog", "tkinter.filedialog"),
MovedModule("tkinter_scrolledtext", "ScrolledText", "tkinter.scrolledtext"),
MovedModule("tkinter_simpledialog", "SimpleDialog", "tkinter.simpledialog"),
MovedModule("tkinter_tix", "Tix", "tkinter.tix"),
MovedModule("tkinter_ttk", "ttk", "tkinter.ttk"),
MovedModule("tkinter_constants", "Tkconstants", "tkinter.constants"),
MovedModule("tkinter_dnd", "Tkdnd", "tkinter.dnd"),
MovedModule("tkinter_colorchooser", "tkColorChooser",
"tkinter.colorchooser"),
MovedModule("tkinter_commondialog", "tkCommonDialog",
"tkinter.commondialog"),
MovedModule("tkinter_tkfiledialog", "tkFileDialog", "tkinter.filedialog"),
MovedModule("tkinter_font", "tkFont", "tkinter.font"),
MovedModule("tkinter_messagebox", "tkMessageBox", "tkinter.messagebox"),
MovedModule("tkinter_tksimpledialog", "tkSimpleDialog",
"tkinter.simpledialog"),
MovedModule("urllib_parse", __name__ + ".moves.urllib_parse", "urllib.parse"),
MovedModule("urllib_error", __name__ + ".moves.urllib_error", "urllib.error"),
MovedModule("urllib", __name__ + ".moves.urllib", __name__ + ".moves.urllib"),
MovedModule("urllib_robotparser", "robotparser", "urllib.robotparser"),
MovedModule("xmlrpc_client", "xmlrpclib", "xmlrpc.client"),
MovedModule("xmlrpc_server", "SimpleXMLRPCServer", "xmlrpc.server"),
MovedAttribute('cStringIO', 'cStringIO', 'io', 'StringIO'),
MovedAttribute('filter', 'itertools', 'builtins', 'ifilter', 'filter'),
MovedAttribute('filterfalse', 'itertools', 'itertools', 'ifilterfalse', 'filterfalse'),
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('getoutput', 'commands', 'subprocess'),
MovedAttribute('range', '__builtin__', 'builtins', 'xrange', 'range'),
MovedAttribute('reload_module', '__builtin__', 'importlib' if PY34 else 'imp', 'reload'),
MovedAttribute('reduce', '__builtin__', 'functools'),
MovedAttribute('shlex_quote', 'pipes', 'shlex', 'quote'),
MovedAttribute('StringIO', 'StringIO', 'io'),
MovedAttribute('UserDict', 'UserDict', 'collections'),
MovedAttribute('UserList', 'UserList', 'collections'),
MovedAttribute('UserString', 'UserString', 'collections'),
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('collections_abc', 'collections', 'collections.abc' if sys.version_info >= (3, 3) else 'collections'),
MovedModule('copyreg', 'copy_reg'),
MovedModule('dbm_gnu', 'gdbm', 'dbm.gnu'),
MovedModule('dbm_ndbm', 'dbm', 'dbm.ndbm'),
MovedModule('_dummy_thread', 'dummy_thread', '_dummy_thread' if sys.version_info < (3, 9) else '_thread'),
MovedModule('http_cookiejar', 'cookielib', 'http.cookiejar'),
MovedModule('http_cookies', 'Cookie', 'http.cookies'),
MovedModule('html_entities', 'htmlentitydefs', 'html.entities'),
MovedModule('html_parser', 'HTMLParser', 'html.parser'),
MovedModule('http_client', 'httplib', 'http.client'),
MovedModule('email_mime_base', 'email.MIMEBase', 'email.mime.base'),
MovedModule('email_mime_image', 'email.MIMEImage', 'email.mime.image'),
MovedModule('email_mime_multipart', 'email.MIMEMultipart', 'email.mime.multipart'),
MovedModule('email_mime_nonmultipart', 'email.MIMENonMultipart', 'email.mime.nonmultipart'),
MovedModule('email_mime_text', 'email.MIMEText', 'email.mime.text'),
MovedModule('BaseHTTPServer', 'BaseHTTPServer', 'http.server'),
MovedModule('CGIHTTPServer', 'CGIHTTPServer', 'http.server'),
MovedModule('SimpleHTTPServer', 'SimpleHTTPServer', 'http.server'),
MovedModule('cPickle', 'cPickle', 'pickle'),
MovedModule('queue', 'Queue'),
MovedModule('reprlib', 'repr'),
MovedModule('socketserver', 'SocketServer'),
MovedModule('_thread', 'thread', '_thread'),
MovedModule('tkinter', 'Tkinter'),
MovedModule('tkinter_dialog', 'Dialog', 'tkinter.dialog'),
MovedModule('tkinter_filedialog', 'FileDialog', 'tkinter.filedialog'),
MovedModule('tkinter_scrolledtext', 'ScrolledText', 'tkinter.scrolledtext'),
MovedModule('tkinter_simpledialog', 'SimpleDialog', 'tkinter.simpledialog'),
MovedModule('tkinter_tix', 'Tix', 'tkinter.tix'),
MovedModule('tkinter_ttk', 'ttk', 'tkinter.ttk'),
MovedModule('tkinter_constants', 'Tkconstants', 'tkinter.constants'),
MovedModule('tkinter_dnd', 'Tkdnd', 'tkinter.dnd'),
MovedModule(
'tkinter_colorchooser', 'tkColorChooser',
'tkinter.colorchooser',
),
MovedModule(
'tkinter_commondialog', 'tkCommonDialog',
'tkinter.commondialog',
),
MovedModule('tkinter_tkfiledialog', 'tkFileDialog', 'tkinter.filedialog'),
MovedModule('tkinter_font', 'tkFont', 'tkinter.font'),
MovedModule('tkinter_messagebox', 'tkMessageBox', 'tkinter.messagebox'),
MovedModule(
'tkinter_tksimpledialog', 'tkSimpleDialog',
'tkinter.simpledialog',
),
MovedModule('urllib_parse', __name__ + '.moves.urllib_parse', 'urllib.parse'),
MovedModule('urllib_error', __name__ + '.moves.urllib_error', 'urllib.error'),
MovedModule('urllib', __name__ + '.moves.urllib', __name__ + '.moves.urllib'),
MovedModule('urllib_robotparser', 'robotparser', 'urllib.robotparser'),
MovedModule('xmlrpc_client', 'xmlrpclib', 'xmlrpc.client'),
MovedModule('xmlrpc_server', 'SimpleXMLRPCServer', 'xmlrpc.server'),
]
# Add windows specific modules.
if sys.platform == "win32":
if sys.platform == 'win32':
_moved_attributes += [
MovedModule("winreg", "_winreg"),
MovedModule('winreg', '_winreg'),
]
for attr in _moved_attributes:
setattr(_MovedItems, attr.name, attr)
if isinstance(attr, MovedModule):
_importer._add_module(attr, "moves." + attr.name)
_importer._add_module(attr, 'moves.' + attr.name)
del attr
_MovedItems._moved_attributes = _moved_attributes
moves = _MovedItems(__name__ + ".moves")
_importer._add_module(moves, "moves")
moves = _MovedItems(__name__ + '.moves')
_importer._add_module(moves, 'moves')
class Module_six_moves_urllib_parse(_LazyModule):
@ -343,31 +348,31 @@ class Module_six_moves_urllib_parse(_LazyModule):
_urllib_parse_moved_attributes = [
MovedAttribute("ParseResult", "urlparse", "urllib.parse"),
MovedAttribute("SplitResult", "urlparse", "urllib.parse"),
MovedAttribute("parse_qs", "urlparse", "urllib.parse"),
MovedAttribute("parse_qsl", "urlparse", "urllib.parse"),
MovedAttribute("urldefrag", "urlparse", "urllib.parse"),
MovedAttribute("urljoin", "urlparse", "urllib.parse"),
MovedAttribute("urlparse", "urlparse", "urllib.parse"),
MovedAttribute("urlsplit", "urlparse", "urllib.parse"),
MovedAttribute("urlunparse", "urlparse", "urllib.parse"),
MovedAttribute("urlunsplit", "urlparse", "urllib.parse"),
MovedAttribute("quote", "urllib", "urllib.parse"),
MovedAttribute("quote_plus", "urllib", "urllib.parse"),
MovedAttribute("unquote", "urllib", "urllib.parse"),
MovedAttribute("unquote_plus", "urllib", "urllib.parse"),
MovedAttribute("unquote_to_bytes", "urllib", "urllib.parse", "unquote", "unquote_to_bytes"),
MovedAttribute("urlencode", "urllib", "urllib.parse"),
MovedAttribute("splitquery", "urllib", "urllib.parse"),
MovedAttribute("splittag", "urllib", "urllib.parse"),
MovedAttribute("splituser", "urllib", "urllib.parse"),
MovedAttribute("splitvalue", "urllib", "urllib.parse"),
MovedAttribute("uses_fragment", "urlparse", "urllib.parse"),
MovedAttribute("uses_netloc", "urlparse", "urllib.parse"),
MovedAttribute("uses_params", "urlparse", "urllib.parse"),
MovedAttribute("uses_query", "urlparse", "urllib.parse"),
MovedAttribute("uses_relative", "urlparse", "urllib.parse"),
MovedAttribute('ParseResult', 'urlparse', 'urllib.parse'),
MovedAttribute('SplitResult', 'urlparse', 'urllib.parse'),
MovedAttribute('parse_qs', 'urlparse', 'urllib.parse'),
MovedAttribute('parse_qsl', 'urlparse', 'urllib.parse'),
MovedAttribute('urldefrag', 'urlparse', 'urllib.parse'),
MovedAttribute('urljoin', 'urlparse', 'urllib.parse'),
MovedAttribute('urlparse', 'urlparse', 'urllib.parse'),
MovedAttribute('urlsplit', 'urlparse', 'urllib.parse'),
MovedAttribute('urlunparse', 'urlparse', 'urllib.parse'),
MovedAttribute('urlunsplit', 'urlparse', 'urllib.parse'),
MovedAttribute('quote', 'urllib', 'urllib.parse'),
MovedAttribute('quote_plus', 'urllib', 'urllib.parse'),
MovedAttribute('unquote', 'urllib', 'urllib.parse'),
MovedAttribute('unquote_plus', 'urllib', 'urllib.parse'),
MovedAttribute('unquote_to_bytes', 'urllib', 'urllib.parse', 'unquote', 'unquote_to_bytes'),
MovedAttribute('urlencode', 'urllib', 'urllib.parse'),
MovedAttribute('splitquery', 'urllib', 'urllib.parse'),
MovedAttribute('splittag', 'urllib', 'urllib.parse'),
MovedAttribute('splituser', 'urllib', 'urllib.parse'),
MovedAttribute('splitvalue', 'urllib', 'urllib.parse'),
MovedAttribute('uses_fragment', 'urlparse', 'urllib.parse'),
MovedAttribute('uses_netloc', 'urlparse', 'urllib.parse'),
MovedAttribute('uses_params', 'urlparse', 'urllib.parse'),
MovedAttribute('uses_query', 'urlparse', 'urllib.parse'),
MovedAttribute('uses_relative', 'urlparse', 'urllib.parse'),
]
for attr in _urllib_parse_moved_attributes:
setattr(Module_six_moves_urllib_parse, attr.name, attr)
@ -375,8 +380,10 @@ del attr
Module_six_moves_urllib_parse._moved_attributes = _urllib_parse_moved_attributes
_importer._add_module(Module_six_moves_urllib_parse(__name__ + ".moves.urllib_parse"),
"moves.urllib_parse", "moves.urllib.parse")
_importer._add_module(
Module_six_moves_urllib_parse(__name__ + '.moves.urllib_parse'),
'moves.urllib_parse', 'moves.urllib.parse',
)
class Module_six_moves_urllib_error(_LazyModule):
@ -385,9 +392,9 @@ class Module_six_moves_urllib_error(_LazyModule):
_urllib_error_moved_attributes = [
MovedAttribute("URLError", "urllib2", "urllib.error"),
MovedAttribute("HTTPError", "urllib2", "urllib.error"),
MovedAttribute("ContentTooShortError", "urllib", "urllib.error"),
MovedAttribute('URLError', 'urllib2', 'urllib.error'),
MovedAttribute('HTTPError', 'urllib2', 'urllib.error'),
MovedAttribute('ContentTooShortError', 'urllib', 'urllib.error'),
]
for attr in _urllib_error_moved_attributes:
setattr(Module_six_moves_urllib_error, attr.name, attr)
@ -395,8 +402,10 @@ del attr
Module_six_moves_urllib_error._moved_attributes = _urllib_error_moved_attributes
_importer._add_module(Module_six_moves_urllib_error(__name__ + ".moves.urllib.error"),
"moves.urllib_error", "moves.urllib.error")
_importer._add_module(
Module_six_moves_urllib_error(__name__ + '.moves.urllib.error'),
'moves.urllib_error', 'moves.urllib.error',
)
class Module_six_moves_urllib_request(_LazyModule):
@ -405,41 +414,41 @@ class Module_six_moves_urllib_request(_LazyModule):
_urllib_request_moved_attributes = [
MovedAttribute("urlopen", "urllib2", "urllib.request"),
MovedAttribute("install_opener", "urllib2", "urllib.request"),
MovedAttribute("build_opener", "urllib2", "urllib.request"),
MovedAttribute("pathname2url", "urllib", "urllib.request"),
MovedAttribute("url2pathname", "urllib", "urllib.request"),
MovedAttribute("getproxies", "urllib", "urllib.request"),
MovedAttribute("Request", "urllib2", "urllib.request"),
MovedAttribute("OpenerDirector", "urllib2", "urllib.request"),
MovedAttribute("HTTPDefaultErrorHandler", "urllib2", "urllib.request"),
MovedAttribute("HTTPRedirectHandler", "urllib2", "urllib.request"),
MovedAttribute("HTTPCookieProcessor", "urllib2", "urllib.request"),
MovedAttribute("ProxyHandler", "urllib2", "urllib.request"),
MovedAttribute("BaseHandler", "urllib2", "urllib.request"),
MovedAttribute("HTTPPasswordMgr", "urllib2", "urllib.request"),
MovedAttribute("HTTPPasswordMgrWithDefaultRealm", "urllib2", "urllib.request"),
MovedAttribute("AbstractBasicAuthHandler", "urllib2", "urllib.request"),
MovedAttribute("HTTPBasicAuthHandler", "urllib2", "urllib.request"),
MovedAttribute("ProxyBasicAuthHandler", "urllib2", "urllib.request"),
MovedAttribute("AbstractDigestAuthHandler", "urllib2", "urllib.request"),
MovedAttribute("HTTPDigestAuthHandler", "urllib2", "urllib.request"),
MovedAttribute("ProxyDigestAuthHandler", "urllib2", "urllib.request"),
MovedAttribute("HTTPHandler", "urllib2", "urllib.request"),
MovedAttribute("HTTPSHandler", "urllib2", "urllib.request"),
MovedAttribute("FileHandler", "urllib2", "urllib.request"),
MovedAttribute("FTPHandler", "urllib2", "urllib.request"),
MovedAttribute("CacheFTPHandler", "urllib2", "urllib.request"),
MovedAttribute("UnknownHandler", "urllib2", "urllib.request"),
MovedAttribute("HTTPErrorProcessor", "urllib2", "urllib.request"),
MovedAttribute("urlretrieve", "urllib", "urllib.request"),
MovedAttribute("urlcleanup", "urllib", "urllib.request"),
MovedAttribute("URLopener", "urllib", "urllib.request"),
MovedAttribute("FancyURLopener", "urllib", "urllib.request"),
MovedAttribute("proxy_bypass", "urllib", "urllib.request"),
MovedAttribute("parse_http_list", "urllib2", "urllib.request"),
MovedAttribute("parse_keqv_list", "urllib2", "urllib.request"),
MovedAttribute('urlopen', 'urllib2', 'urllib.request'),
MovedAttribute('install_opener', 'urllib2', 'urllib.request'),
MovedAttribute('build_opener', 'urllib2', 'urllib.request'),
MovedAttribute('pathname2url', 'urllib', 'urllib.request'),
MovedAttribute('url2pathname', 'urllib', 'urllib.request'),
MovedAttribute('getproxies', 'urllib', 'urllib.request'),
MovedAttribute('Request', 'urllib2', 'urllib.request'),
MovedAttribute('OpenerDirector', 'urllib2', 'urllib.request'),
MovedAttribute('HTTPDefaultErrorHandler', 'urllib2', 'urllib.request'),
MovedAttribute('HTTPRedirectHandler', 'urllib2', 'urllib.request'),
MovedAttribute('HTTPCookieProcessor', 'urllib2', 'urllib.request'),
MovedAttribute('ProxyHandler', 'urllib2', 'urllib.request'),
MovedAttribute('BaseHandler', 'urllib2', 'urllib.request'),
MovedAttribute('HTTPPasswordMgr', 'urllib2', 'urllib.request'),
MovedAttribute('HTTPPasswordMgrWithDefaultRealm', 'urllib2', 'urllib.request'),
MovedAttribute('AbstractBasicAuthHandler', 'urllib2', 'urllib.request'),
MovedAttribute('HTTPBasicAuthHandler', 'urllib2', 'urllib.request'),
MovedAttribute('ProxyBasicAuthHandler', 'urllib2', 'urllib.request'),
MovedAttribute('AbstractDigestAuthHandler', 'urllib2', 'urllib.request'),
MovedAttribute('HTTPDigestAuthHandler', 'urllib2', 'urllib.request'),
MovedAttribute('ProxyDigestAuthHandler', 'urllib2', 'urllib.request'),
MovedAttribute('HTTPHandler', 'urllib2', 'urllib.request'),
MovedAttribute('HTTPSHandler', 'urllib2', 'urllib.request'),
MovedAttribute('FileHandler', 'urllib2', 'urllib.request'),
MovedAttribute('FTPHandler', 'urllib2', 'urllib.request'),
MovedAttribute('CacheFTPHandler', 'urllib2', 'urllib.request'),
MovedAttribute('UnknownHandler', 'urllib2', 'urllib.request'),
MovedAttribute('HTTPErrorProcessor', 'urllib2', 'urllib.request'),
MovedAttribute('urlretrieve', 'urllib', 'urllib.request'),
MovedAttribute('urlcleanup', 'urllib', 'urllib.request'),
MovedAttribute('URLopener', 'urllib', 'urllib.request'),
MovedAttribute('FancyURLopener', 'urllib', 'urllib.request'),
MovedAttribute('proxy_bypass', 'urllib', 'urllib.request'),
MovedAttribute('parse_http_list', 'urllib2', 'urllib.request'),
MovedAttribute('parse_keqv_list', 'urllib2', 'urllib.request'),
]
for attr in _urllib_request_moved_attributes:
setattr(Module_six_moves_urllib_request, attr.name, attr)
@ -447,8 +456,10 @@ del attr
Module_six_moves_urllib_request._moved_attributes = _urllib_request_moved_attributes
_importer._add_module(Module_six_moves_urllib_request(__name__ + ".moves.urllib.request"),
"moves.urllib_request", "moves.urllib.request")
_importer._add_module(
Module_six_moves_urllib_request(__name__ + '.moves.urllib.request'),
'moves.urllib_request', 'moves.urllib.request',
)
class Module_six_moves_urllib_response(_LazyModule):
@ -457,10 +468,10 @@ class Module_six_moves_urllib_response(_LazyModule):
_urllib_response_moved_attributes = [
MovedAttribute("addbase", "urllib", "urllib.response"),
MovedAttribute("addclosehook", "urllib", "urllib.response"),
MovedAttribute("addinfo", "urllib", "urllib.response"),
MovedAttribute("addinfourl", "urllib", "urllib.response"),
MovedAttribute('addbase', 'urllib', 'urllib.response'),
MovedAttribute('addclosehook', 'urllib', 'urllib.response'),
MovedAttribute('addinfo', 'urllib', 'urllib.response'),
MovedAttribute('addinfourl', 'urllib', 'urllib.response'),
]
for attr in _urllib_response_moved_attributes:
setattr(Module_six_moves_urllib_response, attr.name, attr)
@ -468,8 +479,10 @@ del attr
Module_six_moves_urllib_response._moved_attributes = _urllib_response_moved_attributes
_importer._add_module(Module_six_moves_urllib_response(__name__ + ".moves.urllib.response"),
"moves.urllib_response", "moves.urllib.response")
_importer._add_module(
Module_six_moves_urllib_response(__name__ + '.moves.urllib.response'),
'moves.urllib_response', 'moves.urllib.response',
)
class Module_six_moves_urllib_robotparser(_LazyModule):
@ -478,7 +491,7 @@ class Module_six_moves_urllib_robotparser(_LazyModule):
_urllib_robotparser_moved_attributes = [
MovedAttribute("RobotFileParser", "robotparser", "urllib.robotparser"),
MovedAttribute('RobotFileParser', 'robotparser', 'urllib.robotparser'),
]
for attr in _urllib_robotparser_moved_attributes:
setattr(Module_six_moves_urllib_robotparser, attr.name, attr)
@ -486,25 +499,30 @@ del attr
Module_six_moves_urllib_robotparser._moved_attributes = _urllib_robotparser_moved_attributes
_importer._add_module(Module_six_moves_urllib_robotparser(__name__ + ".moves.urllib.robotparser"),
"moves.urllib_robotparser", "moves.urllib.robotparser")
_importer._add_module(
Module_six_moves_urllib_robotparser(__name__ + '.moves.urllib.robotparser'),
'moves.urllib_robotparser', 'moves.urllib.robotparser',
)
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")
error = _importer._get_module("moves.urllib_error")
request = _importer._get_module("moves.urllib_request")
response = _importer._get_module("moves.urllib_response")
robotparser = _importer._get_module("moves.urllib_robotparser")
parse = _importer._get_module('moves.urllib_parse')
error = _importer._get_module('moves.urllib_error')
request = _importer._get_module('moves.urllib_request')
response = _importer._get_module('moves.urllib_response')
robotparser = _importer._get_module('moves.urllib_robotparser')
def __dir__(self):
return ['parse', 'error', 'request', 'response', 'robotparser']
_importer._add_module(Module_six_moves_urllib(__name__ + ".moves.urllib"),
"moves.urllib")
_importer._add_module(
Module_six_moves_urllib(__name__ + '.moves.urllib'),
'moves.urllib',
)
def add_move(move):
@ -520,25 +538,25 @@ def remove_move(name):
try:
del moves.__dict__[name]
except KeyError:
raise AttributeError("no such move, %r" % (name,))
raise AttributeError('no such move, {!r}'.format(name))
if PY3:
_meth_func = "__func__"
_meth_self = "__self__"
_meth_func = '__func__'
_meth_self = '__self__'
_func_closure = "__closure__"
_func_code = "__code__"
_func_defaults = "__defaults__"
_func_globals = "__globals__"
_func_closure = '__closure__'
_func_code = '__code__'
_func_defaults = '__defaults__'
_func_globals = '__globals__'
else:
_meth_func = "im_func"
_meth_self = "im_self"
_meth_func = 'im_func'
_meth_self = 'im_self'
_func_closure = "func_closure"
_func_code = "func_code"
_func_defaults = "func_defaults"
_func_globals = "func_globals"
_func_closure = 'func_closure'
_func_code = 'func_code'
_func_defaults = 'func_defaults'
_func_globals = 'func_globals'
try:
@ -553,7 +571,7 @@ try:
callable = callable
except NameError:
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:
@ -576,14 +594,16 @@ else:
def create_unbound_method(func, cls):
return types.MethodType(func, None, cls)
class Iterator(object):
class Iterator:
def next(self):
return type(self).__next__(self)
callable = callable
_add_doc(get_unbound_function,
"""Get the function out of a possibly unbound function""")
_add_doc(
get_unbound_function,
"""Get the function out of a possibly unbound function""",
)
get_method_function = operator.attrgetter(_meth_func)
@ -607,11 +627,11 @@ if PY3:
def iterlists(d, **kw):
return iter(d.lists(**kw))
viewkeys = operator.methodcaller("keys")
viewkeys = operator.methodcaller('keys')
viewvalues = operator.methodcaller("values")
viewvalues = operator.methodcaller('values')
viewitems = operator.methodcaller("items")
viewitems = operator.methodcaller('items')
else:
def iterkeys(d, **kw):
return d.iterkeys(**kw)
@ -625,29 +645,33 @@ else:
def iterlists(d, **kw):
return d.iterlists(**kw)
viewkeys = operator.methodcaller("viewkeys")
viewkeys = operator.methodcaller('viewkeys')
viewvalues = operator.methodcaller("viewvalues")
viewvalues = operator.methodcaller('viewvalues')
viewitems = operator.methodcaller("viewitems")
viewitems = operator.methodcaller('viewitems')
_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(iteritems,
"Return an iterator over the (key, value) pairs of a dictionary.")
_add_doc(iterlists,
"Return an iterator over the (key, [values]) pairs 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(
iteritems,
'Return an iterator over the (key, value) pairs of a dictionary.',
)
_add_doc(
iterlists,
'Return an iterator over the (key, [values]) pairs of a dictionary.',
)
if PY3:
def b(s):
return s.encode("latin-1")
return s.encode('latin-1')
def u(s):
return s
unichr = chr
import struct
int2byte = struct.Struct(">B").pack
int2byte = struct.Struct('>B').pack
del struct
byte2int = operator.itemgetter(0)
indexbytes = operator.getitem
@ -656,22 +680,22 @@ if PY3:
StringIO = io.StringIO
BytesIO = io.BytesIO
del io
_assertCountEqual = "assertCountEqual"
_assertCountEqual = 'assertCountEqual'
if sys.version_info[1] <= 1:
_assertRaisesRegex = "assertRaisesRegexp"
_assertRegex = "assertRegexpMatches"
_assertNotRegex = "assertNotRegexpMatches"
_assertRaisesRegex = 'assertRaisesRegexp'
_assertRegex = 'assertRegexpMatches'
_assertNotRegex = 'assertNotRegexpMatches'
else:
_assertRaisesRegex = "assertRaisesRegex"
_assertRegex = "assertRegex"
_assertNotRegex = "assertNotRegex"
_assertRaisesRegex = 'assertRaisesRegex'
_assertRegex = 'assertRegex'
_assertNotRegex = 'assertNotRegex'
else:
def b(s):
return s
# Workaround for standalone backslash
def u(s):
return unicode(s.replace(r'\\', r'\\\\'), "unicode_escape")
return unicode(s.replace(r'\\', r'\\\\'), 'unicode_escape')
unichr = unichr
int2byte = chr
@ -683,10 +707,10 @@ else:
iterbytes = functools.partial(itertools.imap, ord)
import StringIO
StringIO = BytesIO = StringIO.StringIO
_assertCountEqual = "assertItemsEqual"
_assertRaisesRegex = "assertRaisesRegexp"
_assertRegex = "assertRegexpMatches"
_assertNotRegex = "assertNotRegexpMatches"
_assertCountEqual = 'assertItemsEqual'
_assertRaisesRegex = 'assertRaisesRegexp'
_assertRegex = 'assertRegexpMatches'
_assertNotRegex = 'assertNotRegexpMatches'
_add_doc(b, """Byte literal""")
_add_doc(u, """Text literal""")
@ -708,7 +732,7 @@ def assertNotRegex(self, *args, **kwargs):
if PY3:
exec_ = getattr(moves.builtins, "exec")
exec_ = getattr(moves.builtins, 'exec')
def reraise(tp, value, tb=None):
try:
@ -754,11 +778,11 @@ else:
raise value
print_ = getattr(moves.builtins, "print", None)
print_ = getattr(moves.builtins, 'print', None)
if print_ is None:
def print_(*args, **kwargs):
"""The new-style print function for Python 2.4 and 2.5."""
fp = kwargs.pop("file", sys.stdout)
fp = kwargs.pop('file', sys.stdout)
if fp is None:
return
@ -766,40 +790,42 @@ if print_ is None:
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):
errors = getattr(fp, "errors", None)
if (
isinstance(fp, file) and
isinstance(data, unicode) and
fp.encoding is not None
):
errors = getattr(fp, 'errors', None)
if errors is None:
errors = "strict"
errors = 'strict'
data = data.encode(fp.encoding, errors)
fp.write(data)
want_unicode = False
sep = kwargs.pop("sep", None)
sep = kwargs.pop('sep', None)
if sep is not None:
if isinstance(sep, unicode):
want_unicode = True
elif not isinstance(sep, str):
raise TypeError("sep must be None or a string")
end = kwargs.pop("end", None)
raise TypeError('sep must be None or a string')
end = kwargs.pop('end', None)
if end is not None:
if isinstance(end, unicode):
want_unicode = True
elif not isinstance(end, str):
raise TypeError("end must be None or a string")
raise TypeError('end must be None or a string')
if kwargs:
raise TypeError("invalid keyword arguments to print()")
raise TypeError('invalid keyword arguments to print()')
if not want_unicode:
for arg in args:
if isinstance(arg, unicode):
want_unicode = True
break
if want_unicode:
newline = unicode("\n")
space = unicode(" ")
newline = unicode('\n')
space = unicode(' ')
else:
newline = "\n"
space = " "
newline = '\n'
space = ' '
if sep is None:
sep = space
if end is None:
@ -813,8 +839,8 @@ if sys.version_info[:2] < (3, 3):
_print = print_
def print_(*args, **kwargs):
fp = kwargs.get("file", sys.stdout)
flush = kwargs.pop("flush", False)
fp = kwargs.get('file', sys.stdout)
flush = kwargs.pop('flush', False)
_print(*args, **kwargs)
if flush and fp is not None:
fp.flush()
@ -827,9 +853,11 @@ if sys.version_info[0:2] < (3, 4):
# attribute on ``wrapper`` object and it doesn't raise an error if any of
# the attributes mentioned in ``assigned`` and ``updated`` are missing on
# ``wrapped`` object.
def _update_wrapper(wrapper, wrapped,
assigned=functools.WRAPPER_ASSIGNMENTS,
updated=functools.WRAPPER_UPDATES):
def _update_wrapper(
wrapper, wrapped,
assigned=functools.WRAPPER_ASSIGNMENTS,
updated=functools.WRAPPER_UPDATES,
):
for attr in assigned:
try:
value = getattr(wrapped, attr)
@ -843,10 +871,14 @@ if sys.version_info[0:2] < (3, 4):
return wrapper
_update_wrapper.__doc__ = functools.update_wrapper.__doc__
def wraps(wrapped, assigned=functools.WRAPPER_ASSIGNMENTS,
updated=functools.WRAPPER_UPDATES):
return functools.partial(_update_wrapper, wrapped=wrapped,
assigned=assigned, updated=updated)
def wraps(
wrapped, assigned=functools.WRAPPER_ASSIGNMENTS,
updated=functools.WRAPPER_UPDATES,
):
return functools.partial(
_update_wrapper, wrapped=wrapped,
assigned=assigned, updated=updated,
)
wraps.__doc__ = functools.wraps.__doc__
else:
@ -965,9 +997,11 @@ def python_2_unicode_compatible(klass):
"""
if PY2:
if '__str__' not in klass.__dict__:
raise ValueError("@python_2_unicode_compatible cannot be applied "
"to %s because it doesn't define __str__()." %
klass.__name__)
raise ValueError(
'@python_2_unicode_compatible cannot be applied '
"to %s because it doesn't define __str__()." %
klass.__name__,
)
klass.__unicode__ = klass.__str__
klass.__str__ = lambda self: self.__unicode__().encode('utf-8')
return klass
@ -978,7 +1012,7 @@ def python_2_unicode_compatible(klass):
# Turn this module into a package.
__path__ = [] # required for PEP 302 and PEP 451
__package__ = __name__ # see PEP 366 @ReservedAssignment
if globals().get("__spec__") is not None:
if globals().get('__spec__') is not None:
__spec__.submodule_search_locations = [] # PEP 451 @UndefinedVariable
# Remove other six meta path importers, since they cause problems. This can
# happen if six is removed from sys.modules and then reloaded. (Setuptools does
@ -989,8 +1023,10 @@ if sys.meta_path:
# be floating around. Therefore, we can't use isinstance() to check for
# 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__):
if (
type(importer).__name__ == '_SixMetaPathImporter' and
importer.name == __name__
):
del sys.meta_path[i]
break
del i, importer