diff options
author | shadchin <shadchin@yandex-team.ru> | 2022-02-10 16:44:39 +0300 |
---|---|---|
committer | Daniil Cherednik <dcherednik@yandex-team.ru> | 2022-02-10 16:44:39 +0300 |
commit | e9656aae26e0358d5378e5b63dcac5c8dbe0e4d0 (patch) | |
tree | 64175d5cadab313b3e7039ebaa06c5bc3295e274 /contrib/python/future | |
parent | 2598ef1d0aee359b4b6d5fdd1758916d5907d04f (diff) | |
download | ydb-e9656aae26e0358d5378e5b63dcac5c8dbe0e4d0.tar.gz |
Restoring authorship annotation for <shadchin@yandex-team.ru>. Commit 2 of 2.
Diffstat (limited to 'contrib/python/future')
45 files changed, 431 insertions, 431 deletions
diff --git a/contrib/python/future/future/__init__.py b/contrib/python/future/future/__init__.py index b5ac6a6a95..ad419d67e2 100644 --- a/contrib/python/future/future/__init__.py +++ b/contrib/python/future/future/__init__.py @@ -68,7 +68,7 @@ See: http://python-future.org Credits ------- -:Author: Ed Schofield, Jordan M. Adler, et al +:Author: Ed Schofield, Jordan M. Adler, et al :Sponsor: Python Charmers Pty Ltd, Australia, and Python Charmers Pte Ltd, Singapore. http://pythoncharmers.com :Others: See docs/credits.rst or http://python-future.org/credits.html @@ -76,7 +76,7 @@ Credits Licensing --------- -Copyright 2013-2019 Python Charmers Pty Ltd, Australia. +Copyright 2013-2019 Python Charmers Pty Ltd, Australia. The software is distributed under an MIT licence. See LICENSE.txt. """ @@ -84,10 +84,10 @@ The software is distributed under an MIT licence. See LICENSE.txt. __title__ = 'future' __author__ = 'Ed Schofield' __license__ = 'MIT' -__copyright__ = 'Copyright 2013-2019 Python Charmers Pty Ltd' +__copyright__ = 'Copyright 2013-2019 Python Charmers Pty Ltd' __ver_major__ = 0 -__ver_minor__ = 18 -__ver_patch__ = 2 +__ver_minor__ = 18 +__ver_patch__ = 2 __ver_sub__ = '' __version__ = "%d.%d.%d%s" % (__ver_major__, __ver_minor__, __ver_patch__, __ver_sub__) diff --git a/contrib/python/future/future/backports/__init__.py b/contrib/python/future/future/backports/__init__.py index 4d7b07435a..c71e065354 100644 --- a/contrib/python/future/future/backports/__init__.py +++ b/contrib/python/future/future/backports/__init__.py @@ -10,7 +10,7 @@ __future_module__ = True from future.standard_library import import_top_level_modules -if sys.version_info[0] >= 3: +if sys.version_info[0] >= 3: import_top_level_modules() diff --git a/contrib/python/future/future/backports/email/message.py b/contrib/python/future/future/backports/email/message.py index 47317e67b2..d8d9615d7d 100644 --- a/contrib/python/future/future/backports/email/message.py +++ b/contrib/python/future/future/backports/email/message.py @@ -800,7 +800,7 @@ class Message(object): # There was no Content-Type header, and we don't know what type # to set it to, so raise an exception. raise errors.HeaderParseError('No Content-Type header found') - newparams = list() + newparams = list() foundp = False for pk, pv in params: if pk.lower() == 'boundary': @@ -814,10 +814,10 @@ class Message(object): # instead??? newparams.append(('boundary', '"%s"' % boundary)) # Replace the existing Content-Type header with the new value - newheaders = list() + newheaders = list() for h, v in self._headers: if h.lower() == 'content-type': - parts = list() + parts = list() for k, v in newparams: if v == '': parts.append(k) diff --git a/contrib/python/future/future/backports/http/client.py b/contrib/python/future/future/backports/http/client.py index cbbcc2cb4f..e663d125c4 100644 --- a/contrib/python/future/future/backports/http/client.py +++ b/contrib/python/future/future/backports/http/client.py @@ -83,11 +83,11 @@ from future.backports.urllib.parse import urlsplit import warnings from array import array -if PY2: - from collections import Iterable -else: - from collections.abc import Iterable - +if PY2: + from collections import Iterable +else: + from collections.abc import Iterable + __all__ = ["HTTPResponse", "HTTPConnection", "HTTPException", "NotConnected", "UnknownProtocol", "UnknownTransferEncoding", "UnimplementedFileMode", @@ -700,19 +700,19 @@ class HTTPResponse(io.RawIOBase): while total_bytes < len(b): if MAXAMOUNT < len(mvb): temp_mvb = mvb[0:MAXAMOUNT] - if PY2: - data = self.fp.read(len(temp_mvb)) - n = len(data) - temp_mvb[:n] = data - else: - n = self.fp.readinto(temp_mvb) + if PY2: + data = self.fp.read(len(temp_mvb)) + n = len(data) + temp_mvb[:n] = data + else: + n = self.fp.readinto(temp_mvb) else: - if PY2: - data = self.fp.read(len(mvb)) - n = len(data) - mvb[:n] = data - else: - n = self.fp.readinto(mvb) + if PY2: + data = self.fp.read(len(mvb)) + n = len(data) + mvb[:n] = data + else: + n = self.fp.readinto(mvb) if not n: raise IncompleteRead(bytes(mvb[0:total_bytes]), len(b)) mvb = mvb[n:] @@ -906,7 +906,7 @@ class HTTPConnection(object): try: self.sock.sendall(data) except TypeError: - if isinstance(data, Iterable): + if isinstance(data, Iterable): for d in data: self.sock.sendall(d) else: diff --git a/contrib/python/future/future/backports/http/cookiejar.py b/contrib/python/future/future/backports/http/cookiejar.py index b514cd6724..af3ef4151a 100644 --- a/contrib/python/future/future/backports/http/cookiejar.py +++ b/contrib/python/future/future/backports/http/cookiejar.py @@ -33,7 +33,7 @@ from __future__ import print_function from __future__ import division from __future__ import absolute_import from future.builtins import filter, int, map, open, str -from future.utils import as_native_str, PY2 +from future.utils import as_native_str, PY2 __all__ = ['Cookie', 'CookieJar', 'CookiePolicy', 'DefaultCookiePolicy', 'FileCookieJar', 'LWPCookieJar', 'LoadError', 'MozillaCookieJar'] @@ -41,8 +41,8 @@ __all__ = ['Cookie', 'CookieJar', 'CookiePolicy', 'DefaultCookiePolicy', import copy import datetime import re -if PY2: - re.ASCII = 0 +if PY2: + re.ASCII = 0 import time from future.backports.urllib.parse import urlparse, urlsplit, quote from future.backports.http.client import HTTP_PORT diff --git a/contrib/python/future/future/backports/http/cookies.py b/contrib/python/future/future/backports/http/cookies.py index 1b3f7372fb..8bb61e22c4 100644 --- a/contrib/python/future/future/backports/http/cookies.py +++ b/contrib/python/future/future/backports/http/cookies.py @@ -138,8 +138,8 @@ from future.utils import PY2, as_native_str # Import our required modules # import re -if PY2: - re.ASCII = 0 # for py2 compatibility +if PY2: + re.ASCII = 0 # for py2 compatibility import string __all__ = ["CookieError", "BaseCookie", "SimpleCookie"] diff --git a/contrib/python/future/future/backports/misc.py b/contrib/python/future/future/backports/misc.py index 8eb08b6bf9..098a0667e8 100644 --- a/contrib/python/future/future/backports/misc.py +++ b/contrib/python/future/future/backports/misc.py @@ -24,14 +24,14 @@ from _weakref import proxy as _proxy from itertools import repeat as _repeat, chain as _chain, starmap as _starmap from socket import getaddrinfo, SOCK_STREAM, error, socket -from future.utils import iteritems, itervalues, PY2, PY26, PY3 +from future.utils import iteritems, itervalues, PY2, PY26, PY3 + +if PY2: + from collections import Mapping, MutableMapping +else: + from collections.abc import Mapping, MutableMapping -if PY2: - from collections import Mapping, MutableMapping -else: - from collections.abc import Mapping, MutableMapping - def ceil(x): """ Return the ceiling of x as an int. @@ -783,7 +783,7 @@ class ChainMap(MutableMapping): # Py2 compatibility: __nonzero__ = __bool__ - + @recursive_repr() def __repr__(self): return '{0.__class__.__name__}({1})'.format( @@ -821,7 +821,7 @@ class ChainMap(MutableMapping): try: del self.maps[0][key] except KeyError: - raise KeyError('Key not found in the first mapping: {0!r}'.format(key)) + raise KeyError('Key not found in the first mapping: {0!r}'.format(key)) def popitem(self): 'Remove and return an item pair from maps[0]. Raise KeyError is maps[0] is empty.' @@ -835,7 +835,7 @@ class ChainMap(MutableMapping): try: return self.maps[0].pop(key, *args) except KeyError: - raise KeyError('Key not found in the first mapping: {0!r}'.format(key)) + raise KeyError('Key not found in the first mapping: {0!r}'.format(key)) def clear(self): 'Clear maps[0], leaving maps[1:] intact.' diff --git a/contrib/python/future/future/backports/urllib/parse.py b/contrib/python/future/future/backports/urllib/parse.py index ada2f8bb4c..04e52d4925 100644 --- a/contrib/python/future/future/backports/urllib/parse.py +++ b/contrib/python/future/future/backports/urllib/parse.py @@ -727,14 +727,14 @@ def quote_from_bytes(bs, safe='/'): return str('') ### For Python-Future: bs = bytes(bs) - ### + ### if isinstance(safe, str): # Normalize 'safe' by converting to bytes and removing non-ASCII chars safe = str(safe).encode('ascii', 'ignore') else: ### For Python-Future: safe = bytes(safe) - ### + ### safe = bytes([c for c in safe if c < 128]) if not bs.rstrip(_ALWAYS_SAFE_BYTES + safe): return bs.decode() diff --git a/contrib/python/future/future/backports/urllib/request.py b/contrib/python/future/future/backports/urllib/request.py index 80fc90829f..baee5401aa 100644 --- a/contrib/python/future/future/backports/urllib/request.py +++ b/contrib/python/future/future/backports/urllib/request.py @@ -113,13 +113,13 @@ import tempfile import contextlib import warnings -from future.utils import PY2 - -if PY2: - from collections import Iterable -else: - from collections.abc import Iterable - +from future.utils import PY2 + +if PY2: + from collections import Iterable +else: + from collections.abc import Iterable + # check for SSL try: import ssl @@ -1227,7 +1227,7 @@ class AbstractHTTPHandler(BaseHandler): mv = memoryview(data) size = len(mv) * mv.itemsize except TypeError: - if isinstance(data, Iterable): + if isinstance(data, Iterable): raise ValueError("Content-Length should be specified " "for iterable data of type %r %r" % (type(data), data)) diff --git a/contrib/python/future/future/backports/xmlrpc/client.py b/contrib/python/future/future/backports/xmlrpc/client.py index d908025c44..3f0cae9b00 100644 --- a/contrib/python/future/future/backports/xmlrpc/client.py +++ b/contrib/python/future/future/backports/xmlrpc/client.py @@ -133,12 +133,12 @@ from __future__ import (absolute_import, division, print_function, unicode_literals) from future.builtins import bytes, dict, int, range, str -import sys +import sys import base64 -if sys.version_info[0] < 3: - # Py2.7 compatibility hack - base64.encodebytes = base64.encodestring - base64.decodebytes = base64.decodestring +if sys.version_info[0] < 3: + # Py2.7 compatibility hack + base64.encodebytes = base64.encodestring + base64.decodebytes = base64.decodestring import time from datetime import datetime from future.backports.http import client as http_client diff --git a/contrib/python/future/future/builtins/__init__.py b/contrib/python/future/future/builtins/__init__.py index 7b0eb2e7f6..8bc1649d2f 100644 --- a/contrib/python/future/future/builtins/__init__.py +++ b/contrib/python/future/future/builtins/__init__.py @@ -11,7 +11,7 @@ from future.builtins.iterators import (filter, map, zip) # The isinstance import is no longer needed. We provide it only for # backward-compatibility with future v0.8.2. It will be removed in future v1.0. from future.builtins.misc import (ascii, chr, hex, input, isinstance, next, - oct, open, pow, round, super, max, min) + oct, open, pow, round, super, max, min) from future.utils import PY3 if PY3: @@ -38,12 +38,12 @@ from future import utils if not utils.PY3: # We only import names that shadow the builtins on Py2. No other namespace # pollution on Py2. - + # Only shadow builtins on Py2; no new names - __all__ = ['filter', 'map', 'zip', + __all__ = ['filter', 'map', 'zip', 'ascii', 'chr', 'hex', 'input', 'next', 'oct', 'open', 'pow', 'round', 'super', - 'bytes', 'dict', 'int', 'list', 'object', 'range', 'str', 'max', 'min' + 'bytes', 'dict', 'int', 'list', 'object', 'range', 'str', 'max', 'min' ] else: diff --git a/contrib/python/future/future/builtins/iterators.py b/contrib/python/future/future/builtins/iterators.py index d24b2f98aa..dff651e0f4 100644 --- a/contrib/python/future/future/builtins/iterators.py +++ b/contrib/python/future/future/builtins/iterators.py @@ -7,7 +7,7 @@ And then, for example:: for i in range(10**15): pass - + for (a, b) in zip(range(10**15), range(-10**15, 0)): pass diff --git a/contrib/python/future/future/builtins/misc.py b/contrib/python/future/future/builtins/misc.py index 380d344943..f86ce5f342 100644 --- a/contrib/python/future/future/builtins/misc.py +++ b/contrib/python/future/future/builtins/misc.py @@ -13,8 +13,8 @@ The builtin functions are: - ``open`` (equivalent to io.open on Py2) - ``super`` (backport of Py3's magic zero-argument super() function - ``round`` (new "Banker's Rounding" behaviour from Py3) -- ``max`` (new default option from Py3.4) -- ``min`` (new default option from Py3.4) +- ``max`` (new default option from Py3.4) +- ``min`` (new default option from Py3.4) ``isinstance`` is also currently exported for backwards compatibility with v0.8.2, although this has been deprecated since v0.9. @@ -61,8 +61,8 @@ if utils.PY2: from future.builtins.newnext import newnext as next from future.builtins.newround import newround as round from future.builtins.newsuper import newsuper as super - from future.builtins.new_min_max import newmax as max - from future.builtins.new_min_max import newmin as min + from future.builtins.new_min_max import newmax as max + from future.builtins.new_min_max import newmin as min from future.types.newint import newint _SENTINEL = object() @@ -93,12 +93,12 @@ if utils.PY2: else: return _builtin_pow(x+0j, y, z) - + # ``future`` doesn't support Py3.0/3.1. If we ever did, we'd add this: # callable = __builtin__.callable __all__ = ['ascii', 'chr', 'hex', 'input', 'isinstance', 'next', 'oct', - 'open', 'pow', 'round', 'super', 'max', 'min'] + 'open', 'pow', 'round', 'super', 'max', 'min'] else: import builtins @@ -114,14 +114,14 @@ else: pow = builtins.pow round = builtins.round super = builtins.super - if utils.PY34_PLUS: - max = builtins.max - min = builtins.min - __all__ = [] - else: - from future.builtins.new_min_max import newmax as max - from future.builtins.new_min_max import newmin as min - __all__ = ['min', 'max'] + if utils.PY34_PLUS: + max = builtins.max + min = builtins.min + __all__ = [] + else: + from future.builtins.new_min_max import newmax as max + from future.builtins.new_min_max import newmin as min + __all__ = ['min', 'max'] # The callable() function was removed from Py3.0 and 3.1 and # reintroduced into Py3.2+. ``future`` doesn't support Py3.0/3.1. If we ever diff --git a/contrib/python/future/future/builtins/new_min_max.py b/contrib/python/future/future/builtins/new_min_max.py index 2cfee40bda..6f0c2a86fe 100644 --- a/contrib/python/future/future/builtins/new_min_max.py +++ b/contrib/python/future/future/builtins/new_min_max.py @@ -1,59 +1,59 @@ -import itertools - -from future import utils -if utils.PY2: - from __builtin__ import max as _builtin_max, min as _builtin_min -else: - from builtins import max as _builtin_max, min as _builtin_min - -_SENTINEL = object() - - -def newmin(*args, **kwargs): - return new_min_max(_builtin_min, *args, **kwargs) - - -def newmax(*args, **kwargs): - return new_min_max(_builtin_max, *args, **kwargs) - - -def new_min_max(_builtin_func, *args, **kwargs): - """ - To support the argument "default" introduced in python 3.4 for min and max - :param _builtin_func: builtin min or builtin max - :param args: - :param kwargs: - :return: returns the min or max based on the arguments passed - """ - - for key, _ in kwargs.items(): - if key not in set(['key', 'default']): - raise TypeError('Illegal argument %s', key) - - if len(args) == 0: - raise TypeError - - if len(args) != 1 and kwargs.get('default', _SENTINEL) is not _SENTINEL: - raise TypeError - - if len(args) == 1: - iterator = iter(args[0]) - try: - first = next(iterator) - except StopIteration: - if kwargs.get('default', _SENTINEL) is not _SENTINEL: - return kwargs.get('default') - else: - raise ValueError('{}() arg is an empty sequence'.format(_builtin_func.__name__)) - else: - iterator = itertools.chain([first], iterator) - if kwargs.get('key') is not None: - return _builtin_func(iterator, key=kwargs.get('key')) - else: - return _builtin_func(iterator) - - if len(args) > 1: - if kwargs.get('key') is not None: - return _builtin_func(args, key=kwargs.get('key')) - else: - return _builtin_func(args) +import itertools + +from future import utils +if utils.PY2: + from __builtin__ import max as _builtin_max, min as _builtin_min +else: + from builtins import max as _builtin_max, min as _builtin_min + +_SENTINEL = object() + + +def newmin(*args, **kwargs): + return new_min_max(_builtin_min, *args, **kwargs) + + +def newmax(*args, **kwargs): + return new_min_max(_builtin_max, *args, **kwargs) + + +def new_min_max(_builtin_func, *args, **kwargs): + """ + To support the argument "default" introduced in python 3.4 for min and max + :param _builtin_func: builtin min or builtin max + :param args: + :param kwargs: + :return: returns the min or max based on the arguments passed + """ + + for key, _ in kwargs.items(): + if key not in set(['key', 'default']): + raise TypeError('Illegal argument %s', key) + + if len(args) == 0: + raise TypeError + + if len(args) != 1 and kwargs.get('default', _SENTINEL) is not _SENTINEL: + raise TypeError + + if len(args) == 1: + iterator = iter(args[0]) + try: + first = next(iterator) + except StopIteration: + if kwargs.get('default', _SENTINEL) is not _SENTINEL: + return kwargs.get('default') + else: + raise ValueError('{}() arg is an empty sequence'.format(_builtin_func.__name__)) + else: + iterator = itertools.chain([first], iterator) + if kwargs.get('key') is not None: + return _builtin_func(iterator, key=kwargs.get('key')) + else: + return _builtin_func(iterator) + + if len(args) > 1: + if kwargs.get('key') is not None: + return _builtin_func(args, key=kwargs.get('key')) + else: + return _builtin_func(args) diff --git a/contrib/python/future/future/builtins/newnext.py b/contrib/python/future/future/builtins/newnext.py index 9f3f274880..097638ac11 100644 --- a/contrib/python/future/future/builtins/newnext.py +++ b/contrib/python/future/future/builtins/newnext.py @@ -43,7 +43,7 @@ _SENTINEL = object() def newnext(iterator, default=_SENTINEL): """ next(iterator[, default]) - + Return the next item from the iterator. If default is given and the iterator is exhausted, it is returned instead of raising StopIteration. """ diff --git a/contrib/python/future/future/builtins/newround.py b/contrib/python/future/future/builtins/newround.py index 400b426a6a..394a2c63c4 100644 --- a/contrib/python/future/future/builtins/newround.py +++ b/contrib/python/future/future/builtins/newround.py @@ -1,7 +1,7 @@ """ ``python-future``: pure Python implementation of Python 3 round(). """ - + from future.utils import PYPY, PY26, bind_method # Use the decimal module for simplicity of implementation (and @@ -12,13 +12,13 @@ from decimal import Decimal, ROUND_HALF_EVEN def newround(number, ndigits=None): """ See Python 3 documentation: uses Banker's Rounding. - + Delegates to the __round__ method if for some reason this exists. - + If not, rounds a number to a given precision in decimal digits (default 0 digits). This returns an int when called with one argument, otherwise the same type as the number. ndigits may be negative. - + See the test_round method in future/tests/test_builtins.py for examples. """ @@ -28,7 +28,7 @@ def newround(number, ndigits=None): ndigits = 0 if hasattr(number, '__round__'): return number.__round__(ndigits) - + if ndigits < 0: raise NotImplementedError('negative ndigits not supported yet') exponent = Decimal('10') ** (-ndigits) @@ -38,21 +38,21 @@ def newround(number, ndigits=None): if 'numpy' in repr(type(number)): number = float(number) - if isinstance(number, Decimal): - d = number + if isinstance(number, Decimal): + d = number else: - if not PY26: - d = Decimal.from_float(number).quantize(exponent, - rounding=ROUND_HALF_EVEN) - else: - d = from_float_26(number).quantize(exponent, rounding=ROUND_HALF_EVEN) + if not PY26: + d = Decimal.from_float(number).quantize(exponent, + rounding=ROUND_HALF_EVEN) + else: + d = from_float_26(number).quantize(exponent, rounding=ROUND_HALF_EVEN) if return_int: return int(d) else: return float(d) - + ### From Python 2.7's decimal.py. Only needed to support Py2.6: def from_float_26(f): diff --git a/contrib/python/future/future/builtins/newsuper.py b/contrib/python/future/future/builtins/newsuper.py index c88daaf9e9..5d3402bd2f 100644 --- a/contrib/python/future/future/builtins/newsuper.py +++ b/contrib/python/future/future/builtins/newsuper.py @@ -24,7 +24,7 @@ Excerpts from Ryan's docstring: "Of course, you can still explicitly pass in the arguments if you want to do something strange. Sometimes you really do want that, e.g. to skip over some classes in the method resolution order. - + "How does it work? By inspecting the calling frame to determine the function object being executed and the object on which it's being called, and then walking the object's __mro__ chain to find out where @@ -51,14 +51,14 @@ def newsuper(typ=_SENTINEL, type_or_obj=_SENTINEL, framedepth=1): # Infer the correct call if used without arguments. if typ is _SENTINEL: # We'll need to do some frame hacking. - f = sys._getframe(framedepth) + f = sys._getframe(framedepth) try: # Get the function's first positional argument. type_or_obj = f.f_locals[f.f_code.co_varnames[0]] except (IndexError, KeyError,): raise RuntimeError('super() used in a function with no args') - + try: # Get the MRO so we can crawl it. mro = type_or_obj.__mro__ @@ -67,9 +67,9 @@ def newsuper(typ=_SENTINEL, type_or_obj=_SENTINEL, framedepth=1): mro = type_or_obj.__class__.__mro__ except AttributeError: raise RuntimeError('super() used with a non-newstyle class') - + # A ``for...else`` block? Yes! It's odd, but useful. - # If unfamiliar with for...else, see: + # If unfamiliar with for...else, see: # # http://psung.blogspot.com/2007/12/for-else-in-python.html for typ in mro: @@ -88,7 +88,7 @@ def newsuper(typ=_SENTINEL, type_or_obj=_SENTINEL, framedepth=1): try: meth = meth.__func__ except AttributeError: - meth = meth.__get__(type_or_obj, typ) + meth = meth.__get__(type_or_obj, typ) except (AttributeError, TypeError): continue if meth.func_code is f.f_code: @@ -98,7 +98,7 @@ def newsuper(typ=_SENTINEL, type_or_obj=_SENTINEL, framedepth=1): break # Found! Break out of the search loop. else: raise RuntimeError('super() called outside a method') - + # Dispatch to builtin super(). if type_or_obj is not _SENTINEL: return _builtin_super(typ, type_or_obj) diff --git a/contrib/python/future/future/moves/__init__.py b/contrib/python/future/future/moves/__init__.py index a90a33b0d0..0cd60d3d5c 100644 --- a/contrib/python/future/future/moves/__init__.py +++ b/contrib/python/future/future/moves/__init__.py @@ -4,5 +4,5 @@ import sys __future_module__ = True from future.standard_library import import_top_level_modules -if sys.version_info[0] >= 3: +if sys.version_info[0] >= 3: import_top_level_modules() diff --git a/contrib/python/future/future/moves/_dummy_thread.py b/contrib/python/future/future/moves/_dummy_thread.py index e508b406cf..e5dca348fb 100644 --- a/contrib/python/future/future/moves/_dummy_thread.py +++ b/contrib/python/future/future/moves/_dummy_thread.py @@ -2,10 +2,10 @@ from __future__ import absolute_import from future.utils import PY3 if PY3: - try: - from _dummy_thread import * - except ImportError: - from _thread import * + try: + from _dummy_thread import * + except ImportError: + from _thread import * else: __future_module__ = True from dummy_thread import * diff --git a/contrib/python/future/future/moves/copyreg.py b/contrib/python/future/future/moves/copyreg.py index 9712f4bbf2..9d08cdc5ed 100644 --- a/contrib/python/future/future/moves/copyreg.py +++ b/contrib/python/future/future/moves/copyreg.py @@ -2,11 +2,11 @@ from __future__ import absolute_import from future.utils import PY3 if PY3: - import copyreg, sys - # A "*" import uses Python 3's copyreg.__all__ which does not include - # all public names in the API surface for copyreg, this avoids that - # problem by just making our module _be_ a reference to the actual module. - sys.modules['future.moves.copyreg'] = copyreg + import copyreg, sys + # A "*" import uses Python 3's copyreg.__all__ which does not include + # all public names in the API surface for copyreg, this avoids that + # problem by just making our module _be_ a reference to the actual module. + sys.modules['future.moves.copyreg'] = copyreg else: __future_module__ = True from copy_reg import * diff --git a/contrib/python/future/future/moves/urllib/error.py b/contrib/python/future/future/moves/urllib/error.py index 1adb4605b2..7d8ada73f8 100644 --- a/contrib/python/future/future/moves/urllib/error.py +++ b/contrib/python/future/future/moves/urllib/error.py @@ -7,10 +7,10 @@ if PY3: from urllib.error import * else: __future_module__ = True - + # We use this method to get at the original Py2 urllib before any renaming magic # ContentTooShortError = sys.py2_modules['urllib'].ContentTooShortError - + with suspend_hooks(): from urllib import ContentTooShortError from urllib2 import URLError, HTTPError diff --git a/contrib/python/future/future/moves/urllib/parse.py b/contrib/python/future/future/moves/urllib/parse.py index 5bee556f0b..9074b8163f 100644 --- a/contrib/python/future/future/moves/urllib/parse.py +++ b/contrib/python/future/future/moves/urllib/parse.py @@ -10,7 +10,7 @@ else: from urlparse import (ParseResult, SplitResult, parse_qs, parse_qsl, urldefrag, urljoin, urlparse, urlsplit, urlunparse, urlunsplit) - + # we use this method to get at the original py2 urllib before any renaming # quote = sys.py2_modules['urllib'].quote # quote_plus = sys.py2_modules['urllib'].quote_plus @@ -18,7 +18,7 @@ else: # unquote_plus = sys.py2_modules['urllib'].unquote_plus # urlencode = sys.py2_modules['urllib'].urlencode # splitquery = sys.py2_modules['urllib'].splitquery - + with suspend_hooks(): from urllib import (quote, quote_plus, diff --git a/contrib/python/future/future/moves/urllib/request.py b/contrib/python/future/future/moves/urllib/request.py index c83e425ff8..972aa4ab5d 100644 --- a/contrib/python/future/future/moves/urllib/request.py +++ b/contrib/python/future/future/moves/urllib/request.py @@ -21,18 +21,18 @@ if PY3: urlretrieve, urlsplit, urlunparse) - - from urllib.parse import (splitattr, - splithost, - splitpasswd, - splitport, - splitquery, - splittag, - splittype, - splituser, - splitvalue, - to_bytes, - unwrap) + + from urllib.parse import (splitattr, + splithost, + splitpasswd, + splitport, + splitquery, + splittag, + splittype, + splituser, + splitvalue, + to_bytes, + unwrap) else: __future_module__ = True with suspend_hooks(): @@ -52,7 +52,7 @@ else: # URLopener, # FancyURLopener, # proxy_bypass) - + # from urllib2 import ( # AbstractBasicAuthHandler, # AbstractDigestAuthHandler, @@ -81,7 +81,7 @@ else: # UnknownHandler, # urlopen, # ) - + # from urlparse import ( # urldefrag # urljoin, diff --git a/contrib/python/future/future/standard_library/__init__.py b/contrib/python/future/future/standard_library/__init__.py index ca1c90d9c1..41c4f36df2 100644 --- a/contrib/python/future/future/standard_library/__init__.py +++ b/contrib/python/future/future/standard_library/__init__.py @@ -30,7 +30,7 @@ And then these normal Py3 imports work on both Py3 and Py2:: from itertools import filterfalse, zip_longest from sys import intern from collections import UserDict, UserList, UserString - from collections import OrderedDict, Counter, ChainMap # even on Py2.6 + from collections import OrderedDict, Counter, ChainMap # even on Py2.6 from subprocess import getoutput, getstatusoutput from subprocess import check_output # even on Py2.6 @@ -125,7 +125,7 @@ RENAMES = { # 'Tkinter': 'tkinter', '_winreg': 'winreg', 'thread': '_thread', - 'dummy_thread': '_dummy_thread' if sys.version_info < (3, 9) else '_thread', + 'dummy_thread': '_dummy_thread' if sys.version_info < (3, 9) else '_thread', # 'anydbm': 'dbm', # causes infinite import loop # 'whichdb': 'dbm', # causes infinite import loop # anydbm and whichdb are handled by fix_imports2 @@ -180,7 +180,7 @@ assert len(set(RENAMES.values()) & set(REPLACED_MODULES)) == 0 MOVES = [('collections', 'UserList', 'UserList', 'UserList'), ('collections', 'UserDict', 'UserDict', 'UserDict'), ('collections', 'UserString','UserString', 'UserString'), - ('collections', 'ChainMap', 'future.backports.misc', 'ChainMap'), + ('collections', 'ChainMap', 'future.backports.misc', 'ChainMap'), ('itertools', 'filterfalse','itertools', 'ifilterfalse'), ('itertools', 'zip_longest','itertools', 'izip_longest'), ('sys', 'intern','__builtin__', 'intern'), @@ -196,7 +196,7 @@ MOVES = [('collections', 'UserList', 'UserList', 'UserList'), ('math', 'ceil', 'future.backports.misc', 'ceil'), ('collections', 'OrderedDict', 'future.backports.misc', 'OrderedDict'), ('collections', 'Counter', 'future.backports.misc', 'Counter'), - ('collections', 'ChainMap', 'future.backports.misc', 'ChainMap'), + ('collections', 'ChainMap', 'future.backports.misc', 'ChainMap'), ('itertools', 'count', 'future.backports.misc', 'count'), ('reprlib', 'recursive_repr', 'future.backports.misc', 'recursive_repr'), ('functools', 'cmp_to_key', 'future.backports.misc', 'cmp_to_key'), @@ -398,7 +398,7 @@ def scrub_future_sys_modules(): """ Deprecated. """ - return {} + return {} class suspend_hooks(object): """ diff --git a/contrib/python/future/future/tests/base.py b/contrib/python/future/future/tests/base.py index 05116b2a00..4ef437baa6 100644 --- a/contrib/python/future/future/tests/base.py +++ b/contrib/python/future/future/tests/base.py @@ -163,7 +163,7 @@ class CodeHandler(unittest.TestCase): """ Converts the code block using ``futurize`` and returns the resulting code. - + Passing stages=[1] or stages=[2] passes the flag ``--stage1`` or ``stage2`` to ``futurize``. Passing both stages runs ``futurize`` with both stages by default. @@ -259,10 +259,10 @@ class CodeHandler(unittest.TestCase): If ignore_imports is True, ignores the presence of any lines beginning: - + from __future__ import ... from future import ... - + for the purpose of the comparison. """ output = self.convert(before, stages=stages, all_imports=all_imports, @@ -272,11 +272,11 @@ class CodeHandler(unittest.TestCase): else: headers = '' - reformatted = reformat_code(expected) - if headers in reformatted: - headers = '' - - self.compare(output, headers + reformatted, + reformatted = reformat_code(expected) + if headers in reformatted: + headers = '' + + self.compare(output, headers + reformatted, ignore_imports=ignore_imports) def unchanged(self, code, **kwargs): @@ -342,10 +342,10 @@ class CodeHandler(unittest.TestCase): '----\n%s\n----' % f.read(), ) ErrorClass = (FuturizeError if 'futurize' in script else PasteurizeError) - - if not hasattr(e, 'output'): - # The attribute CalledProcessError.output doesn't exist on Py2.6 - e.output = None + + if not hasattr(e, 'output'): + # The attribute CalledProcessError.output doesn't exist on Py2.6 + e.output = None raise ErrorClass(msg, e.returncode, e.cmd, output=e.output) return output diff --git a/contrib/python/future/future/types/__init__.py b/contrib/python/future/future/types/__init__.py index 3be1519aa1..062507703e 100644 --- a/contrib/python/future/future/types/__init__.py +++ b/contrib/python/future/future/types/__init__.py @@ -15,7 +15,7 @@ It is used as follows:: to bring in the new semantics for these functions from Python 3. And then, for example:: - + b = bytes(b'ABCD') assert list(b) == [65, 66, 67, 68] assert repr(b) == "b'ABCD'" @@ -46,7 +46,7 @@ then, for example:: pass and:: - + class VerboseList(list): def append(self, item): print('Adding an item') @@ -112,7 +112,7 @@ def disallow_types(argnums, disallowed_types): raises a TypeError when f is called if a unicode object is passed as `a` or a bytes object is passed as `b`. - This also skips over keyword arguments, so + This also skips over keyword arguments, so @disallow_types([0, 1], [unicode, bytes]) def g(a, b=None): @@ -130,7 +130,7 @@ def disallow_types(argnums, disallowed_types): ... def __add__(self, other): ... pass - >>> newbytes('1234') + u'1234' #doctest: +IGNORE_EXCEPTION_DETAIL + >>> newbytes('1234') + u'1234' #doctest: +IGNORE_EXCEPTION_DETAIL Traceback (most recent call last): ... TypeError: can't concat 'bytes' to (unicode) str diff --git a/contrib/python/future/future/types/newbytes.py b/contrib/python/future/future/types/newbytes.py index 1b7339c621..c9d584a7ca 100644 --- a/contrib/python/future/future/types/newbytes.py +++ b/contrib/python/future/future/types/newbytes.py @@ -9,16 +9,16 @@ from numbers import Integral import string import copy -from future.utils import istext, isbytes, PY2, PY3, with_metaclass +from future.utils import istext, isbytes, PY2, PY3, with_metaclass from future.types import no, issubset from future.types.newobject import newobject -if PY2: - from collections import Iterable -else: - from collections.abc import Iterable +if PY2: + from collections import Iterable +else: + from collections.abc import Iterable + - _builtin_bytes = bytes if PY3: @@ -104,8 +104,8 @@ class newbytes(with_metaclass(BaseNewBytes, _builtin_bytes)): newargs.append(errors) value = args[0].encode(*newargs) ### - elif hasattr(args[0], '__bytes__'): - value = args[0].__bytes__() + elif hasattr(args[0], '__bytes__'): + value = args[0].__bytes__() elif isinstance(args[0], Iterable): if len(args[0]) == 0: # This could be an empty list or tuple. Return b'' as on Py3. @@ -178,29 +178,29 @@ class newbytes(with_metaclass(BaseNewBytes, _builtin_bytes)): def __rmul__(self, other): return newbytes(super(newbytes, self).__rmul__(other)) - def __mod__(self, vals): - if isinstance(vals, newbytes): - vals = _builtin_bytes.__str__(vals) - - elif isinstance(vals, tuple): - newvals = [] - for v in vals: - if isinstance(v, newbytes): - v = _builtin_bytes.__str__(v) - newvals.append(v) - vals = tuple(newvals) - - elif (hasattr(vals.__class__, '__getitem__') and - hasattr(vals.__class__, 'iteritems')): - for k, v in vals.iteritems(): - if isinstance(v, newbytes): - vals[k] = _builtin_bytes.__str__(v) - - return _builtin_bytes.__mod__(self, vals) - - def __imod__(self, other): - return self.__mod__(other) - + def __mod__(self, vals): + if isinstance(vals, newbytes): + vals = _builtin_bytes.__str__(vals) + + elif isinstance(vals, tuple): + newvals = [] + for v in vals: + if isinstance(v, newbytes): + v = _builtin_bytes.__str__(v) + newvals.append(v) + vals = tuple(newvals) + + elif (hasattr(vals.__class__, '__getitem__') and + hasattr(vals.__class__, 'iteritems')): + for k, v in vals.iteritems(): + if isinstance(v, newbytes): + vals[k] = _builtin_bytes.__str__(v) + + return _builtin_bytes.__mod__(self, vals) + + def __imod__(self, other): + return self.__mod__(other) + def join(self, iterable_of_bytes): errmsg = 'sequence item {0}: expected bytes, {1} found' if isbytes(iterable_of_bytes) or istext(iterable_of_bytes): @@ -377,24 +377,24 @@ class newbytes(with_metaclass(BaseNewBytes, _builtin_bytes)): unorderable_err = 'unorderable types: bytes() and {0}' def __lt__(self, other): - if isinstance(other, _builtin_bytes): - return super(newbytes, self).__lt__(other) - raise TypeError(self.unorderable_err.format(type(other))) + if isinstance(other, _builtin_bytes): + return super(newbytes, self).__lt__(other) + raise TypeError(self.unorderable_err.format(type(other))) def __le__(self, other): - if isinstance(other, _builtin_bytes): - return super(newbytes, self).__le__(other) - raise TypeError(self.unorderable_err.format(type(other))) + if isinstance(other, _builtin_bytes): + return super(newbytes, self).__le__(other) + raise TypeError(self.unorderable_err.format(type(other))) def __gt__(self, other): - if isinstance(other, _builtin_bytes): - return super(newbytes, self).__gt__(other) - raise TypeError(self.unorderable_err.format(type(other))) + if isinstance(other, _builtin_bytes): + return super(newbytes, self).__gt__(other) + raise TypeError(self.unorderable_err.format(type(other))) def __ge__(self, other): - if isinstance(other, _builtin_bytes): - return super(newbytes, self).__ge__(other) - raise TypeError(self.unorderable_err.format(type(other))) + if isinstance(other, _builtin_bytes): + return super(newbytes, self).__ge__(other) + raise TypeError(self.unorderable_err.format(type(other))) def __native__(self): # We can't just feed a newbytes object into str(), because diff --git a/contrib/python/future/future/types/newdict.py b/contrib/python/future/future/types/newdict.py index 6bec7a476d..3f3a559dd5 100644 --- a/contrib/python/future/future/types/newdict.py +++ b/contrib/python/future/future/types/newdict.py @@ -100,7 +100,7 @@ class newdict(with_metaclass(BaseNewDict, _builtin_dict)): else: value = args[0] return super(newdict, cls).__new__(cls, value) - + def __native__(self): """ Hook for the future.utils.native() function diff --git a/contrib/python/future/future/types/newint.py b/contrib/python/future/future/types/newint.py index 455d8de388..748dba9d23 100644 --- a/contrib/python/future/future/types/newint.py +++ b/contrib/python/future/future/types/newint.py @@ -16,9 +16,9 @@ from future.utils import PY3, isint, istext, isbytes, with_metaclass, native if PY3: long = int - from collections.abc import Iterable -else: - from collections import Iterable + from collections.abc import Iterable +else: + from collections import Iterable class BaseNewInt(type): @@ -358,7 +358,7 @@ class newint(with_metaclass(BaseNewInt, long)): raise TypeError("cannot convert unicode objects to bytes") # mybytes can also be passed as a sequence of integers on Py3. # Test for this: - elif isinstance(mybytes, Iterable): + elif isinstance(mybytes, Iterable): mybytes = newbytes(mybytes) b = mybytes if byteorder == 'big' else mybytes[::-1] if len(b) == 0: diff --git a/contrib/python/future/future/types/newmemoryview.py b/contrib/python/future/future/types/newmemoryview.py index 76166529e6..09f804dcf4 100644 --- a/contrib/python/future/future/types/newmemoryview.py +++ b/contrib/python/future/future/types/newmemoryview.py @@ -4,13 +4,13 @@ A pretty lame implementation of a memoryview object for Python 2.6. from numbers import Integral import string -from future.utils import istext, isbytes, PY2, with_metaclass +from future.utils import istext, isbytes, PY2, with_metaclass from future.types import no, issubset -if PY2: - from collections import Iterable -else: - from collections.abc import Iterable +if PY2: + from collections import Iterable +else: + from collections.abc import Iterable # class BaseNewBytes(type): # def __instancecheck__(cls, instance): diff --git a/contrib/python/future/future/types/newobject.py b/contrib/python/future/future/types/newobject.py index 8c364153b3..31b84fc12c 100644 --- a/contrib/python/future/future/types/newobject.py +++ b/contrib/python/future/future/types/newobject.py @@ -15,10 +15,10 @@ Example use:: a = A() print(str(a)) - + # On Python 2, these relations hold: assert unicode(a) == my_unicode_string - assert str(a) == my_unicode_string.encode('utf-8') + assert str(a) == my_unicode_string.encode('utf-8') Another example:: @@ -32,7 +32,7 @@ Another example:: return next(self._iter).upper() def __iter__(self): return self - + assert list(Upper('hello')) == list('HELLO') """ @@ -44,7 +44,7 @@ class newobject(object): next __unicode__ __nonzero__ - + Subclasses of this class can merely define the Python 3 methods (__next__, __str__, and __bool__). """ @@ -52,7 +52,7 @@ class newobject(object): if hasattr(self, '__next__'): return type(self).__next__(self) raise TypeError('newobject is not an iterator') - + def __unicode__(self): # All subclasses of the builtin object should have __str__ defined. # Note that old-style classes do not have __str__ defined. @@ -105,13 +105,13 @@ class newobject(object): # else: # value = args[0] # return super(newdict, cls).__new__(cls, value) - + def __native__(self): """ Hook for the future.utils.native() function """ return object(self) - __slots__ = [] + __slots__ = [] __all__ = ['newobject'] diff --git a/contrib/python/future/future/types/newrange.py b/contrib/python/future/future/types/newrange.py index 02150797bb..eda01a5a50 100644 --- a/contrib/python/future/future/types/newrange.py +++ b/contrib/python/future/future/types/newrange.py @@ -19,12 +19,12 @@ From Dan Crosta's README: """ from __future__ import absolute_import -from future.utils import PY2 - -if PY2: - from collections import Sequence, Iterator -else: - from collections.abc import Sequence, Iterator +from future.utils import PY2 + +if PY2: + from collections import Sequence, Iterator +else: + from collections.abc import Sequence, Iterator from itertools import islice from future.backports.misc import count # with step parameter on Py2.6 @@ -95,10 +95,10 @@ class newrange(Sequence): def index(self, value): """Return the 0-based position of integer `value` in the sequence this range represents.""" - try: - diff = value - self._start - except TypeError: - raise ValueError('%r is not in range' % value) + try: + diff = value - self._start + except TypeError: + raise ValueError('%r is not in range' % value) quotient, remainder = divmod(diff, self._step) if remainder == 0 and 0 <= quotient < self._len: return abs(quotient) @@ -160,9 +160,9 @@ class range_iterator(Iterator): def __iter__(self): return self - def __next__(self): - return next(self._stepper) - + def __next__(self): + return next(self._stepper) + def next(self): return next(self._stepper) diff --git a/contrib/python/future/future/types/newstr.py b/contrib/python/future/future/types/newstr.py index 0f8c56765e..8ca191f978 100644 --- a/contrib/python/future/future/types/newstr.py +++ b/contrib/python/future/future/types/newstr.py @@ -37,7 +37,7 @@ Note that ``str()`` (and ``print()``) would then normally call the ``__unicode__`` method on objects in Python 2. To define string representations of your objects portably across Py3 and Py2, use the :func:`python_2_unicode_compatible` decorator in :mod:`future.utils`. - + """ from numbers import Number @@ -50,9 +50,9 @@ from future.types.newobject import newobject if PY3: # We'll probably never use newstr on Py3 anyway... unicode = str - from collections.abc import Iterable -else: - from collections import Iterable + from collections.abc import Iterable +else: + from collections import Iterable class BaseNewStr(type): @@ -75,7 +75,7 @@ class newstr(with_metaclass(BaseNewStr, unicode)): str(object='') -> str str(bytes_or_buffer[, encoding[, errors]]) -> str - + Create a new string object from the given object. If encoding or errors is specified, then the object must expose a data buffer that will be decoded using the given encoding and error handler. @@ -83,7 +83,7 @@ class newstr(with_metaclass(BaseNewStr, unicode)): or repr(object). encoding defaults to sys.getdefaultencoding(). errors defaults to 'strict'. - + """ if len(args) == 0: return super(newstr, cls).__new__(cls) @@ -102,12 +102,12 @@ class newstr(with_metaclass(BaseNewStr, unicode)): else: value = args[0] return super(newstr, cls).__new__(cls, value) - + def __repr__(self): """ Without the u prefix """ - + value = super(newstr, self).__repr__() # assert value[0] == u'u' return value[1:] @@ -131,7 +131,7 @@ class newstr(with_metaclass(BaseNewStr, unicode)): else: raise TypeError(errmsg.format(type(key))) return issubset(list(newkey), list(self)) - + @no('newbytes') def __add__(self, other): return newstr(super(newstr, self).__add__(other)) @@ -293,15 +293,15 @@ class newstr(with_metaclass(BaseNewStr, unicode)): isinstance(other, bytes) and not isnewbytes(other)): return super(newstr, self).__eq__(other) else: - return NotImplemented - - def __hash__(self): - if (isinstance(self, unicode) or - isinstance(self, bytes) and not isnewbytes(self)): - return super(newstr, self).__hash__() - else: - raise NotImplementedError() - + return NotImplemented + + def __hash__(self): + if (isinstance(self, unicode) or + isinstance(self, bytes) and not isnewbytes(self)): + return super(newstr, self).__hash__() + else: + raise NotImplementedError() + def __ne__(self, other): if (isinstance(other, unicode) or isinstance(other, bytes) and not isnewbytes(other)): @@ -312,28 +312,28 @@ class newstr(with_metaclass(BaseNewStr, unicode)): unorderable_err = 'unorderable types: str() and {0}' def __lt__(self, other): - if (isinstance(other, unicode) or - isinstance(other, bytes) and not isnewbytes(other)): - return super(newstr, self).__lt__(other) - raise TypeError(self.unorderable_err.format(type(other))) + if (isinstance(other, unicode) or + isinstance(other, bytes) and not isnewbytes(other)): + return super(newstr, self).__lt__(other) + raise TypeError(self.unorderable_err.format(type(other))) def __le__(self, other): - if (isinstance(other, unicode) or - isinstance(other, bytes) and not isnewbytes(other)): - return super(newstr, self).__le__(other) - raise TypeError(self.unorderable_err.format(type(other))) + if (isinstance(other, unicode) or + isinstance(other, bytes) and not isnewbytes(other)): + return super(newstr, self).__le__(other) + raise TypeError(self.unorderable_err.format(type(other))) def __gt__(self, other): - if (isinstance(other, unicode) or - isinstance(other, bytes) and not isnewbytes(other)): - return super(newstr, self).__gt__(other) - raise TypeError(self.unorderable_err.format(type(other))) + if (isinstance(other, unicode) or + isinstance(other, bytes) and not isnewbytes(other)): + return super(newstr, self).__gt__(other) + raise TypeError(self.unorderable_err.format(type(other))) def __ge__(self, other): - if (isinstance(other, unicode) or - isinstance(other, bytes) and not isnewbytes(other)): - return super(newstr, self).__ge__(other) - raise TypeError(self.unorderable_err.format(type(other))) + if (isinstance(other, unicode) or + isinstance(other, bytes) and not isnewbytes(other)): + return super(newstr, self).__ge__(other) + raise TypeError(self.unorderable_err.format(type(other))) def __getattribute__(self, name): """ diff --git a/contrib/python/future/future/utils/__init__.py b/contrib/python/future/future/utils/__init__.py index 7ba94a2c7b..46bd96def3 100644 --- a/contrib/python/future/future/utils/__init__.py +++ b/contrib/python/future/future/utils/__init__.py @@ -19,9 +19,9 @@ This module exports useful functions for 2/3 compatible code: * text_type: unicode in Python 2, str in Python 3 * string_types: basestring in Python 2, str in Python 3 - * binary_type: str in Python 2, bytes in Python 3 - * integer_types: (int, long) in Python 2, int in Python 3 - * class_types: (type, types.ClassType) in Python 2, type in Python 3 + * binary_type: str in Python 2, bytes in Python 3 + * integer_types: (int, long) in Python 2, int in Python 3 + * class_types: (type, types.ClassType) in Python 2, type in Python 3 * bchr(c): Take an integer and make a 1-character byte string @@ -57,10 +57,10 @@ import copy import inspect -PY3 = sys.version_info[0] >= 3 -PY34_PLUS = sys.version_info[0:2] >= (3, 4) -PY35_PLUS = sys.version_info[0:2] >= (3, 5) -PY36_PLUS = sys.version_info[0:2] >= (3, 6) +PY3 = sys.version_info[0] >= 3 +PY34_PLUS = sys.version_info[0:2] >= (3, 4) +PY35_PLUS = sys.version_info[0:2] >= (3, 5) +PY36_PLUS = sys.version_info[0:2] >= (3, 6) PY2 = sys.version_info[0] == 2 PY26 = sys.version_info[0:2] == (2, 6) PY27 = sys.version_info[0:2] == (2, 7) @@ -408,34 +408,34 @@ if PY3: allows re-raising exceptions with the cls value and traceback on Python 2 and 3. """ - if isinstance(tp, BaseException): - # If the first object is an instance, the type of the exception - # is the class of the instance, the instance itself is the value, - # and the second object must be None. - if value is not None: - raise TypeError("instance exception may not have a separate value") - exc = tp - elif isinstance(tp, type) and not issubclass(tp, BaseException): - # If the first object is a class, it becomes the type of the - # exception. - raise TypeError("class must derive from BaseException, not %s" % tp.__name__) + if isinstance(tp, BaseException): + # If the first object is an instance, the type of the exception + # is the class of the instance, the instance itself is the value, + # and the second object must be None. + if value is not None: + raise TypeError("instance exception may not have a separate value") + exc = tp + elif isinstance(tp, type) and not issubclass(tp, BaseException): + # If the first object is a class, it becomes the type of the + # exception. + raise TypeError("class must derive from BaseException, not %s" % tp.__name__) else: - # The second object is used to determine the exception value: If it - # is an instance of the class, the instance becomes the exception - # value. If the second object is a tuple, it is used as the argument - # list for the class constructor; if it is None, an empty argument - # list is used, and any other object is treated as a single argument - # to the constructor. The instance so created by calling the - # constructor is used as the exception value. - if isinstance(value, tp): - exc = value - elif isinstance(value, tuple): - exc = tp(*value) - elif value is None: - exc = tp() - else: - exc = tp(value) - + # The second object is used to determine the exception value: If it + # is an instance of the class, the instance becomes the exception + # value. If the second object is a tuple, it is used as the argument + # list for the class constructor; if it is None, an empty argument + # list is used, and any other object is treated as a single argument + # to the constructor. The instance so created by calling the + # constructor is used as the exception value. + if isinstance(value, tp): + exc = value + elif isinstance(value, tuple): + exc = tp(*value) + elif value is None: + exc = tp() + else: + exc = tp(value) + if exc.__traceback__ is not tb: raise exc.with_traceback(tb) raise exc @@ -468,14 +468,14 @@ else: e.__suppress_context__ = False if isinstance(cause, type) and issubclass(cause, Exception): e.__cause__ = cause() - e.__cause__.__traceback__ = sys.exc_info()[2] + e.__cause__.__traceback__ = sys.exc_info()[2] e.__suppress_context__ = True elif cause is None: e.__cause__ = None e.__suppress_context__ = True elif isinstance(cause, BaseException): e.__cause__ = cause - object.__setattr__(e.__cause__, '__traceback__', sys.exc_info()[2]) + object.__setattr__(e.__cause__, '__traceback__', sys.exc_info()[2]) e.__suppress_context__ = True else: raise TypeError("exception causes must derive from BaseException") @@ -579,14 +579,14 @@ def isbytes(obj): def isnewbytes(obj): """ - Equivalent to the result of ``type(obj) == type(newbytes)`` - in other words, it is REALLY a newbytes instance, not a Py2 native str + Equivalent to the result of ``type(obj) == type(newbytes)`` + in other words, it is REALLY a newbytes instance, not a Py2 native str object? - - Note that this does not cover subclasses of newbytes, and it is not - equivalent to ininstance(obj, newbytes) + + Note that this does not cover subclasses of newbytes, and it is not + equivalent to ininstance(obj, newbytes) """ - return type(obj).__name__ == 'newbytes' + return type(obj).__name__ == 'newbytes' def isint(obj): @@ -752,16 +752,16 @@ else: __all__ = ['PY2', 'PY26', 'PY3', 'PYPY', - 'as_native_str', 'binary_type', 'bind_method', 'bord', 'bstr', - 'bytes_to_native_str', 'class_types', 'encode_filename', - 'ensure_new_type', 'exec_', 'get_next', 'getexception', - 'implements_iterator', 'integer_types', 'is_new_style', 'isbytes', - 'isidentifier', 'isint', 'isnewbytes', 'istext', 'iteritems', - 'iterkeys', 'itervalues', 'lfilter', 'listitems', 'listvalues', - 'lmap', 'lrange', 'lzip', 'native', 'native_bytes', 'native_str', + 'as_native_str', 'binary_type', 'bind_method', 'bord', 'bstr', + 'bytes_to_native_str', 'class_types', 'encode_filename', + 'ensure_new_type', 'exec_', 'get_next', 'getexception', + 'implements_iterator', 'integer_types', 'is_new_style', 'isbytes', + 'isidentifier', 'isint', 'isnewbytes', 'istext', 'iteritems', + 'iterkeys', 'itervalues', 'lfilter', 'listitems', 'listvalues', + 'lmap', 'lrange', 'lzip', 'native', 'native_bytes', 'native_str', 'native_str_to_bytes', 'old_div', 'python_2_unicode_compatible', 'raise_', - 'raise_with_traceback', 'reraise', 'string_types', - 'text_to_native_str', 'text_type', 'tobytes', 'viewitems', - 'viewkeys', 'viewvalues', 'with_metaclass' - ] + 'raise_with_traceback', 'reraise', 'string_types', + 'text_to_native_str', 'text_type', 'tobytes', 'viewitems', + 'viewkeys', 'viewvalues', 'with_metaclass' + ] diff --git a/contrib/python/future/future/utils/surrogateescape.py b/contrib/python/future/future/utils/surrogateescape.py index 3b2a6db628..0dcc9fa6e6 100644 --- a/contrib/python/future/future/utils/surrogateescape.py +++ b/contrib/python/future/future/utils/surrogateescape.py @@ -83,7 +83,7 @@ def replace_surrogate_encode(mystring): # The following magic comes from Py3.3's Python/codecs.c file: if not 0xD800 <= code <= 0xDCFF: # Not a surrogate. Fail with the original exception. - raise NotASurrogateError + raise NotASurrogateError # mybytes = [0xe0 | (code >> 12), # 0x80 | ((code >> 6) & 0x3f), # 0x80 | (code & 0x3f)] diff --git a/contrib/python/future/html/parser.py b/contrib/python/future/html/parser.py index d23f435b23..e39488797e 100644 --- a/contrib/python/future/html/parser.py +++ b/contrib/python/future/html/parser.py @@ -2,7 +2,7 @@ from __future__ import absolute_import import sys __future_module__ = True -if sys.version_info[0] >= 3: +if sys.version_info[0] >= 3: raise ImportError('Cannot import module from python-future source folder') else: from future.moves.html.parser import * diff --git a/contrib/python/future/http/client.py b/contrib/python/future/http/client.py index f731d73c0b..a6a31006bd 100644 --- a/contrib/python/future/http/client.py +++ b/contrib/python/future/http/client.py @@ -77,9 +77,9 @@ except ImportError: # These may not be available on all versions of Python 2.6.x or 2.7.x try: from httplib import ( - _CS_IDLE, - _CS_REQ_STARTED, - _CS_REQ_SENT, + _CS_IDLE, + _CS_REQ_STARTED, + _CS_REQ_SENT, _MAXLINE, _MAXHEADERS, _is_legal_header_name, diff --git a/contrib/python/future/past/__init__.py b/contrib/python/future/past/__init__.py index 989664eea5..1471303933 100644 --- a/contrib/python/future/past/__init__.py +++ b/contrib/python/future/past/__init__.py @@ -61,26 +61,26 @@ this:: $ python3 - >>> from past.translation import autotranslate + >>> from past.translation import autotranslate >>> authotranslate('mypy2module') >>> import mypy2module until the authors of the Python 2 modules have upgraded their code. Then, for example:: - + >>> mypy2module.func_taking_py2_string(oldstr(b'abcd')) Credits ------- -:Author: Ed Schofield, Jordan M. Adler, et al +:Author: Ed Schofield, Jordan M. Adler, et al :Sponsor: Python Charmers Pty Ltd, Australia: http://pythoncharmers.com Licensing --------- -Copyright 2013-2019 Python Charmers Pty Ltd, Australia. +Copyright 2013-2019 Python Charmers Pty Ltd, Australia. The software is distributed under an MIT licence. See LICENSE.txt. """ diff --git a/contrib/python/future/past/builtins/__init__.py b/contrib/python/future/past/builtins/__init__.py index ef0d8a2e40..1b19e373c8 100644 --- a/contrib/python/future/past/builtins/__init__.py +++ b/contrib/python/future/past/builtins/__init__.py @@ -59,9 +59,9 @@ from past import utils if utils.PY3: # We only import names that shadow the builtins on Py3. No other namespace # pollution on Py3. - + # Only shadow builtins on Py3; no new names - __all__ = ['filter', 'map', 'range', 'reduce', 'zip', + __all__ = ['filter', 'map', 'range', 'reduce', 'zip', 'basestring', 'dict', 'str', 'long', 'unicode', 'apply', 'chr', 'cmp', 'execfile', 'intern', 'raw_input', 'reload', 'unichr', 'xrange' diff --git a/contrib/python/future/past/builtins/misc.py b/contrib/python/future/past/builtins/misc.py index 61a8bcb5c7..a1bae82f5b 100644 --- a/contrib/python/future/past/builtins/misc.py +++ b/contrib/python/future/past/builtins/misc.py @@ -1,17 +1,17 @@ from __future__ import unicode_literals - + import inspect -from future.utils import PY2, PY3, exec_ +from future.utils import PY2, PY3, exec_ -if PY2: - from collections import Mapping -else: - from collections.abc import Mapping +if PY2: + from collections import Mapping +else: + from collections.abc import Mapping if PY3: import builtins - from collections.abc import Mapping + from collections.abc import Mapping def apply(f, *args, **kw): return f(*args, **kw) @@ -41,9 +41,9 @@ if PY3: """ return '0' + builtins.oct(number)[2:] - import warnings - warnings.filterwarnings("ignore", category=DeprecationWarning, module="past.builtins.misc") - + import warnings + warnings.filterwarnings("ignore", category=DeprecationWarning, module="past.builtins.misc") + raw_input = input from imp import reload unicode = str @@ -51,7 +51,7 @@ if PY3: xrange = range else: import __builtin__ - from collections import Mapping + from collections import Mapping apply = __builtin__.apply chr = __builtin__.chr cmp = __builtin__.cmp @@ -84,7 +84,7 @@ if PY3: raise TypeError('globals must be a mapping') if not isinstance(mylocals, Mapping): raise TypeError('locals must be a mapping') - with open(filename, "rb") as fin: + with open(filename, "rb") as fin: source = fin.read() code = compile(source, filename, "exec") exec_(code, myglobals, mylocals) diff --git a/contrib/python/future/past/builtins/noniterators.py b/contrib/python/future/past/builtins/noniterators.py index 3cb4f90546..183ffffda4 100644 --- a/contrib/python/future/past/builtins/noniterators.py +++ b/contrib/python/future/past/builtins/noniterators.py @@ -6,7 +6,7 @@ This module is designed to be used as follows:: And then, for example:: assert isinstance(range(5), list) - + The list-producing functions this brings in are:: - ``filter`` @@ -19,7 +19,7 @@ The list-producing functions this brings in are:: from __future__ import division, absolute_import, print_function -from itertools import chain, starmap +from itertools import chain, starmap import itertools # since zip_longest doesn't exist on Py2 from past.types import basestring from past.utils import PY3 @@ -36,7 +36,7 @@ if PY3: def oldfilter(*args): """ filter(function or None, sequence) -> list, tuple, or string - + Return those items of sequence for which function(item) is true. If function is None, return the items that are true. If sequence is a tuple or string, return the same type, else return a list. @@ -56,7 +56,7 @@ if PY3: def oldmap(func, *iterables): """ map(function, sequence[, sequence, ...]) -> list - + Return a list of the results of applying the function to the items of the argument sequence(s). If more than one sequence is given, the function is called with an argument list consisting of @@ -64,7 +64,7 @@ if PY3: missing values when not all sequences have the same length. If the function is None, return a list of the items of the sequence (or a list of tuples if more than one sequence). - + Test cases: >>> oldmap(None, 'hello world') ['h', 'e', 'l', 'l', 'o', ' ', 'w', 'o', 'r', 'l', 'd'] @@ -72,7 +72,7 @@ if PY3: >>> oldmap(None, range(4)) [0, 1, 2, 3] - More test cases are in test_past.test_builtins. + More test cases are in test_past.test_builtins. """ zipped = itertools.zip_longest(*iterables) l = list(zipped) @@ -102,22 +102,22 @@ if PY3: # PyObject *it; /* the iterator object */ # int saw_StopIteration; /* bool: did the iterator end? */ # } sequence; - # + # # PyObject *func, *result; # sequence *seqs = NULL, *sqp; # Py_ssize_t n, len; # register int i, j; - # + # # n = PyTuple_Size(args); # if (n < 2) { # PyErr_SetString(PyExc_TypeError, # "map() requires at least two args"); # return NULL; # } - # + # # func = PyTuple_GetItem(args, 0); # n--; - # + # # if (func == Py_None) { # if (PyErr_WarnPy3k("map(None, ...) not supported in 3.x; " # "use list(...)", 1) < 0) @@ -127,7 +127,7 @@ if PY3: # return PySequence_List(PyTuple_GetItem(args, 1)); # } # } - # + # # /* Get space for sequence descriptors. Must NULL out the iterator # * pointers so that jumping to Fail_2 later doesn't see trash. # */ @@ -139,7 +139,7 @@ if PY3: # seqs[i].it = (PyObject*)NULL; # seqs[i].saw_StopIteration = 0; # } - # + # # /* Do a first pass to obtain iterators for the arguments, and set len # * to the largest of their lengths. # */ @@ -147,7 +147,7 @@ if PY3: # for (i = 0, sqp = seqs; i < n; ++i, ++sqp) { # PyObject *curseq; # Py_ssize_t curlen; - # + # # /* Get iterator. */ # curseq = PyTuple_GetItem(args, i+1); # sqp->it = PyObject_GetIter(curseq); @@ -159,27 +159,27 @@ if PY3: # PyErr_SetString(PyExc_TypeError, errbuf); # goto Fail_2; # } - # + # # /* Update len. */ # curlen = _PyObject_LengthHint(curseq, 8); # if (curlen > len) # len = curlen; # } - # + # # /* Get space for the result list. */ # if ((result = (PyObject *) PyList_New(len)) == NULL) # goto Fail_2; - # + # # /* Iterate over the sequences until all have stopped. */ # for (i = 0; ; ++i) { # PyObject *alist, *item=NULL, *value; # int numactive = 0; - # + # # if (func == Py_None && n == 1) # alist = NULL; # else if ((alist = PyTuple_New(n)) == NULL) # goto Fail_1; - # + # # for (j = 0, sqp = seqs; j < n; ++j, ++sqp) { # if (sqp->saw_StopIteration) { # Py_INCREF(Py_None); @@ -204,15 +204,15 @@ if PY3: # else # break; # } - # + # # if (!alist) # alist = item; - # + # # if (numactive == 0) { # Py_DECREF(alist); # break; # } - # + # # if (func == Py_None) # value = alist; # else { @@ -230,12 +230,12 @@ if PY3: # else if (PyList_SetItem(result, i, value) < 0) # goto Fail_1; # } - # + # # if (i < len && PyList_SetSlice(result, i, len, NULL) < 0) # goto Fail_1; - # + # # goto Succeed; - # + # # Fail_1: # Py_DECREF(result); # Fail_2: diff --git a/contrib/python/future/past/types/olddict.py b/contrib/python/future/past/types/olddict.py index 641dd8e358..f4f92a26a6 100644 --- a/contrib/python/future/past/types/olddict.py +++ b/contrib/python/future/past/types/olddict.py @@ -71,7 +71,7 @@ class olddict(with_metaclass(BaseOldDict, _builtin_dict)): # in the keyword argument list. For example: dict(one=1, two=2) # """ - # + # # if len(args) == 0: # return super(olddict, cls).__new__(cls) # # Was: elif isinstance(args[0], newbytes): @@ -85,7 +85,7 @@ class olddict(with_metaclass(BaseOldDict, _builtin_dict)): # else: # value = args[0] # return super(olddict, cls).__new__(cls, value) - + def __native__(self): """ Hook for the past.utils.native() function diff --git a/contrib/python/future/past/types/oldstr.py b/contrib/python/future/past/types/oldstr.py index 5f883f7645..a477d8844e 100644 --- a/contrib/python/future/past/types/oldstr.py +++ b/contrib/python/future/past/types/oldstr.py @@ -6,10 +6,10 @@ from numbers import Integral from past.utils import PY2, with_metaclass -if PY2: - from collections import Iterable -else: - from collections.abc import Iterable +if PY2: + from collections import Iterable +else: + from collections.abc import Iterable _builtin_bytes = bytes @@ -36,7 +36,7 @@ def unescape(s): """ return s.encode().decode('unicode_escape') - + class oldstr(with_metaclass(BaseOldStr, _builtin_bytes)): """ A forward port of the Python 2 8-bit string object to Py3 @@ -58,14 +58,14 @@ class oldstr(with_metaclass(BaseOldStr, _builtin_bytes)): # bytes(bytes_or_buffer) -> immutable copy of bytes_or_buffer # bytes(int) -> bytes object of size given by the parameter initialized with null bytes # bytes() -> empty bytes object - # + # # Construct an immutable array of bytes from: # - an iterable yielding integers in range(256) # - a text string encoded using the specified encoding # - any object implementing the buffer API. # - an integer # """ - # + # # if len(args) == 0: # return super(newbytes, cls).__new__(cls) # # Was: elif isinstance(args[0], newbytes): @@ -87,7 +87,7 @@ class oldstr(with_metaclass(BaseOldStr, _builtin_bytes)): # if 'errors' in kwargs: # newargs.append(kwargs['errors']) # value = args[0].encode(*newargs) - # ### + # ### # elif isinstance(args[0], Iterable): # if len(args[0]) == 0: # # What is this? @@ -104,7 +104,7 @@ class oldstr(with_metaclass(BaseOldStr, _builtin_bytes)): # else: # value = args[0] # return super(newbytes, cls).__new__(cls, value) - + def __repr__(self): s = super(oldstr, self).__repr__() # e.g. b'abc' on Py3, b'abc' on Py3 return s[1:] @@ -127,7 +127,7 @@ class oldstr(with_metaclass(BaseOldStr, _builtin_bytes)): def __contains__(self, key): if isinstance(key, int): return False - + def __native__(self): return bytes(self) diff --git a/contrib/python/future/past/utils/__init__.py b/contrib/python/future/past/utils/__init__.py index 91e14efed1..f6b2642df5 100644 --- a/contrib/python/future/past/utils/__init__.py +++ b/contrib/python/future/past/utils/__init__.py @@ -16,7 +16,7 @@ For example: import sys import numbers -PY3 = sys.version_info[0] >= 3 +PY3 = sys.version_info[0] >= 3 PY2 = sys.version_info[0] == 2 PYPY = hasattr(sys, 'pypy_translation_info') @@ -26,13 +26,13 @@ def with_metaclass(meta, *bases): Function from jinja2/_compat.py. License: BSD. Use it like this:: - + class BaseForm(object): pass - + class FormType(type): pass - + class Form(with_metaclass(FormType, BaseForm)): pass @@ -42,7 +42,7 @@ def with_metaclass(meta, *bases): we also need to make sure that we downgrade the custom metaclass for one level to something closer to type (that's why __call__ and __init__ comes back from type etc.). - + This has the advantage over six.with_metaclass of not introducing dummy classes into the final MRO. """ @@ -62,7 +62,7 @@ def native(obj): On Py3, returns the corresponding native Py3 types that are superclasses for forward-ported objects from Py2: - + >>> from past.builtins import str, dict >>> native(str(b'ABC')) # Output on Py3 follows. On Py2, output is 'ABC' diff --git a/contrib/python/future/ya.make b/contrib/python/future/ya.make index 5a56e2f461..ba24f13341 100644 --- a/contrib/python/future/ya.make +++ b/contrib/python/future/ya.make @@ -4,7 +4,7 @@ LICENSE(MIT) OWNER(g:python-contrib) -VERSION(0.18.2) +VERSION(0.18.2) NO_CHECK_IMPORTS( future.backports.email.policy # email backport is incomplete in v0.16.0. @@ -72,7 +72,7 @@ PY_SRCS( future/builtins/disabled.py future/builtins/iterators.py future/builtins/misc.py - future/builtins/new_min_max.py + future/builtins/new_min_max.py future/builtins/newnext.py future/builtins/newround.py future/builtins/newsuper.py |