diff options
author | monster <monster@ydb.tech> | 2022-07-07 14:41:37 +0300 |
---|---|---|
committer | monster <monster@ydb.tech> | 2022-07-07 14:41:37 +0300 |
commit | 06e5c21a835c0e923506c4ff27929f34e00761c2 (patch) | |
tree | 75efcbc6854ef9bd476eb8bf00cc5c900da436a2 /contrib/python/six | |
parent | 03f024c4412e3aa613bb543cf1660176320ba8f4 (diff) | |
download | ydb-06e5c21a835c0e923506c4ff27929f34e00761c2.tar.gz |
fix ya.make
Diffstat (limited to 'contrib/python/six')
-rw-r--r-- | contrib/python/six/.dist-info/METADATA | 49 | ||||
-rw-r--r-- | contrib/python/six/.dist-info/top_level.txt | 1 | ||||
-rw-r--r-- | contrib/python/six/.yandex_meta/yamaker.yaml | 2 | ||||
-rw-r--r-- | contrib/python/six/LICENSE | 18 | ||||
-rw-r--r-- | contrib/python/six/README.rst | 29 | ||||
-rw-r--r-- | contrib/python/six/patches/01-arcadia.patch | 11 | ||||
-rw-r--r-- | contrib/python/six/six.py | 998 | ||||
-rw-r--r-- | contrib/python/six/tests/test_six.py | 1041 |
8 files changed, 0 insertions, 2149 deletions
diff --git a/contrib/python/six/.dist-info/METADATA b/contrib/python/six/.dist-info/METADATA deleted file mode 100644 index 6d7525c2eb..0000000000 --- a/contrib/python/six/.dist-info/METADATA +++ /dev/null @@ -1,49 +0,0 @@ -Metadata-Version: 2.1 -Name: six -Version: 1.16.0 -Summary: Python 2 and 3 compatibility utilities -Home-page: https://github.com/benjaminp/six -Author: Benjamin Peterson -Author-email: benjamin@python.org -License: MIT -Platform: UNKNOWN -Classifier: Development Status :: 5 - Production/Stable -Classifier: Programming Language :: Python :: 2 -Classifier: Programming Language :: Python :: 3 -Classifier: Intended Audience :: Developers -Classifier: License :: OSI Approved :: MIT License -Classifier: Topic :: Software Development :: Libraries -Classifier: Topic :: Utilities -Requires-Python: >=2.7, !=3.0.*, !=3.1.*, !=3.2.* - -.. image:: https://img.shields.io/pypi/v/six.svg - :target: https://pypi.org/project/six/ - :alt: six on PyPI - -.. image:: https://travis-ci.org/benjaminp/six.svg?branch=master - :target: https://travis-ci.org/benjaminp/six - :alt: six on TravisCI - -.. image:: https://readthedocs.org/projects/six/badge/?version=latest - :target: https://six.readthedocs.io/ - :alt: six's documentation on Read the Docs - -.. image:: https://img.shields.io/badge/license-MIT-green.svg - :target: https://github.com/benjaminp/six/blob/master/LICENSE - :alt: MIT License badge - -Six is a Python 2 and 3 compatibility library. It provides utility functions -for smoothing over the differences between the Python versions with the goal of -writing Python code that is compatible on both Python versions. See the -documentation for more information on what is provided. - -Six supports Python 2.7 and 3.3+. It is contained in only one Python -file, so it can be easily copied into your project. (The copyright and license -notice must be retained.) - -Online documentation is at https://six.readthedocs.io/. - -Bugs can be reported to https://github.com/benjaminp/six. The code can also -be found there. - - diff --git a/contrib/python/six/.dist-info/top_level.txt b/contrib/python/six/.dist-info/top_level.txt deleted file mode 100644 index ffe2fce498..0000000000 --- a/contrib/python/six/.dist-info/top_level.txt +++ /dev/null @@ -1 +0,0 @@ -six diff --git a/contrib/python/six/.yandex_meta/yamaker.yaml b/contrib/python/six/.yandex_meta/yamaker.yaml deleted file mode 100644 index 2502bc85b9..0000000000 --- a/contrib/python/six/.yandex_meta/yamaker.yaml +++ /dev/null @@ -1,2 +0,0 @@ -keep: -- tests/test_six.py diff --git a/contrib/python/six/LICENSE b/contrib/python/six/LICENSE deleted file mode 100644 index de6633112c..0000000000 --- a/contrib/python/six/LICENSE +++ /dev/null @@ -1,18 +0,0 @@ -Copyright (c) 2010-2020 Benjamin Peterson - -Permission is hereby granted, free of charge, to any person obtaining a copy of -this software and associated documentation files (the "Software"), to deal in -the Software without restriction, including without limitation the rights to -use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of -the Software, and to permit persons to whom the Software is furnished to do so, -subject to the following conditions: - -The above copyright notice and this permission notice shall be included in all -copies or substantial portions of the Software. - -THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS -FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR -COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 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. diff --git a/contrib/python/six/README.rst b/contrib/python/six/README.rst deleted file mode 100644 index 6339ba5d93..0000000000 --- a/contrib/python/six/README.rst +++ /dev/null @@ -1,29 +0,0 @@ -.. image:: https://img.shields.io/pypi/v/six.svg - :target: https://pypi.org/project/six/ - :alt: six on PyPI - -.. image:: https://travis-ci.org/benjaminp/six.svg?branch=master - :target: https://travis-ci.org/benjaminp/six - :alt: six on TravisCI - -.. image:: https://readthedocs.org/projects/six/badge/?version=latest - :target: https://six.readthedocs.io/ - :alt: six's documentation on Read the Docs - -.. image:: https://img.shields.io/badge/license-MIT-green.svg - :target: https://github.com/benjaminp/six/blob/master/LICENSE - :alt: MIT License badge - -Six is a Python 2 and 3 compatibility library. It provides utility functions -for smoothing over the differences between the Python versions with the goal of -writing Python code that is compatible on both Python versions. See the -documentation for more information on what is provided. - -Six supports Python 2.7 and 3.3+. It is contained in only one Python -file, so it can be easily copied into your project. (The copyright and license -notice must be retained.) - -Online documentation is at https://six.readthedocs.io/. - -Bugs can be reported to https://github.com/benjaminp/six. The code can also -be found there. diff --git a/contrib/python/six/patches/01-arcadia.patch b/contrib/python/six/patches/01-arcadia.patch deleted file mode 100644 index 57f85cb6d9..0000000000 --- a/contrib/python/six/patches/01-arcadia.patch +++ /dev/null @@ -1,11 +0,0 @@ ---- contrib/python/six/six.py (index) -+++ contrib/python/six/six.py (working tree) -@@ -274,7 +274,7 @@ _moved_attributes = [ - 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("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"), diff --git a/contrib/python/six/six.py b/contrib/python/six/six.py deleted file mode 100644 index 4cba03c75f..0000000000 --- a/contrib/python/six/six.py +++ /dev/null @@ -1,998 +0,0 @@ -# Copyright (c) 2010-2020 Benjamin Peterson -# -# Permission is hereby granted, free of charge, to any person obtaining a copy -# of this software and associated documentation files (the "Software"), to deal -# in the Software without restriction, including without limitation the rights -# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell -# copies of the Software, and to permit persons to whom the Software is -# furnished to do so, subject to the following conditions: -# -# The above copyright notice and this permission notice shall be included in all -# copies or substantial portions of the Software. -# -# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE -# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER -# 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 - -import functools -import itertools -import operator -import sys -import types - -__author__ = "Benjamin Peterson <benjamin@python.org>" -__version__ = "1.16.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, - integer_types = int, - class_types = type, - text_type = str - binary_type = bytes - - MAXSIZE = sys.maxsize -else: - string_types = basestring, - integer_types = (int, long) - class_types = (type, types.ClassType) - text_type = unicode - binary_type = str - - 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): - - 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 - -if PY34: - from importlib.util import spec_from_loader -else: - spec_from_loader = None - - -def _add_doc(func, doc): - """Add documentation to a function.""" - func.__doc__ = doc - - -def _import_module(name): - """Import module, returning the module after the last dot.""" - __import__(name) - return sys.modules[name] - - -class _LazyDescr(object): - - def __init__(self, name): - self.name = name - - def __get__(self, obj, tp): - result = self._resolve() - setattr(obj, self.name, result) # Invokes __set__. - try: - # This is a bit ugly, but it avoids running this again by - # removing this descriptor. - delattr(obj.__class__, self.name) - except AttributeError: - pass - return result - - -class MovedModule(_LazyDescr): - - def __init__(self, name, old, new=None): - super(MovedModule, self).__init__(name) - if PY3: - if new is None: - new = name - self.mod = new - else: - self.mod = old - - def _resolve(self): - return _import_module(self.mod) - - def __getattr__(self, attr): - _module = self._resolve() - value = getattr(_module, attr) - setattr(self, attr, value) - return value - - -class _LazyModule(types.ModuleType): - - def __init__(self, name): - super(_LazyModule, self).__init__(name) - self.__doc__ = self.__class__.__doc__ - - def __dir__(self): - attrs = ["__doc__", "__name__"] - attrs += [attr.name for attr in self._moved_attributes] - return attrs - - # Subclasses should override this - _moved_attributes = [] - - -class MovedAttribute(_LazyDescr): - - def __init__(self, name, old_mod, new_mod, old_attr=None, new_attr=None): - super(MovedAttribute, self).__init__(name) - if PY3: - if new_mod is None: - new_mod = name - self.mod = new_mod - if new_attr is None: - if old_attr is None: - new_attr = name - else: - new_attr = old_attr - self.attr = new_attr - else: - self.mod = old_mod - if old_attr is None: - old_attr = name - self.attr = old_attr - - def _resolve(self): - module = _import_module(self.mod) - return getattr(module, self.attr) - - -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 = {} - - def _add_module(self, mod, *fullnames): - for fullname in fullnames: - self.known_modules[self.name + "." + fullname] = mod - - def _get_module(self, fullname): - return self.known_modules[self.name + "." + fullname] - - def find_module(self, fullname, path=None): - if fullname in self.known_modules: - return self - return None - - def find_spec(self, fullname, path, target=None): - if fullname in self.known_modules: - return spec_from_loader(fullname, self) - return None - - def __get_module(self, fullname): - try: - return self.known_modules[fullname] - except KeyError: - raise ImportError("This loader does not know module " + fullname) - - def load_module(self, fullname): - try: - # in case of a reload - return sys.modules[fullname] - except KeyError: - pass - mod = self.__get_module(fullname) - if isinstance(mod, MovedModule): - mod = mod._resolve() - else: - mod.__loader__ = self - sys.modules[fullname] = mod - return mod - - def is_package(self, fullname): - """ - Return true, if the named module is a package. - - We need this method to get correct spec objects with - Python 3.4 (see PEP451) - """ - return hasattr(self.__get_module(fullname), "__path__") - - def get_code(self, fullname): - """Return None - - Required, if is_package is implemented""" - self.__get_module(fullname) # eventually raises ImportError - return None - get_source = get_code # same as get_code - - def create_module(self, spec): - return self.load_module(spec.name) - - def exec_module(self, module): - pass - -_importer = _SixMetaPathImporter(__name__) - - -class _MovedItems(_LazyModule): - - """Lazy loading of moved objects""" - __path__ = [] # mark as package - - -_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"), -] -# 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): - _importer._add_module(attr, "moves." + attr.name) -del attr - -_MovedItems._moved_attributes = _moved_attributes - -moves = _MovedItems(__name__ + ".moves") -_importer._add_module(moves, "moves") - - -class Module_six_moves_urllib_parse(_LazyModule): - - """Lazy loading of moved objects in six.moves.urllib_parse""" - - -_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"), -] -for attr in _urllib_parse_moved_attributes: - setattr(Module_six_moves_urllib_parse, attr.name, attr) -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") - - -class Module_six_moves_urllib_error(_LazyModule): - - """Lazy loading of moved objects in six.moves.urllib_error""" - - -_urllib_error_moved_attributes = [ - 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) -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") - - -class Module_six_moves_urllib_request(_LazyModule): - - """Lazy loading of moved objects in six.moves.urllib_request""" - - -_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"), -] -for attr in _urllib_request_moved_attributes: - setattr(Module_six_moves_urllib_request, attr.name, attr) -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") - - -class Module_six_moves_urllib_response(_LazyModule): - - """Lazy loading of moved objects in six.moves.urllib_response""" - - -_urllib_response_moved_attributes = [ - 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) -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") - - -class Module_six_moves_urllib_robotparser(_LazyModule): - - """Lazy loading of moved objects in six.moves.urllib_robotparser""" - - -_urllib_robotparser_moved_attributes = [ - MovedAttribute("RobotFileParser", "robotparser", "urllib.robotparser"), -] -for attr in _urllib_robotparser_moved_attributes: - setattr(Module_six_moves_urllib_robotparser, attr.name, attr) -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") - - -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") - - def __dir__(self): - return ['parse', 'error', 'request', 'response', 'robotparser'] - -_importer._add_module(Module_six_moves_urllib(__name__ + ".moves.urllib"), - "moves.urllib") - - -def add_move(move): - """Add an item to six.moves.""" - setattr(_MovedItems, move.name, move) - - -def remove_move(name): - """Remove item from six.moves.""" - try: - delattr(_MovedItems, name) - except AttributeError: - try: - del moves.__dict__[name] - except KeyError: - raise AttributeError("no such move, %r" % (name,)) - - -if PY3: - _meth_func = "__func__" - _meth_self = "__self__" - - _func_closure = "__closure__" - _func_code = "__code__" - _func_defaults = "__defaults__" - _func_globals = "__globals__" -else: - _meth_func = "im_func" - _meth_self = "im_self" - - _func_closure = "func_closure" - _func_code = "func_code" - _func_defaults = "func_defaults" - _func_globals = "func_globals" - - -try: - advance_iterator = next -except NameError: - def advance_iterator(it): - return it.next() -next = advance_iterator - - -try: - callable = callable -except NameError: - def callable(obj): - return any("__call__" in klass.__dict__ for klass in type(obj).__mro__) - - -if PY3: - def get_unbound_function(unbound): - return unbound - - create_bound_method = types.MethodType - - def create_unbound_method(func, cls): - return func - - Iterator = object -else: - def get_unbound_function(unbound): - return unbound.im_func - - 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): - return type(self).__next__(self) - - callable = callable -_add_doc(get_unbound_function, - """Get the function out of a possibly unbound function""") - - -get_method_function = operator.attrgetter(_meth_func) -get_method_self = operator.attrgetter(_meth_self) -get_function_closure = operator.attrgetter(_func_closure) -get_function_code = operator.attrgetter(_func_code) -get_function_defaults = operator.attrgetter(_func_defaults) -get_function_globals = operator.attrgetter(_func_globals) - - -if PY3: - def iterkeys(d, **kw): - return iter(d.keys(**kw)) - - def itervalues(d, **kw): - return iter(d.values(**kw)) - - def iteritems(d, **kw): - return iter(d.items(**kw)) - - def iterlists(d, **kw): - return iter(d.lists(**kw)) - - viewkeys = operator.methodcaller("keys") - - viewvalues = operator.methodcaller("values") - - viewitems = operator.methodcaller("items") -else: - def iterkeys(d, **kw): - return d.iterkeys(**kw) - - def itervalues(d, **kw): - return d.itervalues(**kw) - - def iteritems(d, **kw): - return d.iteritems(**kw) - - def iterlists(d, **kw): - return d.iterlists(**kw) - - viewkeys = operator.methodcaller("viewkeys") - - viewvalues = operator.methodcaller("viewvalues") - - 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.") - - -if PY3: - def b(s): - return s.encode("latin-1") - - def u(s): - return s - unichr = chr - 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 - del io - _assertCountEqual = "assertCountEqual" - if sys.version_info[1] <= 1: - _assertRaisesRegex = "assertRaisesRegexp" - _assertRegex = "assertRegexpMatches" - _assertNotRegex = "assertNotRegexpMatches" - else: - _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") - 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) - import StringIO - StringIO = BytesIO = StringIO.StringIO - _assertCountEqual = "assertItemsEqual" - _assertRaisesRegex = "assertRaisesRegexp" - _assertRegex = "assertRegexpMatches" - _assertNotRegex = "assertNotRegexpMatches" -_add_doc(b, """Byte literal""") -_add_doc(u, """Text literal""") - - -def assertCountEqual(self, *args, **kwargs): - return getattr(self, _assertCountEqual)(*args, **kwargs) - - -def assertRaisesRegex(self, *args, **kwargs): - return getattr(self, _assertRaisesRegex)(*args, **kwargs) - - -def assertRegex(self, *args, **kwargs): - return getattr(self, _assertRegex)(*args, **kwargs) - - -def assertNotRegex(self, *args, **kwargs): - return getattr(self, _assertNotRegex)(*args, **kwargs) - - -if PY3: - exec_ = getattr(moves.builtins, "exec") - - def reraise(tp, value, tb=None): - try: - if value is None: - value = tp() - if value.__traceback__ is not tb: - raise value.with_traceback(tb) - raise value - finally: - value = None - tb = None - -else: - def exec_(_code_, _globs_=None, _locs_=None): - """Execute code in a namespace.""" - if _globs_ is None: - frame = sys._getframe(1) - _globs_ = frame.f_globals - if _locs_ is None: - _locs_ = frame.f_locals - del frame - elif _locs_ is None: - _locs_ = _globs_ - exec("""exec _code_ in _globs_, _locs_""") - - exec_("""def reraise(tp, value, tb=None): - try: - raise tp, value, tb - finally: - tb = None -""") - - -if sys.version_info[:2] > (3,): - exec_("""def raise_from(value, from_value): - try: - raise value from from_value - finally: - value = None -""") -else: - def raise_from(value, from_value): - raise value - - -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) - 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): - errors = getattr(fp, "errors", None) - if errors is None: - errors = "strict" - data = data.encode(fp.encoding, errors) - fp.write(data) - want_unicode = False - 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) - 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") - if kwargs: - 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(" ") - else: - newline = "\n" - space = " " - if sep is None: - sep = space - if end is None: - end = newline - for i, arg in enumerate(args): - if i: - write(sep) - write(arg) - 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) - _print(*args, **kwargs) - if flush and fp is not None: - fp.flush() - -_add_doc(reraise, """Reraise an exception.""") - -if sys.version_info[0:2] < (3, 4): - # This does exactly the same what the :func:`py3:functools.update_wrapper` - # function does on Python versions after 3.2. It sets the ``__wrapped__`` - # 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): - for attr in assigned: - try: - value = getattr(wrapped, attr) - except AttributeError: - continue - else: - setattr(wrapper, attr, value) - for attr in updated: - getattr(wrapper, attr).update(getattr(wrapped, attr, {})) - wrapper.__wrapped__ = wrapped - 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) - wraps.__doc__ = functools.wraps.__doc__ - -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(type): - - def __new__(cls, name, this_bases, d): - if sys.version_info[:2] >= (3, 7): - # This version introduced PEP 560 that requires a bit - # of extra care (we mimic what is done by __build_class__). - resolved_bases = types.resolve_bases(bases) - if resolved_bases is not bases: - d['__orig_bases__'] = bases - else: - resolved_bases = bases - return meta(name, resolved_bases, d) - - @classmethod - def __prepare__(cls, name, this_bases): - return meta.__prepare__(name, bases) - return type.__new__(metaclass, 'temporary_class', (), {}) - - -def add_metaclass(metaclass): - """Class decorator for creating a class with a metaclass.""" - def wrapper(cls): - orig_vars = cls.__dict__.copy() - slots = orig_vars.get('__slots__') - if slots is not None: - if isinstance(slots, str): - slots = [slots] - for slots_var in slots: - orig_vars.pop(slots_var) - orig_vars.pop('__dict__', None) - orig_vars.pop('__weakref__', None) - if hasattr(cls, '__qualname__'): - orig_vars['__qualname__'] = cls.__qualname__ - return metaclass(cls.__name__, cls.__bases__, orig_vars) - return wrapper - - -def ensure_binary(s, encoding='utf-8', errors='strict'): - """Coerce **s** to six.binary_type. - - For Python 2: - - `unicode` -> encoded to `str` - - `str` -> `str` - - For Python 3: - - `str` -> encoded to `bytes` - - `bytes` -> `bytes` - """ - if isinstance(s, binary_type): - return s - if isinstance(s, text_type): - return s.encode(encoding, errors) - raise TypeError("not expecting type '%s'" % type(s)) - - -def ensure_str(s, encoding='utf-8', errors='strict'): - """Coerce *s* to `str`. - - For Python 2: - - `unicode` -> encoded to `str` - - `str` -> `str` - - For Python 3: - - `str` -> `str` - - `bytes` -> decoded to `str` - """ - # Optimization: Fast return for the common case. - if type(s) is str: - return s - if PY2 and isinstance(s, text_type): - return s.encode(encoding, errors) - elif PY3 and isinstance(s, binary_type): - return s.decode(encoding, errors) - elif not isinstance(s, (text_type, binary_type)): - raise TypeError("not expecting type '%s'" % type(s)) - return s - - -def ensure_text(s, encoding='utf-8', errors='strict'): - """Coerce *s* to six.text_type. - - For Python 2: - - `unicode` -> `unicode` - - `str` -> `unicode` - - For Python 3: - - `str` -> `str` - - `bytes` -> decoded to `str` - """ - if isinstance(s, binary_type): - return s.decode(encoding, errors) - elif isinstance(s, text_type): - return s - else: - raise TypeError("not expecting type '%s'" % type(s)) - - -def python_2_unicode_compatible(klass): - """ - A class decorator that defines __unicode__ and __str__ methods under Python 2. - Under Python 3 it does nothing. - - To support Python 2 and 3 with a single code base, define a __str__ method - returning text and apply this decorator to the class. - """ - 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__) - klass.__unicode__ = klass.__str__ - klass.__str__ = lambda self: self.__unicode__().encode('utf-8') - return klass - - -# Complete the moves implementation. -# This code is at the end of this module to speed up module loading. -# 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: - __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 -# this for some reason.) -if sys.meta_path: - for i, importer in enumerate(sys.meta_path): - # Here's some real nastiness: Another "instance" of the six module might - # 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__): - del sys.meta_path[i] - break - del i, importer -# Finally, add the importer to the meta path import hook. -sys.meta_path.append(_importer) diff --git a/contrib/python/six/tests/test_six.py b/contrib/python/six/tests/test_six.py deleted file mode 100644 index 7b8b03b5e6..0000000000 --- a/contrib/python/six/tests/test_six.py +++ /dev/null @@ -1,1041 +0,0 @@ -# Copyright (c) 2010-2020 Benjamin Peterson -# -# Permission is hereby granted, free of charge, to any person obtaining a copy -# of this software and associated documentation files (the "Software"), to deal -# in the Software without restriction, including without limitation the rights -# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell -# copies of the Software, and to permit persons to whom the Software is -# furnished to do so, subject to the following conditions: -# -# The above copyright notice and this permission notice shall be included in all -# copies or substantial portions of the Software. -# -# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE -# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER -# 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. - -import operator -import sys -import types -import unittest -import abc - -import pytest - -import six - - -def test_add_doc(): - def f(): - """Icky doc""" - pass - six._add_doc(f, """New doc""") - assert f.__doc__ == "New doc" - - -def test_import_module(): - from logging import handlers - m = six._import_module("logging.handlers") - assert m is handlers - - -def test_integer_types(): - assert isinstance(1, six.integer_types) - assert isinstance(-1, six.integer_types) - assert isinstance(six.MAXSIZE + 23, six.integer_types) - assert not isinstance(.1, six.integer_types) - - -def test_string_types(): - assert isinstance("hi", six.string_types) - assert isinstance(six.u("hi"), six.string_types) - assert issubclass(six.text_type, six.string_types) - - -def test_class_types(): - class X: - pass - class Y(object): - pass - assert isinstance(X, six.class_types) - assert isinstance(Y, six.class_types) - assert not isinstance(X(), six.class_types) - - -def test_text_type(): - assert type(six.u("hi")) is six.text_type - - -def test_binary_type(): - assert type(six.b("hi")) is six.binary_type - - -def test_MAXSIZE(): - try: - # This shouldn't raise an overflow error. - six.MAXSIZE.__index__() - except AttributeError: - # Before Python 2.6. - pass - pytest.raises( - (ValueError, OverflowError), - operator.mul, [None], six.MAXSIZE + 1) - - -def test_lazy(): - if six.PY3: - html_name = "html.parser" - else: - html_name = "HTMLParser" - assert html_name not in sys.modules - mod = six.moves.html_parser - assert sys.modules[html_name] is mod - assert "htmlparser" not in six._MovedItems.__dict__ - - -try: - import _tkinter -except ImportError: - have_tkinter = False -else: - have_tkinter = True - -have_gdbm = True -try: - import gdbm -except ImportError: - try: - import dbm.gnu - except ImportError: - have_gdbm = False - -@pytest.mark.parametrize("item_name", - [item.name for item in six._moved_attributes]) -def test_move_items(item_name): - """Ensure that everything loads correctly.""" - try: - item = getattr(six.moves, item_name) - if isinstance(item, types.ModuleType): - __import__("six.moves." + item_name) - except ImportError: - if item_name == "winreg" and not sys.platform.startswith("win"): - pytest.skip("Windows only module") - if item_name.startswith("tkinter"): - if not have_tkinter: - pytest.skip("requires tkinter") - if item_name.startswith("dbm_gnu") and not have_gdbm: - pytest.skip("requires gdbm") - raise - assert item_name in dir(six.moves) - - -@pytest.mark.parametrize("item_name", - [item.name for item in six._urllib_parse_moved_attributes]) -def test_move_items_urllib_parse(item_name): - """Ensure that everything loads correctly.""" - assert item_name in dir(six.moves.urllib.parse) - getattr(six.moves.urllib.parse, item_name) - - -@pytest.mark.parametrize("item_name", - [item.name for item in six._urllib_error_moved_attributes]) -def test_move_items_urllib_error(item_name): - """Ensure that everything loads correctly.""" - assert item_name in dir(six.moves.urllib.error) - getattr(six.moves.urllib.error, item_name) - - -@pytest.mark.parametrize("item_name", - [item.name for item in six._urllib_request_moved_attributes]) -def test_move_items_urllib_request(item_name): - """Ensure that everything loads correctly.""" - assert item_name in dir(six.moves.urllib.request) - getattr(six.moves.urllib.request, item_name) - - -@pytest.mark.parametrize("item_name", - [item.name for item in six._urllib_response_moved_attributes]) -def test_move_items_urllib_response(item_name): - """Ensure that everything loads correctly.""" - assert item_name in dir(six.moves.urllib.response) - getattr(six.moves.urllib.response, item_name) - - -@pytest.mark.parametrize("item_name", - [item.name for item in six._urllib_robotparser_moved_attributes]) -def test_move_items_urllib_robotparser(item_name): - """Ensure that everything loads correctly.""" - assert item_name in dir(six.moves.urllib.robotparser) - getattr(six.moves.urllib.robotparser, item_name) - - -def test_import_moves_error_1(): - from six.moves.urllib.parse import urljoin - from six import moves - # In 1.4.1: AttributeError: 'Module_six_moves_urllib_parse' object has no attribute 'urljoin' - assert moves.urllib.parse.urljoin - - -def test_import_moves_error_2(): - from six import moves - assert moves.urllib.parse.urljoin - # In 1.4.1: ImportError: cannot import name urljoin - from six.moves.urllib.parse import urljoin - - -def test_import_moves_error_3(): - from six.moves.urllib.parse import urljoin - # In 1.4.1: ImportError: cannot import name urljoin - from six.moves.urllib_parse import urljoin - - -def test_from_imports(): - from six.moves.queue import Queue - assert isinstance(Queue, six.class_types) - from six.moves.configparser import ConfigParser - assert isinstance(ConfigParser, six.class_types) - - -def test_filter(): - from six.moves import filter - f = filter(lambda x: x % 2, range(10)) - assert six.advance_iterator(f) == 1 - - -def test_filter_false(): - from six.moves import filterfalse - f = filterfalse(lambda x: x % 3, range(10)) - assert six.advance_iterator(f) == 0 - assert six.advance_iterator(f) == 3 - assert six.advance_iterator(f) == 6 - -def test_map(): - from six.moves import map - assert six.advance_iterator(map(lambda x: x + 1, range(2))) == 1 - - -def test_getoutput(): - from six.moves import getoutput - output = getoutput('echo "foo"') - assert output == 'foo' - - -def test_zip(): - from six.moves import zip - assert six.advance_iterator(zip(range(2), range(2))) == (0, 0) - - -def test_zip_longest(): - from six.moves import zip_longest - it = zip_longest(range(2), range(1)) - - assert six.advance_iterator(it) == (0, 0) - assert six.advance_iterator(it) == (1, None) - - -class TestCustomizedMoves: - - def teardown_method(self, meth): - try: - del six._MovedItems.spam - except AttributeError: - pass - try: - del six.moves.__dict__["spam"] - except KeyError: - pass - - - def test_moved_attribute(self): - attr = six.MovedAttribute("spam", "foo", "bar") - if six.PY3: - assert attr.mod == "bar" - else: - assert attr.mod == "foo" - assert attr.attr == "spam" - attr = six.MovedAttribute("spam", "foo", "bar", "lemma") - assert attr.attr == "lemma" - attr = six.MovedAttribute("spam", "foo", "bar", "lemma", "theorm") - if six.PY3: - assert attr.attr == "theorm" - else: - assert attr.attr == "lemma" - - - def test_moved_module(self): - attr = six.MovedModule("spam", "foo") - if six.PY3: - assert attr.mod == "spam" - else: - assert attr.mod == "foo" - attr = six.MovedModule("spam", "foo", "bar") - if six.PY3: - assert attr.mod == "bar" - else: - assert attr.mod == "foo" - - - def test_custom_move_module(self): - attr = six.MovedModule("spam", "six", "six") - six.add_move(attr) - six.remove_move("spam") - assert not hasattr(six.moves, "spam") - attr = six.MovedModule("spam", "six", "six") - six.add_move(attr) - from six.moves import spam - assert spam is six - six.remove_move("spam") - assert not hasattr(six.moves, "spam") - - - def test_custom_move_attribute(self): - attr = six.MovedAttribute("spam", "six", "six", "u", "u") - six.add_move(attr) - six.remove_move("spam") - assert not hasattr(six.moves, "spam") - attr = six.MovedAttribute("spam", "six", "six", "u", "u") - six.add_move(attr) - from six.moves import spam - assert spam is six.u - six.remove_move("spam") - assert not hasattr(six.moves, "spam") - - - def test_empty_remove(self): - pytest.raises(AttributeError, six.remove_move, "eggs") - - -def test_get_unbound_function(): - class X(object): - def m(self): - pass - assert six.get_unbound_function(X.m) is X.__dict__["m"] - - -def test_get_method_self(): - class X(object): - def m(self): - pass - x = X() - assert six.get_method_self(x.m) is x - pytest.raises(AttributeError, six.get_method_self, 42) - - -def test_get_method_function(): - class X(object): - def m(self): - pass - x = X() - assert six.get_method_function(x.m) is X.__dict__["m"] - pytest.raises(AttributeError, six.get_method_function, hasattr) - - -def test_get_function_closure(): - def f(): - x = 42 - def g(): - return x - return g - cell = six.get_function_closure(f())[0] - assert type(cell).__name__ == "cell" - - -def test_get_function_code(): - def f(): - pass - assert isinstance(six.get_function_code(f), types.CodeType) - if not hasattr(sys, "pypy_version_info"): - pytest.raises(AttributeError, six.get_function_code, hasattr) - - -def test_get_function_defaults(): - def f(x, y=3, b=4): - pass - assert six.get_function_defaults(f) == (3, 4) - - -def test_get_function_globals(): - def f(): - pass - assert six.get_function_globals(f) is globals() - - -def test_dictionary_iterators(monkeypatch): - def stock_method_name(iterwhat): - """Given a method suffix like "lists" or "values", return the name - of the dict method that delivers those on the version of Python - we're running in.""" - if six.PY3: - return iterwhat - return 'iter' + iterwhat - - class MyDict(dict): - if not six.PY3: - def lists(self, **kw): - return [1, 2, 3] - def iterlists(self, **kw): - return iter([1, 2, 3]) - f = MyDict.iterlists - del MyDict.iterlists - setattr(MyDict, stock_method_name('lists'), f) - - d = MyDict(zip(range(10), reversed(range(10)))) - for name in "keys", "values", "items", "lists": - meth = getattr(six, "iter" + name) - it = meth(d) - assert not isinstance(it, list) - assert list(it) == list(getattr(d, name)()) - pytest.raises(StopIteration, six.advance_iterator, it) - record = [] - def with_kw(*args, **kw): - record.append(kw["kw"]) - return old(*args) - old = getattr(MyDict, stock_method_name(name)) - monkeypatch.setattr(MyDict, stock_method_name(name), with_kw) - meth(d, kw=42) - assert record == [42] - monkeypatch.undo() - - -def test_dictionary_views(): - d = dict(zip(range(10), (range(11, 20)))) - for name in "keys", "values", "items": - meth = getattr(six, "view" + name) - view = meth(d) - assert set(view) == set(getattr(d, name)()) - - -def test_advance_iterator(): - assert six.next is six.advance_iterator - l = [1, 2] - it = iter(l) - assert six.next(it) == 1 - assert six.next(it) == 2 - pytest.raises(StopIteration, six.next, it) - pytest.raises(StopIteration, six.next, it) - - -def test_iterator(): - class myiter(six.Iterator): - def __next__(self): - return 13 - assert six.advance_iterator(myiter()) == 13 - class myitersub(myiter): - def __next__(self): - return 14 - assert six.advance_iterator(myitersub()) == 14 - - -def test_callable(): - class X: - def __call__(self): - pass - def method(self): - pass - assert six.callable(X) - assert six.callable(X()) - assert six.callable(test_callable) - assert six.callable(hasattr) - assert six.callable(X.method) - assert six.callable(X().method) - assert not six.callable(4) - assert not six.callable("string") - - -def test_create_bound_method(): - class X(object): - pass - def f(self): - return self - x = X() - b = six.create_bound_method(f, x) - assert isinstance(b, types.MethodType) - assert b() is x - - -def test_create_unbound_method(): - class X(object): - pass - - def f(self): - return self - u = six.create_unbound_method(f, X) - pytest.raises(TypeError, u) - if six.PY2: - assert isinstance(u, types.MethodType) - x = X() - assert f(x) is x - - -if six.PY3: - - def test_b(): - data = six.b("\xff") - assert isinstance(data, bytes) - assert len(data) == 1 - assert data == bytes([255]) - - - def test_u(): - s = six.u("hi \u0439 \U00000439 \\ \\\\ \n") - assert isinstance(s, str) - assert s == "hi \u0439 \U00000439 \\ \\\\ \n" - -else: - - def test_b(): - data = six.b("\xff") - assert isinstance(data, str) - assert len(data) == 1 - assert data == "\xff" - - - def test_u(): - s = six.u("hi \u0439 \U00000439 \\ \\\\ \n") - assert isinstance(s, unicode) - assert s == "hi \xd0\xb9 \xd0\xb9 \\ \\\\ \n".decode("utf8") - - -def test_u_escapes(): - s = six.u("\u1234") - assert len(s) == 1 - - -def test_unichr(): - assert six.u("\u1234") == six.unichr(0x1234) - assert type(six.u("\u1234")) is type(six.unichr(0x1234)) - - -def test_int2byte(): - assert six.int2byte(3) == six.b("\x03") - pytest.raises(Exception, six.int2byte, 256) - - -def test_byte2int(): - assert six.byte2int(six.b("\x03")) == 3 - assert six.byte2int(six.b("\x03\x04")) == 3 - pytest.raises(IndexError, six.byte2int, six.b("")) - - -def test_bytesindex(): - assert six.indexbytes(six.b("hello"), 3) == ord("l") - - -def test_bytesiter(): - it = six.iterbytes(six.b("hi")) - assert six.next(it) == ord("h") - assert six.next(it) == ord("i") - pytest.raises(StopIteration, six.next, it) - - -def test_StringIO(): - fp = six.StringIO() - fp.write(six.u("hello")) - assert fp.getvalue() == six.u("hello") - - -def test_BytesIO(): - fp = six.BytesIO() - fp.write(six.b("hello")) - assert fp.getvalue() == six.b("hello") - - -def test_exec_(): - def f(): - l = [] - six.exec_("l.append(1)") - assert l == [1] - f() - ns = {} - six.exec_("x = 42", ns) - assert ns["x"] == 42 - glob = {} - loc = {} - six.exec_("global y; y = 42; x = 12", glob, loc) - assert glob["y"] == 42 - assert "x" not in glob - assert loc["x"] == 12 - assert "y" not in loc - - -def test_reraise(): - def get_next(tb): - if six.PY3: - return tb.tb_next.tb_next - else: - return tb.tb_next - e = Exception("blah") - try: - raise e - except Exception: - tp, val, tb = sys.exc_info() - try: - six.reraise(tp, val, tb) - except Exception: - tp2, value2, tb2 = sys.exc_info() - assert tp2 is Exception - assert value2 is e - assert tb is get_next(tb2) - try: - six.reraise(tp, val) - except Exception: - tp2, value2, tb2 = sys.exc_info() - assert tp2 is Exception - assert value2 is e - assert tb2 is not tb - try: - six.reraise(tp, val, tb2) - except Exception: - tp2, value2, tb3 = sys.exc_info() - assert tp2 is Exception - assert value2 is e - assert get_next(tb3) is tb2 - try: - six.reraise(tp, None, tb) - except Exception: - tp2, value2, tb2 = sys.exc_info() - assert tp2 is Exception - assert value2 is not val - assert isinstance(value2, Exception) - assert tb is get_next(tb2) - - -def test_raise_from(): - try: - try: - raise Exception("blah") - except Exception: - ctx = sys.exc_info()[1] - f = Exception("foo") - six.raise_from(f, None) - except Exception: - tp, val, tb = sys.exc_info() - if sys.version_info[:2] > (3, 0): - # We should have done a raise f from None equivalent. - assert val.__cause__ is None - assert val.__context__ is ctx - # And that should suppress the context on the exception. - assert val.__suppress_context__ - # For all versions the outer exception should have raised successfully. - assert str(val) == "foo" - - -def test_print_(): - save = sys.stdout - out = sys.stdout = six.moves.StringIO() - try: - six.print_("Hello,", "person!") - finally: - sys.stdout = save - assert out.getvalue() == "Hello, person!\n" - out = six.StringIO() - six.print_("Hello,", "person!", file=out) - assert out.getvalue() == "Hello, person!\n" - out = six.StringIO() - six.print_("Hello,", "person!", file=out, end="") - assert out.getvalue() == "Hello, person!" - out = six.StringIO() - six.print_("Hello,", "person!", file=out, sep="X") - assert out.getvalue() == "Hello,Xperson!\n" - out = six.StringIO() - six.print_(six.u("Hello,"), six.u("person!"), file=out) - result = out.getvalue() - assert isinstance(result, six.text_type) - assert result == six.u("Hello, person!\n") - six.print_("Hello", file=None) # This works. - out = six.StringIO() - six.print_(None, file=out) - assert out.getvalue() == "None\n" - class FlushableStringIO(six.StringIO): - def __init__(self): - six.StringIO.__init__(self) - self.flushed = False - def flush(self): - self.flushed = True - out = FlushableStringIO() - six.print_("Hello", file=out) - assert not out.flushed - six.print_("Hello", file=out, flush=True) - assert out.flushed - - -def test_print_exceptions(): - pytest.raises(TypeError, six.print_, x=3) - pytest.raises(TypeError, six.print_, end=3) - pytest.raises(TypeError, six.print_, sep=42) - - -def test_with_metaclass(): - class Meta(type): - pass - class X(six.with_metaclass(Meta)): - pass - assert type(X) is Meta - assert issubclass(X, object) - class Base(object): - pass - class X(six.with_metaclass(Meta, Base)): - pass - assert type(X) is Meta - assert issubclass(X, Base) - class Base2(object): - pass - class X(six.with_metaclass(Meta, Base, Base2)): - pass - assert type(X) is Meta - assert issubclass(X, Base) - assert issubclass(X, Base2) - assert X.__mro__ == (X, Base, Base2, object) - class X(six.with_metaclass(Meta)): - pass - class MetaSub(Meta): - pass - class Y(six.with_metaclass(MetaSub, X)): - pass - assert type(Y) is MetaSub - assert Y.__mro__ == (Y, X, object) - - -def test_with_metaclass_typing(): - try: - import typing - except ImportError: - pytest.skip("typing module required") - class Meta(type): - pass - if sys.version_info[:2] < (3, 7): - # Generics with custom metaclasses were broken on older versions. - class Meta(Meta, typing.GenericMeta): - pass - T = typing.TypeVar('T') - class G(six.with_metaclass(Meta, typing.Generic[T])): - pass - class GA(six.with_metaclass(abc.ABCMeta, typing.Generic[T])): - pass - assert isinstance(G, Meta) - assert isinstance(GA, abc.ABCMeta) - assert G[int] is not G[G[int]] - assert GA[int] is not GA[GA[int]] - assert G.__bases__ == (typing.Generic,) - assert G.__orig_bases__ == (typing.Generic[T],) - - -@pytest.mark.skipif("sys.version_info[:2] < (3, 7)") -def test_with_metaclass_pep_560(): - class Meta(type): - pass - class A: - pass - class B: - pass - class Fake: - def __mro_entries__(self, bases): - return (A, B) - fake = Fake() - class G(six.with_metaclass(Meta, fake)): - pass - class GA(six.with_metaclass(abc.ABCMeta, fake)): - pass - assert isinstance(G, Meta) - assert isinstance(GA, abc.ABCMeta) - assert G.__bases__ == (A, B) - assert G.__orig_bases__ == (fake,) - - -@pytest.mark.skipif("sys.version_info[:2] < (3, 0)") -def test_with_metaclass_prepare(): - """Test that with_metaclass causes Meta.__prepare__ to be called with the correct arguments.""" - - class MyDict(dict): - pass - - class Meta(type): - - @classmethod - def __prepare__(cls, name, bases): - namespace = MyDict(super().__prepare__(name, bases), cls=cls, bases=bases) - namespace['namespace'] = namespace - return namespace - - class Base(object): - pass - - bases = (Base,) - - class X(six.with_metaclass(Meta, *bases)): - pass - - assert getattr(X, 'cls', type) is Meta - assert getattr(X, 'bases', ()) == bases - assert isinstance(getattr(X, 'namespace', {}), MyDict) - - -def test_wraps(): - def f(g): - @six.wraps(g) - def w(): - return 42 - return w - def k(): - pass - original_k = k - k = f(f(k)) - assert hasattr(k, '__wrapped__') - k = k.__wrapped__ - assert hasattr(k, '__wrapped__') - k = k.__wrapped__ - assert k is original_k - assert not hasattr(k, '__wrapped__') - - def f(g, assign, update): - def w(): - return 42 - w.glue = {"foo": "bar"} - w.xyzzy = {"qux": "quux"} - return six.wraps(g, assign, update)(w) - k.glue = {"melon": "egg"} - k.turnip = 43 - k = f(k, ["turnip", "baz"], ["glue", "xyzzy"]) - assert k.__name__ == "w" - assert k.turnip == 43 - assert not hasattr(k, "baz") - assert k.glue == {"melon": "egg", "foo": "bar"} - assert k.xyzzy == {"qux": "quux"} - - -def test_wraps_raises_on_missing_updated_field_on_wrapper(): - """Ensure six.wraps doesn't ignore missing attrs wrapper. - - Because that's what happens in Py3's functools.update_wrapper. - """ - def wrapped(): - pass - - def wrapper(): - pass - - with pytest.raises(AttributeError, match='has no attribute.*xyzzy'): - six.wraps(wrapped, [], ['xyzzy'])(wrapper) - - - -def test_add_metaclass(): - class Meta(type): - pass - class X: - "success" - X = six.add_metaclass(Meta)(X) - assert type(X) is Meta - assert issubclass(X, object) - assert X.__module__ == __name__ - assert X.__doc__ == "success" - class Base(object): - pass - class X(Base): - pass - X = six.add_metaclass(Meta)(X) - assert type(X) is Meta - assert issubclass(X, Base) - class Base2(object): - pass - class X(Base, Base2): - pass - X = six.add_metaclass(Meta)(X) - assert type(X) is Meta - assert issubclass(X, Base) - assert issubclass(X, Base2) - - # Test a second-generation subclass of a type. - class Meta1(type): - m1 = "m1" - class Meta2(Meta1): - m2 = "m2" - class Base: - b = "b" - Base = six.add_metaclass(Meta1)(Base) - class X(Base): - x = "x" - X = six.add_metaclass(Meta2)(X) - assert type(X) is Meta2 - assert issubclass(X, Base) - assert type(Base) is Meta1 - assert "__dict__" not in vars(X) - instance = X() - instance.attr = "test" - assert vars(instance) == {"attr": "test"} - assert instance.b == Base.b - assert instance.x == X.x - - # Test a class with slots. - class MySlots(object): - __slots__ = ["a", "b"] - MySlots = six.add_metaclass(Meta1)(MySlots) - - assert MySlots.__slots__ == ["a", "b"] - instance = MySlots() - instance.a = "foo" - pytest.raises(AttributeError, setattr, instance, "c", "baz") - - # Test a class with string for slots. - class MyStringSlots(object): - __slots__ = "ab" - MyStringSlots = six.add_metaclass(Meta1)(MyStringSlots) - assert MyStringSlots.__slots__ == "ab" - instance = MyStringSlots() - instance.ab = "foo" - pytest.raises(AttributeError, setattr, instance, "a", "baz") - pytest.raises(AttributeError, setattr, instance, "b", "baz") - - class MySlotsWeakref(object): - __slots__ = "__weakref__", - MySlotsWeakref = six.add_metaclass(Meta)(MySlotsWeakref) - assert type(MySlotsWeakref) is Meta - - -@pytest.mark.skipif("sys.version_info[:2] < (3, 3)") -def test_add_metaclass_nested(): - # Regression test for https://github.com/benjaminp/six/issues/259 - class Meta(type): - pass - - class A: - class B: pass - - expected = 'test_add_metaclass_nested.<locals>.A.B' - - assert A.B.__qualname__ == expected - - class A: - @six.add_metaclass(Meta) - class B: pass - - assert A.B.__qualname__ == expected - - -def test_assertCountEqual(): - class TestAssertCountEqual(unittest.TestCase): - def test(self): - with self.assertRaises(AssertionError): - six.assertCountEqual(self, (1, 2), [3, 4, 5]) - - six.assertCountEqual(self, (1, 2), [2, 1]) - - TestAssertCountEqual('test').test() - - -def test_assertRegex(): - class TestAssertRegex(unittest.TestCase): - def test(self): - with self.assertRaises(AssertionError): - six.assertRegex(self, 'test', r'^a') - - six.assertRegex(self, 'test', r'^t') - - TestAssertRegex('test').test() - - -def test_assertNotRegex(): - class TestAssertNotRegex(unittest.TestCase): - def test(self): - with self.assertRaises(AssertionError): - six.assertNotRegex(self, 'test', r'^t') - - six.assertNotRegex(self, 'test', r'^a') - - TestAssertNotRegex('test').test() - - -def test_assertRaisesRegex(): - class TestAssertRaisesRegex(unittest.TestCase): - def test(self): - with six.assertRaisesRegex(self, AssertionError, '^Foo'): - raise AssertionError('Foo') - - with self.assertRaises(AssertionError): - with six.assertRaisesRegex(self, AssertionError, r'^Foo'): - raise AssertionError('Bar') - - TestAssertRaisesRegex('test').test() - - -def test_python_2_unicode_compatible(): - @six.python_2_unicode_compatible - class MyTest(object): - def __str__(self): - return six.u('hello') - - def __bytes__(self): - return six.b('hello') - - my_test = MyTest() - - if six.PY2: - assert str(my_test) == six.b("hello") - assert unicode(my_test) == six.u("hello") - elif six.PY3: - assert bytes(my_test) == six.b("hello") - assert str(my_test) == six.u("hello") - - assert getattr(six.moves.builtins, 'bytes', str)(my_test) == six.b("hello") - - -class EnsureTests: - - # grinning face emoji - UNICODE_EMOJI = six.u("\U0001F600") - BINARY_EMOJI = b"\xf0\x9f\x98\x80" - - def test_ensure_binary_raise_type_error(self): - with pytest.raises(TypeError): - six.ensure_str(8) - - def test_errors_and_encoding(self): - six.ensure_binary(self.UNICODE_EMOJI, encoding='latin-1', errors='ignore') - with pytest.raises(UnicodeEncodeError): - six.ensure_binary(self.UNICODE_EMOJI, encoding='latin-1', errors='strict') - - def test_ensure_binary_raise(self): - converted_unicode = six.ensure_binary(self.UNICODE_EMOJI, encoding='utf-8', errors='strict') - converted_binary = six.ensure_binary(self.BINARY_EMOJI, encoding="utf-8", errors='strict') - if six.PY2: - # PY2: unicode -> str - assert converted_unicode == self.BINARY_EMOJI and isinstance(converted_unicode, str) - # PY2: str -> str - assert converted_binary == self.BINARY_EMOJI and isinstance(converted_binary, str) - else: - # PY3: str -> bytes - assert converted_unicode == self.BINARY_EMOJI and isinstance(converted_unicode, bytes) - # PY3: bytes -> bytes - assert converted_binary == self.BINARY_EMOJI and isinstance(converted_binary, bytes) - - def test_ensure_str(self): - converted_unicode = six.ensure_str(self.UNICODE_EMOJI, encoding='utf-8', errors='strict') - converted_binary = six.ensure_str(self.BINARY_EMOJI, encoding="utf-8", errors='strict') - if six.PY2: - # PY2: unicode -> str - assert converted_unicode == self.BINARY_EMOJI and isinstance(converted_unicode, str) - # PY2: str -> str - assert converted_binary == self.BINARY_EMOJI and isinstance(converted_binary, str) - else: - # PY3: str -> str - assert converted_unicode == self.UNICODE_EMOJI and isinstance(converted_unicode, str) - # PY3: bytes -> str - assert converted_binary == self.UNICODE_EMOJI and isinstance(converted_unicode, str) - - def test_ensure_text(self): - converted_unicode = six.ensure_text(self.UNICODE_EMOJI, encoding='utf-8', errors='strict') - converted_binary = six.ensure_text(self.BINARY_EMOJI, encoding="utf-8", errors='strict') - if six.PY2: - # PY2: unicode -> unicode - assert converted_unicode == self.UNICODE_EMOJI and isinstance(converted_unicode, unicode) - # PY2: str -> unicode - assert converted_binary == self.UNICODE_EMOJI and isinstance(converted_unicode, unicode) - else: - # PY3: str -> str - assert converted_unicode == self.UNICODE_EMOJI and isinstance(converted_unicode, str) - # PY3: bytes -> str - assert converted_binary == self.UNICODE_EMOJI and isinstance(converted_unicode, str) |