diff options
author | deshevoy <deshevoy@yandex-team.ru> | 2022-02-10 16:46:57 +0300 |
---|---|---|
committer | Daniil Cherednik <dcherednik@yandex-team.ru> | 2022-02-10 16:46:57 +0300 |
commit | 28148f76dbfcc644d96427d41c92f36cbf2fdc6e (patch) | |
tree | b83306b6e37edeea782e9eed673d89286c4fef35 /contrib/python/py | |
parent | e988f30484abe5fdeedcc7a5d3c226c01a21800c (diff) | |
download | ydb-28148f76dbfcc644d96427d41c92f36cbf2fdc6e.tar.gz |
Restoring authorship annotation for <deshevoy@yandex-team.ru>. Commit 2 of 2.
Diffstat (limited to 'contrib/python/py')
20 files changed, 764 insertions, 764 deletions
diff --git a/contrib/python/py/py/__init__.py b/contrib/python/py/py/__init__.py index e8d06b03a1..b892ce1a2a 100644 --- a/contrib/python/py/py/__init__.py +++ b/contrib/python/py/py/__init__.py @@ -1,5 +1,5 @@ """ -pylib: rapid testing and development utils +pylib: rapid testing and development utils this module uses apipkg.py for lazy-loading sub modules and classes. The initpkg-dictionary below specifies @@ -8,25 +8,25 @@ dictionary or an import path. (c) Holger Krekel and others, 2004-2014 """ -from py._error import error - -try: - from py._vendored_packages import apipkg - lib_not_mangled_by_packagers = True - vendor_prefix = '._vendored_packages.' -except ImportError: - import apipkg - lib_not_mangled_by_packagers = False - vendor_prefix = '' - -try: - from ._version import version as __version__ -except ImportError: - # broken installation, we don't even try - __version__ = "unknown" - - -apipkg.initpkg(__name__, attr={'_apipkg': apipkg, 'error': error}, exportdefs={ +from py._error import error + +try: + from py._vendored_packages import apipkg + lib_not_mangled_by_packagers = True + vendor_prefix = '._vendored_packages.' +except ImportError: + import apipkg + lib_not_mangled_by_packagers = False + vendor_prefix = '' + +try: + from ._version import version as __version__ +except ImportError: + # broken installation, we don't even try + __version__ = "unknown" + + +apipkg.initpkg(__name__, attr={'_apipkg': apipkg, 'error': error}, exportdefs={ # access to all standard lib modules 'std': '._std:std', @@ -46,13 +46,13 @@ apipkg.initpkg(__name__, attr={'_apipkg': apipkg, 'error': error}, exportdefs={ }, 'apipkg' : { - 'initpkg' : vendor_prefix + 'apipkg:initpkg', - 'ApiModule' : vendor_prefix + 'apipkg:ApiModule', + 'initpkg' : vendor_prefix + 'apipkg:initpkg', + 'ApiModule' : vendor_prefix + 'apipkg:ApiModule', }, 'iniconfig' : { - 'IniConfig' : vendor_prefix + 'iniconfig:IniConfig', - 'ParseError' : vendor_prefix + 'iniconfig:ParseError', + 'IniConfig' : vendor_prefix + 'iniconfig:IniConfig', + 'ParseError' : vendor_prefix + 'iniconfig:ParseError', }, 'path' : { diff --git a/contrib/python/py/py/_code/_assertionnew.py b/contrib/python/py/py/_code/_assertionnew.py index bc7d1292cc..d03f29d870 100644 --- a/contrib/python/py/py/_code/_assertionnew.py +++ b/contrib/python/py/py/_code/_assertionnew.py @@ -10,10 +10,10 @@ import py from py._code.assertion import _format_explanation, BuiltinAssertionError -def _is_ast_expr(node): - return isinstance(node, ast.expr) -def _is_ast_stmt(node): - return isinstance(node, ast.stmt) +def _is_ast_expr(node): + return isinstance(node, ast.expr) +def _is_ast_stmt(node): + return isinstance(node, ast.stmt) class Failure(Exception): diff --git a/contrib/python/py/py/_code/_assertionold.py b/contrib/python/py/py/_code/_assertionold.py index 041616bacf..1bb70a875d 100644 --- a/contrib/python/py/py/_code/_assertionold.py +++ b/contrib/python/py/py/_code/_assertionold.py @@ -2,7 +2,7 @@ import py import sys, inspect from compiler import parse, ast, pycodegen from py._code.assertion import BuiltinAssertionError, _format_explanation -import types +import types passthroughex = py.builtin._sysex @@ -471,7 +471,7 @@ def check(s, frame=None): def interpret(source, frame, should_fail=False): module = Interpretable(parse(source, 'exec').node) #print "got module", module - if isinstance(frame, types.FrameType): + if isinstance(frame, types.FrameType): frame = py.code.Frame(frame) try: module.run(frame) diff --git a/contrib/python/py/py/_code/assertion.py b/contrib/python/py/py/_code/assertion.py index a72b8a2eaf..ff1643799c 100644 --- a/contrib/python/py/py/_code/assertion.py +++ b/contrib/python/py/py/_code/assertion.py @@ -87,4 +87,4 @@ if sys.version_info > (3, 0): reinterpret_old = "old reinterpretation not available for py3" else: from py._code._assertionold import interpret as reinterpret_old -from py._code._assertionnew import interpret as reinterpret +from py._code._assertionnew import interpret as reinterpret diff --git a/contrib/python/py/py/_code/code.py b/contrib/python/py/py/_code/code.py index 6478dbad88..dad796283f 100644 --- a/contrib/python/py/py/_code/code.py +++ b/contrib/python/py/py/_code/code.py @@ -1,6 +1,6 @@ import py import sys -from inspect import CO_VARARGS, CO_VARKEYWORDS, isclass +from inspect import CO_VARARGS, CO_VARKEYWORDS, isclass builtin_repr = repr @@ -11,9 +11,9 @@ if sys.version_info[0] >= 3: else: from py._code._py2traceback import format_exception_only -import traceback - - +import traceback + + class Code(object): """ wrapper around Python code objects """ def __init__(self, rawcode): @@ -24,7 +24,7 @@ class Code(object): self.firstlineno = rawcode.co_firstlineno - 1 self.name = rawcode.co_name except AttributeError: - raise TypeError("not a code object: %r" % (rawcode,)) + raise TypeError("not a code object: %r" % (rawcode,)) self.raw = rawcode def __eq__(self, other): @@ -109,7 +109,7 @@ class Frame(object): """ f_locals = self.f_locals.copy() f_locals.update(vars) - py.builtin.exec_(code, self.f_globals, f_locals) + py.builtin.exec_(code, self.f_globals, f_locals) def repr(self, object): """ return a 'safe' (non-recursive, one-line) string repr for 'object' @@ -133,7 +133,7 @@ class Frame(object): pass # this can occur when using Psyco return retval - + class TracebackEntry(object): """ a single entry in a traceback """ @@ -157,7 +157,7 @@ class TracebackEntry(object): return self.lineno - self.frame.code.firstlineno def __repr__(self): - return "<TracebackEntry %s:%d>" % (self.frame.code.path, self.lineno+1) + return "<TracebackEntry %s:%d>" % (self.frame.code.path, self.lineno+1) @property def statement(self): @@ -241,19 +241,19 @@ class TracebackEntry(object): raise except: line = "???" - return " File %r:%d in %s\n %s\n" % (fn, self.lineno+1, name, line) + return " File %r:%d in %s\n %s\n" % (fn, self.lineno+1, name, line) def name(self): return self.frame.code.raw.co_name name = property(name, None, None, "co_name of underlaying code") - + class Traceback(list): """ Traceback objects encapsulate and offer higher level access to Traceback entries. """ Entry = TracebackEntry - + def __init__(self, tb): """ initialize from given python traceback object. """ if hasattr(tb, 'tb_next'): @@ -368,8 +368,8 @@ class ExceptionInfo(object): self.traceback = py.code.Traceback(self.tb) def __repr__(self): - return "<ExceptionInfo %s tblen=%d>" % ( - self.typename, len(self.traceback)) + return "<ExceptionInfo %s tblen=%d>" % ( + self.typename, len(self.traceback)) def exconly(self, tryshort=False): """ return the exception as a string @@ -398,7 +398,7 @@ class ExceptionInfo(object): return ReprFileLocation(path, lineno+1, exconly) def getrepr(self, showlocals=False, style="long", - abspath=False, tbfilter=True, funcargs=False): + abspath=False, tbfilter=True, funcargs=False): """ return str()able representation of this exception info. showlocals: show locals per traceback entry style: long|short|no|native traceback style @@ -408,14 +408,14 @@ class ExceptionInfo(object): """ if style == 'native': return ReprExceptionInfo(ReprTracebackNative( - traceback.format_exception( + traceback.format_exception( self.type, self.value, self.traceback[0]._rawentry, )), self._getreprcrash()) - fmt = FormattedExcinfo( - showlocals=showlocals, style=style, + fmt = FormattedExcinfo( + showlocals=showlocals, style=style, abspath=abspath, tbfilter=tbfilter, funcargs=funcargs) return fmt.repr_excinfo(self) @@ -427,7 +427,7 @@ class ExceptionInfo(object): def __unicode__(self): entry = self.traceback[-1] loc = ReprFileLocation(entry.path, entry.lineno + 1, self.exconly()) - return loc.__unicode__() + return loc.__unicode__() class FormattedExcinfo(object): @@ -436,8 +436,8 @@ class FormattedExcinfo(object): flow_marker = ">" fail_marker = "E" - def __init__(self, showlocals=False, style="long", - abspath=True, tbfilter=True, funcargs=False): + def __init__(self, showlocals=False, style="long", + abspath=True, tbfilter=True, funcargs=False): self.showlocals = showlocals self.style = style self.tbfilter = tbfilter @@ -530,7 +530,7 @@ class FormattedExcinfo(object): #else: # self._line("%-10s =\\" % (name,)) # # XXX - # pprint.pprint(value, stream=self.excinfowriter) + # pprint.pprint(value, stream=self.excinfowriter) return ReprLocals(lines) def repr_traceback_entry(self, entry, excinfo=None): @@ -788,7 +788,7 @@ def getrawcode(obj, trycall=True): obj = getattr(obj, 'f_code', obj) obj = getattr(obj, '__code__', obj) if trycall and not hasattr(obj, 'co_firstlineno'): - if hasattr(obj, '__call__') and not isclass(obj): + if hasattr(obj, '__call__') and not isclass(obj): x = getrawcode(obj.__call__, trycall=False) if hasattr(x, 'co_firstlineno'): return x diff --git a/contrib/python/py/py/_code/source.py b/contrib/python/py/py/_code/source.py index 419c6d9a1d..7fc7b23a96 100644 --- a/contrib/python/py/py/_code/source.py +++ b/contrib/python/py/py/_code/source.py @@ -193,8 +193,8 @@ class Source(object): if flag & _AST_FLAG: return co lines = [(x + "\n") for x in self.lines] - import linecache - linecache.cache[filename] = (1, None, lines, filename) + import linecache + linecache.cache[filename] = (1, None, lines, filename) return co # @@ -225,8 +225,8 @@ def getfslineno(obj): code = py.code.Code(obj) except TypeError: try: - fn = (inspect.getsourcefile(obj) or - inspect.getfile(obj)) + fn = (inspect.getsourcefile(obj) or + inspect.getfile(obj)) except TypeError: return "", -1 @@ -249,7 +249,7 @@ def getfslineno(obj): def findsource(obj): try: - sourcelines, lineno = inspect.findsource(obj) + sourcelines, lineno = inspect.findsource(obj) except py.builtin._sysex: raise except: diff --git a/contrib/python/py/py/_error.py b/contrib/python/py/py/_error.py index f9f4d4c4d1..a6375de9fa 100644 --- a/contrib/python/py/py/_error.py +++ b/contrib/python/py/py/_error.py @@ -2,7 +2,7 @@ create errno-specific classes for IO or os calls. """ -from types import ModuleType +from types import ModuleType import sys, os, errno class Error(EnvironmentError): @@ -24,7 +24,7 @@ _winerrnomap = { 2: errno.ENOENT, 3: errno.ENOENT, 17: errno.EEXIST, - 18: errno.EXDEV, + 18: errno.EXDEV, 13: errno.EBUSY, # empty cd drive, but ENOMEDIUM seems unavailiable 22: errno.ENOTDIR, 20: errno.ENOTDIR, @@ -32,7 +32,7 @@ _winerrnomap = { 5: errno.EACCES, # anything better? } -class ErrorMaker(ModuleType): +class ErrorMaker(ModuleType): """ lazily provides Exception classes for each possible POSIX errno (as defined per the 'errno' module). All such instances subclass EnvironmentError. @@ -87,5 +87,5 @@ class ErrorMaker(ModuleType): __tracebackhide__ = True -error = ErrorMaker('py.error') -sys.modules[error.__name__] = error
\ No newline at end of file +error = ErrorMaker('py.error') +sys.modules[error.__name__] = error
\ No newline at end of file diff --git a/contrib/python/py/py/_io/terminalwriter.py b/contrib/python/py/py/_io/terminalwriter.py index cffef98006..442ca2395e 100644 --- a/contrib/python/py/py/_io/terminalwriter.py +++ b/contrib/python/py/py/_io/terminalwriter.py @@ -5,10 +5,10 @@ Helper functions for writing to terminals and files. """ -import sys, os, unicodedata +import sys, os, unicodedata import py py3k = sys.version_info[0] >= 3 -py33 = sys.version_info >= (3, 3) +py33 = sys.version_info >= (3, 3) from py.builtin import text, bytes win32_and_ctypes = False @@ -25,21 +25,21 @@ if sys.platform == "win32": def _getdimensions(): - if py33: - import shutil - size = shutil.get_terminal_size() - return size.lines, size.columns - else: - import termios, fcntl, struct - call = fcntl.ioctl(1, termios.TIOCGWINSZ, "\000" * 8) - height, width = struct.unpack("hhhh", call)[:2] - return height, width + if py33: + import shutil + size = shutil.get_terminal_size() + return size.lines, size.columns + else: + import termios, fcntl, struct + call = fcntl.ioctl(1, termios.TIOCGWINSZ, "\000" * 8) + height, width = struct.unpack("hhhh", call)[:2] + return height, width def get_terminal_width(): - width = 0 + width = 0 try: - _, width = _getdimensions() + _, width = _getdimensions() except py.builtin._sysex: raise except: @@ -59,21 +59,21 @@ def get_terminal_width(): terminal_width = get_terminal_width() -char_width = { - 'A': 1, # "Ambiguous" - 'F': 2, # Fullwidth - 'H': 1, # Halfwidth - 'N': 1, # Neutral - 'Na': 1, # Narrow - 'W': 2, # Wide -} - - -def get_line_width(text): - text = unicodedata.normalize('NFC', text) - return sum(char_width.get(unicodedata.east_asian_width(c), 1) for c in text) - - +char_width = { + 'A': 1, # "Ambiguous" + 'F': 2, # Fullwidth + 'H': 1, # Halfwidth + 'N': 1, # Neutral + 'Na': 1, # Narrow + 'W': 2, # Wide +} + + +def get_line_width(text): + text = unicodedata.normalize('NFC', text) + return sum(char_width.get(unicodedata.east_asian_width(c), 1) for c in text) + + # XXX unify with _escaped func below def ansi_print(text, esc, file=None, newline=True, flush=False): if file is None: @@ -152,7 +152,7 @@ class TerminalWriter(object): if stringio: self.stringio = file = py.io.TextIO() else: - from sys import stdout as file + from sys import stdout as file elif py.builtin.callable(file) and not ( hasattr(file, "write") and hasattr(file, "flush")): file = WriteFile(file, encoding=encoding) @@ -162,42 +162,42 @@ class TerminalWriter(object): self._file = file self.hasmarkup = should_do_markup(file) self._lastlen = 0 - self._chars_on_current_line = 0 - self._width_of_current_line = 0 - - @property - def fullwidth(self): - if hasattr(self, '_terminal_width'): - return self._terminal_width - return get_terminal_width() - - @fullwidth.setter - def fullwidth(self, value): - self._terminal_width = value - - @property - def chars_on_current_line(self): - """Return the number of characters written so far in the current line. - - Please note that this count does not produce correct results after a reline() call, - see #164. - - .. versionadded:: 1.5.0 - - :rtype: int - """ - return self._chars_on_current_line - - @property - def width_of_current_line(self): - """Return an estimate of the width so far in the current line. - - .. versionadded:: 1.6.0 - - :rtype: int - """ - return self._width_of_current_line - + self._chars_on_current_line = 0 + self._width_of_current_line = 0 + + @property + def fullwidth(self): + if hasattr(self, '_terminal_width'): + return self._terminal_width + return get_terminal_width() + + @fullwidth.setter + def fullwidth(self, value): + self._terminal_width = value + + @property + def chars_on_current_line(self): + """Return the number of characters written so far in the current line. + + Please note that this count does not produce correct results after a reline() call, + see #164. + + .. versionadded:: 1.5.0 + + :rtype: int + """ + return self._chars_on_current_line + + @property + def width_of_current_line(self): + """Return an estimate of the width so far in the current line. + + .. versionadded:: 1.6.0 + + :rtype: int + """ + return self._width_of_current_line + def _escaped(self, text, esc): if esc and self.hasmarkup: text = (''.join(['\x1b[%sm' % cod for cod in esc]) + @@ -248,27 +248,27 @@ class TerminalWriter(object): if msg: if not isinstance(msg, (bytes, text)): msg = text(msg) - - self._update_chars_on_current_line(msg) - + + self._update_chars_on_current_line(msg) + if self.hasmarkup and kw: markupmsg = self.markup(msg, **kw) else: markupmsg = msg write_out(self._file, markupmsg) - def _update_chars_on_current_line(self, text_or_bytes): - newline = b'\n' if isinstance(text_or_bytes, bytes) else '\n' - current_line = text_or_bytes.rsplit(newline, 1)[-1] - if isinstance(current_line, bytes): - current_line = current_line.decode('utf-8', errors='replace') - if newline in text_or_bytes: - self._chars_on_current_line = len(current_line) - self._width_of_current_line = get_line_width(current_line) - else: - self._chars_on_current_line += len(current_line) - self._width_of_current_line += get_line_width(current_line) - + def _update_chars_on_current_line(self, text_or_bytes): + newline = b'\n' if isinstance(text_or_bytes, bytes) else '\n' + current_line = text_or_bytes.rsplit(newline, 1)[-1] + if isinstance(current_line, bytes): + current_line = current_line.decode('utf-8', errors='replace') + if newline in text_or_bytes: + self._chars_on_current_line = len(current_line) + self._width_of_current_line = get_line_width(current_line) + else: + self._chars_on_current_line += len(current_line) + self._width_of_current_line += get_line_width(current_line) + def line(self, s='', **kw): self.write(s, **kw) self._checkfill(s) @@ -292,9 +292,9 @@ class Win32ConsoleWriter(TerminalWriter): if msg: if not isinstance(msg, (bytes, text)): msg = text(msg) - - self._update_chars_on_current_line(msg) - + + self._update_chars_on_current_line(msg) + oldcolors = None if self.hasmarkup and kw: handle = GetStdHandle(STD_OUTPUT_HANDLE) diff --git a/contrib/python/py/py/_log/log.py b/contrib/python/py/py/_log/log.py index 873fd0a6da..56969bcb58 100644 --- a/contrib/python/py/py/_log/log.py +++ b/contrib/python/py/py/_log/log.py @@ -14,10 +14,10 @@ XXX implement this API: (maybe put it into slogger.py?) debug=py.log.STDOUT, command=None) """ -import py -import sys +import py +import sys + - class Message(object): def __init__(self, keywords, args): self.keywords = keywords @@ -72,7 +72,7 @@ class KeywordMapper: def getstate(self): return self.keywords2consumer.copy() - + def setstate(self, state): self.keywords2consumer.clear() self.keywords2consumer.update(state) @@ -107,22 +107,22 @@ class KeywordMapper: consumer = File(consumer) self.keywords2consumer[keywords] = consumer - + def default_consumer(msg): """ the default consumer, prints the message to stdout (using 'print') """ sys.stderr.write(str(msg)+"\n") default_keywordmapper = KeywordMapper() - + def setconsumer(keywords, consumer): default_keywordmapper.setconsumer(keywords, consumer) - + def setstate(state): default_keywordmapper.setstate(state) - - + + def getstate(): return default_keywordmapper.getstate() @@ -130,12 +130,12 @@ def getstate(): # Consumers # - + class File(object): """ log consumer wrapping a file(-like) object """ def __init__(self, f): assert hasattr(f, 'write') - # assert isinstance(f, file) or not hasattr(f, 'open') + # assert isinstance(f, file) or not hasattr(f, 'open') self._file = f def __call__(self, msg): @@ -144,7 +144,7 @@ class File(object): if hasattr(self._file, 'flush'): self._file.flush() - + class Path(object): """ log consumer that opens and writes to a Path """ def __init__(self, filename, append=False, @@ -168,39 +168,39 @@ class Path(object): if not self._buffering: self._file.flush() - + def STDOUT(msg): """ consumer that writes to sys.stdout """ sys.stdout.write(str(msg)+"\n") - + def STDERR(msg): """ consumer that writes to sys.stderr """ sys.stderr.write(str(msg)+"\n") - + class Syslog: """ consumer that writes to the syslog daemon """ - def __init__(self, priority=None): + def __init__(self, priority=None): if priority is None: priority = self.LOG_INFO self.priority = priority def __call__(self, msg): """ write a message to the log """ - import syslog - syslog.syslog(self.priority, str(msg)) - - -try: - import syslog -except ImportError: - pass -else: - for _prio in "EMERG ALERT CRIT ERR WARNING NOTICE INFO DEBUG".split(): - _prio = "LOG_" + _prio - try: - setattr(Syslog, _prio, getattr(syslog, _prio)) - except AttributeError: - pass + import syslog + syslog.syslog(self.priority, str(msg)) + + +try: + import syslog +except ImportError: + pass +else: + for _prio in "EMERG ALERT CRIT ERR WARNING NOTICE INFO DEBUG".split(): + _prio = "LOG_" + _prio + try: + setattr(Syslog, _prio, getattr(syslog, _prio)) + except AttributeError: + pass diff --git a/contrib/python/py/py/_log/warning.py b/contrib/python/py/py/_log/warning.py index c5ee3ef597..6ef20d98a2 100644 --- a/contrib/python/py/py/_log/warning.py +++ b/contrib/python/py/py/_log/warning.py @@ -32,11 +32,11 @@ def _apiwarn(startversion, msg, stacklevel=2, function=None): msg = "%s (since version %s)" %(msg, startversion) warn(msg, stacklevel=stacklevel+1, function=function) - + def warn(msg, stacklevel=1, function=None): if function is not None: - import inspect - filename = inspect.getfile(function) + import inspect + filename = inspect.getfile(function) lineno = py.code.getrawcode(function).co_firstlineno else: try: @@ -69,11 +69,11 @@ def warn(msg, stacklevel=1, function=None): filename = module path = py.path.local(filename) warning = DeprecationWarning(msg, path, lineno) - import warnings - warnings.warn_explicit(warning, category=Warning, + import warnings + warnings.warn_explicit(warning, category=Warning, filename=str(warning.path), lineno=warning.lineno, - registry=warnings.__dict__.setdefault( + registry=warnings.__dict__.setdefault( "__warningsregistry__", {}) ) diff --git a/contrib/python/py/py/_path/common.py b/contrib/python/py/py/_path/common.py index a7408dbfe6..2364e5fef5 100644 --- a/contrib/python/py/py/_path/common.py +++ b/contrib/python/py/py/_path/common.py @@ -1,55 +1,55 @@ """ """ -import warnings -import os -import sys -import posixpath -import fnmatch +import warnings +import os +import sys +import posixpath +import fnmatch import py # Moved from local.py. iswin32 = sys.platform == "win32" or (getattr(os, '_name', False) == 'nt') -try: +try: # FileNotFoundError might happen in py34, and is not available with py27. import_errors = (ImportError, FileNotFoundError) except NameError: import_errors = (ImportError,) try: - from os import fspath -except ImportError: - def fspath(path): - """ - Return the string representation of the path. - If str or bytes is passed in, it is returned unchanged. - This code comes from PEP 519, modified to support earlier versions of - python. - - This is required for python < 3.6. - """ - if isinstance(path, (py.builtin.text, py.builtin.bytes)): - return path - - # Work from the object's type to match method resolution of other magic - # methods. - path_type = type(path) - try: - return path_type.__fspath__(path) - except AttributeError: - if hasattr(path_type, '__fspath__'): - raise - try: - import pathlib + from os import fspath +except ImportError: + def fspath(path): + """ + Return the string representation of the path. + If str or bytes is passed in, it is returned unchanged. + This code comes from PEP 519, modified to support earlier versions of + python. + + This is required for python < 3.6. + """ + if isinstance(path, (py.builtin.text, py.builtin.bytes)): + return path + + # Work from the object's type to match method resolution of other magic + # methods. + path_type = type(path) + try: + return path_type.__fspath__(path) + except AttributeError: + if hasattr(path_type, '__fspath__'): + raise + try: + import pathlib except import_errors: - pass - else: - if isinstance(path, pathlib.PurePath): - return py.builtin.text(path) - - raise TypeError("expected str, bytes or os.PathLike object, not " - + path_type.__name__) - + pass + else: + if isinstance(path, pathlib.PurePath): + return py.builtin.text(path) + + raise TypeError("expected str, bytes or os.PathLike object, not " + + path_type.__name__) + class Checkers: _depend_on_existence = 'exists', 'link', 'dir', 'file' @@ -133,7 +133,7 @@ class PathBase(object): Checkers = Checkers def __div__(self, other): - return self.join(fspath(other)) + return self.join(fspath(other)) __truediv__ = __div__ # py3k def basename(self): @@ -179,16 +179,16 @@ class PathBase(object): def readlines(self, cr=1): """ read and return a list of lines from the path. if cr is False, the newline will be removed from the end of each line. """ - if sys.version_info < (3, ): - mode = 'rU' - else: # python 3 deprecates mode "U" in favor of "newline" option - mode = 'r' - + if sys.version_info < (3, ): + mode = 'rU' + else: # python 3 deprecates mode "U" in favor of "newline" option + mode = 'r' + if not cr: - content = self.read(mode) + content = self.read(mode) return content.split('\n') else: - f = self.open(mode) + f = self.open(mode) try: return f.readlines() finally: @@ -198,16 +198,16 @@ newline will be removed from the end of each line. """ """ (deprecated) return object unpickled from self.read() """ f = self.open('rb') try: - import pickle - return py.error.checked_call(pickle.load, f) + import pickle + return py.error.checked_call(pickle.load, f) finally: f.close() def move(self, target): """ move this path to target. """ if target.relto(self): - raise py.error.EINVAL( - target, + raise py.error.EINVAL( + target, "cannot move path into a subdirectory of itself") try: self.rename(target) @@ -237,7 +237,7 @@ newline will be removed from the end of each line. """ path.check(file=1, link=1) # a link pointing to a file """ if not kw: - kw = {'exists': 1} + kw = {'exists': 1} return self.Checkers(self)._evaluate(kw) def fnmatch(self, pattern): @@ -270,7 +270,7 @@ newline will be removed from the end of each line. """ strrelpath += self.sep #assert strrelpath[-1] == self.sep #assert strrelpath[-2] != self.sep - strself = self.strpath + strself = self.strpath if sys.platform == "win32" or getattr(os, '_name', None) == 'nt': if os.path.normcase(strself).startswith( os.path.normcase(strrelpath)): @@ -386,9 +386,9 @@ newline will be removed from the end of each line. """ def _sortlist(self, res, sort): if sort: if hasattr(sort, '__call__'): - warnings.warn(DeprecationWarning( - "listdir(sort=callable) is deprecated and breaks on python3" - ), stacklevel=3) + warnings.warn(DeprecationWarning( + "listdir(sort=callable) is deprecated and breaks on python3" + ), stacklevel=3) res.sort(sort) else: res.sort() @@ -397,14 +397,14 @@ newline will be removed from the end of each line. """ """ return True if other refers to the same stat object as self. """ return self.strpath == str(other) - def __fspath__(self): - return self.strpath - + def __fspath__(self): + return self.strpath + class Visitor: def __init__(self, fil, rec, ignore, bf, sort): - if isinstance(fil, py.builtin._basestring): + if isinstance(fil, py.builtin._basestring): fil = FNMatcher(fil) - if isinstance(rec, py.builtin._basestring): + if isinstance(rec, py.builtin._basestring): self.rec = FNMatcher(rec) elif not hasattr(rec, '__call__') and rec: self.rec = lambda path: True @@ -456,4 +456,4 @@ class FNMatcher: name = str(path) # path.strpath # XXX svn? if not os.path.isabs(pattern): pattern = '*' + path.sep + pattern - return fnmatch.fnmatch(name, pattern) + return fnmatch.fnmatch(name, pattern) diff --git a/contrib/python/py/py/_path/local.py b/contrib/python/py/py/_path/local.py index 22542bd5ff..1385a03987 100644 --- a/contrib/python/py/py/_path/local.py +++ b/contrib/python/py/py/_path/local.py @@ -4,10 +4,10 @@ local path implementation. from __future__ import with_statement from contextlib import contextmanager -import sys, os, atexit, io, uuid +import sys, os, atexit, io, uuid import py from py._path import common -from py._path.common import iswin32, fspath +from py._path.common import iswin32, fspath from stat import S_ISLNK, S_ISDIR, S_ISREG from os.path import abspath, normpath, isabs, exists, isdir, isfile, islink, dirname @@ -152,12 +152,12 @@ class LocalPath(FSBase): """ if path is None: self.strpath = py.error.checked_call(os.getcwd) - else: - try: - path = fspath(path) - except TypeError: - raise ValueError("can only pass None, Path instances " - "or non-empty strings to LocalPath") + else: + try: + path = fspath(path) + except TypeError: + raise ValueError("can only pass None, Path instances " + "or non-empty strings to LocalPath") if expanduser: path = os.path.expanduser(path) self.strpath = abspath(path) @@ -169,11 +169,11 @@ class LocalPath(FSBase): return hash(s) def __eq__(self, other): - s1 = fspath(self) - try: - s2 = fspath(other) - except TypeError: - return False + s1 = fspath(self) + try: + s2 = fspath(other) + except TypeError: + return False if iswin32: s1 = s1.lower() try: @@ -186,15 +186,15 @@ class LocalPath(FSBase): return not (self == other) def __lt__(self, other): - return fspath(self) < fspath(other) + return fspath(self) < fspath(other) def __gt__(self, other): - return fspath(self) > fspath(other) + return fspath(self) > fspath(other) def samefile(self, other): """ return True if 'other' references the same file as 'self'. """ - other = fspath(other) + other = fspath(other) if not isabs(other): other = abspath(other) if self == other: @@ -213,16 +213,16 @@ class LocalPath(FSBase): if rec: # force remove of readonly files on windows if iswin32: - self.chmod(0o700, rec=1) - import shutil - py.error.checked_call( - shutil.rmtree, self.strpath, + self.chmod(0o700, rec=1) + import shutil + py.error.checked_call( + shutil.rmtree, self.strpath, ignore_errors=ignore_errors) else: py.error.checked_call(os.rmdir, self.strpath) else: if iswin32: - self.chmod(0o700) + self.chmod(0o700) py.error.checked_call(os.remove, self.strpath) def computehash(self, hashtype="md5", chunksize=524288): @@ -333,7 +333,7 @@ class LocalPath(FSBase): of the args is an absolute path. """ sep = self.sep - strargs = [fspath(arg) for arg in args] + strargs = [fspath(arg) for arg in args] strpath = self.strpath if kwargs.get('abs'): newargs = [] @@ -343,16 +343,16 @@ class LocalPath(FSBase): strargs = newargs break newargs.insert(0, arg) - # special case for when we have e.g. strpath == "/" - actual_sep = "" if strpath.endswith(sep) else sep + # special case for when we have e.g. strpath == "/" + actual_sep = "" if strpath.endswith(sep) else sep for arg in strargs: arg = arg.strip(sep) if iswin32: # allow unix style paths even on windows. arg = arg.strip('/') arg = arg.replace('/', sep) - strpath = strpath + actual_sep + arg - actual_sep = sep + strpath = strpath + actual_sep + arg + actual_sep = sep obj = object.__new__(self.__class__) obj.strpath = normpath(strpath) return obj @@ -418,22 +418,22 @@ class LocalPath(FSBase): """ return last modification time of the path. """ return self.stat().mtime - def copy(self, target, mode=False, stat=False): - """ copy path to target. - - If mode is True, will copy copy permission from path to target. - If stat is True, copy permission, last modification - time, last access time, and flags from path to target. - """ + def copy(self, target, mode=False, stat=False): + """ copy path to target. + + If mode is True, will copy copy permission from path to target. + If stat is True, copy permission, last modification + time, last access time, and flags from path to target. + """ if self.check(file=1): if target.check(dir=1): target = target.join(self.basename) assert self!=target copychunked(self, target) if mode: - copymode(self.strpath, target.strpath) - if stat: - copystat(self, target) + copymode(self.strpath, target.strpath) + if stat: + copystat(self, target) else: def rec(p): return p.check(link=0) @@ -449,28 +449,28 @@ class LocalPath(FSBase): elif x.check(dir=1): newx.ensure(dir=1) if mode: - copymode(x.strpath, newx.strpath) - if stat: - copystat(x, newx) + copymode(x.strpath, newx.strpath) + if stat: + copystat(x, newx) def rename(self, target): """ rename this path to target. """ - target = fspath(target) + target = fspath(target) return py.error.checked_call(os.rename, self.strpath, target) def dump(self, obj, bin=1): """ pickle object into path location""" f = self.open('wb') - import pickle + import pickle try: - py.error.checked_call(pickle.dump, obj, f, bin) + py.error.checked_call(pickle.dump, obj, f, bin) finally: f.close() def mkdir(self, *args): """ create & return the directory joined with args. """ p = self.join(*args) - py.error.checked_call(os.mkdir, fspath(p)) + py.error.checked_call(os.mkdir, fspath(p)) return p def write_binary(self, data, ensure=False): @@ -619,7 +619,7 @@ class LocalPath(FSBase): if rec: for x in self.visit(rec=rec): py.error.checked_call(os.chmod, str(x), mode) - py.error.checked_call(os.chmod, self.strpath, mode) + py.error.checked_call(os.chmod, self.strpath, mode) def pypkgpath(self): """ return the Python package path by looking for the last @@ -705,7 +705,7 @@ class LocalPath(FSBase): mod = sys.modules[modname] if self.basename == "__init__.py": return mod # we don't check anything as we might - # be in a namespace package ... too icky to check + # be in a namespace package ... too icky to check modfile = mod.__file__ if modfile[-4:] in ('.pyc', '.pyo'): modfile = modfile[:-1] @@ -719,17 +719,17 @@ class LocalPath(FSBase): except py.error.ENOENT: issame = False if not issame: - ignore = os.getenv('PY_IGNORE_IMPORTMISMATCH') - if ignore != '1': - raise self.ImportMismatchError(modname, modfile, self) + ignore = os.getenv('PY_IGNORE_IMPORTMISMATCH') + if ignore != '1': + raise self.ImportMismatchError(modname, modfile, self) return mod else: try: return sys.modules[modname] except KeyError: # we have a custom modname, do a pseudo-import - import types - mod = types.ModuleType(modname) + import types + mod = types.ModuleType(modname) mod.__file__ = str(self) sys.modules[modname] = mod try: @@ -774,7 +774,7 @@ class LocalPath(FSBase): else: if paths is None: if iswin32: - paths = os.environ['Path'].split(';') + paths = os.environ['Path'].split(';') if '' not in paths and '.' not in paths: paths.append('.') try: @@ -782,10 +782,10 @@ class LocalPath(FSBase): except KeyError: pass else: - paths = [path.replace('%SystemRoot%', systemroot) + paths = [path.replace('%SystemRoot%', systemroot) for path in paths] else: - paths = os.environ['PATH'].split(':') + paths = os.environ['PATH'].split(':') tryadd = [] if iswin32: tryadd += os.environ['PATHEXT'].split(os.pathsep) @@ -816,18 +816,18 @@ class LocalPath(FSBase): return cls(x) _gethomedir = classmethod(_gethomedir) - # """ - # special class constructors for local filesystem paths - # """ - @classmethod + # """ + # special class constructors for local filesystem paths + # """ + @classmethod def get_temproot(cls): """ return the system's temporary directory (where tempfiles are usually created in) """ - import tempfile - return py.path.local(tempfile.gettempdir()) + import tempfile + return py.path.local(tempfile.gettempdir()) - @classmethod + @classmethod def mkdtemp(cls, rootdir=None): """ return a Path object pointing to a fresh new temporary directory (which we created ourself). @@ -838,41 +838,41 @@ class LocalPath(FSBase): return cls(py.error.checked_call(tempfile.mkdtemp, dir=str(rootdir))) def make_numbered_dir(cls, prefix='session-', rootdir=None, keep=3, - lock_timeout=172800): # two days + lock_timeout=172800): # two days """ return unique directory with a number greater than the current maximum one. The number is assumed to start directly after prefix. if keep is true directories with a number less than (maxnum-keep) - will be removed. If .lock files are used (lock_timeout non-zero), - algorithm is multi-process safe. + will be removed. If .lock files are used (lock_timeout non-zero), + algorithm is multi-process safe. """ if rootdir is None: rootdir = cls.get_temproot() - nprefix = prefix.lower() + nprefix = prefix.lower() def parse_num(path): """ parse the number out of a path (if it matches the prefix) """ - nbasename = path.basename.lower() - if nbasename.startswith(nprefix): + nbasename = path.basename.lower() + if nbasename.startswith(nprefix): try: - return int(nbasename[len(nprefix):]) + return int(nbasename[len(nprefix):]) except ValueError: pass - def create_lockfile(path): - """ exclusively create lockfile. Throws when failed """ + def create_lockfile(path): + """ exclusively create lockfile. Throws when failed """ mypid = os.getpid() - lockfile = path.join('.lock') + lockfile = path.join('.lock') if hasattr(lockfile, 'mksymlinkto'): lockfile.mksymlinkto(str(mypid)) else: - fd = py.error.checked_call(os.open, str(lockfile), os.O_WRONLY | os.O_CREAT | os.O_EXCL, 0o644) - with os.fdopen(fd, 'w') as f: - f.write(str(mypid)) - return lockfile - - def atexit_remove_lockfile(lockfile): - """ ensure lockfile is removed at process exit """ - mypid = os.getpid() + fd = py.error.checked_call(os.open, str(lockfile), os.O_WRONLY | os.O_CREAT | os.O_EXCL, 0o644) + with os.fdopen(fd, 'w') as f: + f.write(str(mypid)) + return lockfile + + def atexit_remove_lockfile(lockfile): + """ ensure lockfile is removed at process exit """ + mypid = os.getpid() def try_remove_lockfile(): # in a fork() situation, only the last process should # remove the .lock, otherwise the other processes run the @@ -887,83 +887,83 @@ class LocalPath(FSBase): pass atexit.register(try_remove_lockfile) - # compute the maximum number currently in use with the prefix - lastmax = None - while True: - maxnum = -1 - for path in rootdir.listdir(): - num = parse_num(path) - if num is not None: - maxnum = max(maxnum, num) - - # make the new directory - try: - udir = rootdir.mkdir(prefix + str(maxnum+1)) - if lock_timeout: - lockfile = create_lockfile(udir) - atexit_remove_lockfile(lockfile) - except (py.error.EEXIST, py.error.ENOENT, py.error.EBUSY): - # race condition (1): another thread/process created the dir - # in the meantime - try again - # race condition (2): another thread/process spuriously acquired - # lock treating empty directory as candidate - # for removal - try again - # race condition (3): another thread/process tried to create the lock at - # the same time (happened in Python 3.3 on Windows) - # https://ci.appveyor.com/project/pytestbot/py/build/1.0.21/job/ffi85j4c0lqwsfwa - if lastmax == maxnum: - raise - lastmax = maxnum - continue - break - - def get_mtime(path): - """ read file modification time """ - try: - return path.lstat().mtime - except py.error.Error: - pass - - garbage_prefix = prefix + 'garbage-' - - def is_garbage(path): - """ check if path denotes directory scheduled for removal """ - bn = path.basename - return bn.startswith(garbage_prefix) - + # compute the maximum number currently in use with the prefix + lastmax = None + while True: + maxnum = -1 + for path in rootdir.listdir(): + num = parse_num(path) + if num is not None: + maxnum = max(maxnum, num) + + # make the new directory + try: + udir = rootdir.mkdir(prefix + str(maxnum+1)) + if lock_timeout: + lockfile = create_lockfile(udir) + atexit_remove_lockfile(lockfile) + except (py.error.EEXIST, py.error.ENOENT, py.error.EBUSY): + # race condition (1): another thread/process created the dir + # in the meantime - try again + # race condition (2): another thread/process spuriously acquired + # lock treating empty directory as candidate + # for removal - try again + # race condition (3): another thread/process tried to create the lock at + # the same time (happened in Python 3.3 on Windows) + # https://ci.appveyor.com/project/pytestbot/py/build/1.0.21/job/ffi85j4c0lqwsfwa + if lastmax == maxnum: + raise + lastmax = maxnum + continue + break + + def get_mtime(path): + """ read file modification time """ + try: + return path.lstat().mtime + except py.error.Error: + pass + + garbage_prefix = prefix + 'garbage-' + + def is_garbage(path): + """ check if path denotes directory scheduled for removal """ + bn = path.basename + return bn.startswith(garbage_prefix) + # prune old directories - udir_time = get_mtime(udir) - if keep and udir_time: + udir_time = get_mtime(udir) + if keep and udir_time: for path in rootdir.listdir(): num = parse_num(path) if num is not None and num <= (maxnum - keep): try: - # try acquiring lock to remove directory as exclusive user - if lock_timeout: - create_lockfile(path) - except (py.error.EEXIST, py.error.ENOENT, py.error.EBUSY): - path_time = get_mtime(path) - if not path_time: - # assume directory doesn't exist now - continue - if abs(udir_time - path_time) < lock_timeout: - # assume directory with lockfile exists - # and lock timeout hasn't expired yet - continue - - # path dir locked for exclusive use - # and scheduled for removal to avoid another thread/process - # treating it as a new directory or removal candidate - garbage_path = rootdir.join(garbage_prefix + str(uuid.uuid4())) + # try acquiring lock to remove directory as exclusive user + if lock_timeout: + create_lockfile(path) + except (py.error.EEXIST, py.error.ENOENT, py.error.EBUSY): + path_time = get_mtime(path) + if not path_time: + # assume directory doesn't exist now + continue + if abs(udir_time - path_time) < lock_timeout: + # assume directory with lockfile exists + # and lock timeout hasn't expired yet + continue + + # path dir locked for exclusive use + # and scheduled for removal to avoid another thread/process + # treating it as a new directory or removal candidate + garbage_path = rootdir.join(garbage_prefix + str(uuid.uuid4())) + try: + path.rename(garbage_path) + garbage_path.remove(rec=1) + except KeyboardInterrupt: + raise + except: # this might be py.error.Error, WindowsError ... + pass + if is_garbage(path): try: - path.rename(garbage_path) - garbage_path.remove(rec=1) - except KeyboardInterrupt: - raise - except: # this might be py.error.Error, WindowsError ... - pass - if is_garbage(path): - try: path.remove(rec=1) except KeyboardInterrupt: raise @@ -993,22 +993,22 @@ class LocalPath(FSBase): return udir make_numbered_dir = classmethod(make_numbered_dir) - + def copymode(src, dest): - """ copy permission from src to dst. """ - import shutil - shutil.copymode(src, dest) - - -def copystat(src, dest): - """ copy permission, last modification time, - last access time, and flags from src to dst.""" - import shutil - shutil.copystat(str(src), str(dest)) - - + """ copy permission from src to dst. """ + import shutil + shutil.copymode(src, dest) + + +def copystat(src, dest): + """ copy permission, last modification time, + last access time, and flags from src to dst.""" + import shutil + shutil.copystat(str(src), str(dest)) + + def copychunked(src, dest): - chunksize = 524288 # half a meg of bytes + chunksize = 524288 # half a meg of bytes fsrc = src.open('rb') try: fdest = dest.open('wb') @@ -1023,7 +1023,7 @@ def copychunked(src, dest): finally: fsrc.close() - + def isimportable(name): if name and (name[0].isalpha() or name[0] == '_'): name = name.replace("_", '') diff --git a/contrib/python/py/py/_path/svnurl.py b/contrib/python/py/py/_path/svnurl.py index 1ede990ed7..6589a71d09 100644 --- a/contrib/python/py/py/_path/svnurl.py +++ b/contrib/python/py/py/_path/svnurl.py @@ -315,7 +315,7 @@ class InfoSvnCommand: # locked, see 'svn help ls' lspattern = re.compile( r'^ *(?P<rev>\d+) +(?P<author>.+?) +(0? *(?P<size>\d+))? ' - r'*(?P<date>\w+ +\d{2} +[\d:]+) +(?P<file>.*)$') + r'*(?P<date>\w+ +\d{2} +[\d:]+) +(?P<file>.*)$') def __init__(self, line): # this is a typical line from 'svn ls http://...' #_ 1127 jum 0 Jul 13 15:28 branch/ diff --git a/contrib/python/py/py/_path/svnwc.py b/contrib/python/py/py/_path/svnwc.py index d69b51619a..b5b9d8d544 100644 --- a/contrib/python/py/py/_path/svnwc.py +++ b/contrib/python/py/py/_path/svnwc.py @@ -94,7 +94,7 @@ def _getsvnversion(ver=[]): def _escape_helper(text): text = str(text) - if sys.platform != 'win32': + if sys.platform != 'win32': text = str(text).replace('$', '\\$') return text @@ -327,7 +327,7 @@ def fixlocale(): return '' # some nasty chunk of code to solve path and url conversion and quoting issues -ILLEGAL_CHARS = '* | \\ / : < > ? \t \n \x0b \x0c \r'.split(' ') +ILLEGAL_CHARS = '* | \\ / : < > ? \t \n \x0b \x0c \r'.split(' ') if os.sep in ILLEGAL_CHARS: ILLEGAL_CHARS.remove(os.sep) ISWINDOWS = sys.platform == 'win32' @@ -354,7 +354,7 @@ def path_to_fspath(path, addat=True): def url_from_path(path): fspath = path_to_fspath(path, False) - from urllib import quote + from urllib import quote if ISWINDOWS: match = _reg_allow_disk.match(fspath) fspath = fspath.replace('\\', '/') @@ -490,7 +490,7 @@ class SvnWCCommandPath(common.PathBase): strerr.find('file already exists') != -1 or strerr.find('w150002:') != -1 or strerr.find("can't create directory") != -1): - raise py.error.EEXIST(strerr) #self) + raise py.error.EEXIST(strerr) #self) raise return out @@ -504,7 +504,7 @@ class SvnWCCommandPath(common.PathBase): if url is None: url = self.url if rev is None or rev == -1: - if (sys.platform != 'win32' and + if (sys.platform != 'win32' and _getsvnversion() == '1.3'): url += "@HEAD" else: @@ -785,7 +785,7 @@ recursively. """ info = InfoSvnWCCommand(output) # Can't reliably compare on Windows without access to win32api - if sys.platform != 'win32': + if sys.platform != 'win32': if info.path != self.localpath: raise py.error.ENOENT(self, "not a versioned resource:" + " %s != %s" % (info.path, self.localpath)) diff --git a/contrib/python/py/py/_std.py b/contrib/python/py/py/_std.py index bd84411da6..66adb7b023 100644 --- a/contrib/python/py/py/_std.py +++ b/contrib/python/py/py/_std.py @@ -1,11 +1,11 @@ import sys -import warnings +import warnings + + +class PyStdIsDeprecatedWarning(DeprecationWarning): + pass + - -class PyStdIsDeprecatedWarning(DeprecationWarning): - pass - - class Std(object): """ makes top-level python modules available as an attribute, importing them on first access. diff --git a/contrib/python/py/py/_vendored_packages/apipkg/__init__.py b/contrib/python/py/py/_vendored_packages/apipkg/__init__.py index 6f7cd75b39..350d8c4b07 100644 --- a/contrib/python/py/py/_vendored_packages/apipkg/__init__.py +++ b/contrib/python/py/py/_vendored_packages/apipkg/__init__.py @@ -1,50 +1,50 @@ -""" +""" apipkg: control the exported namespace of a Python package. - + see https://pypi.python.org/pypi/apipkg - -(c) holger krekel, 2009 - MIT license -""" -import os -import sys -from types import ModuleType - + +(c) holger krekel, 2009 - MIT license +""" +import os +import sys +from types import ModuleType + from .version import version as __version__ # NOQA:F401 - - -def _py_abspath(path): - """ - special version of abspath - that will leave paths from jython jars alone - """ + + +def _py_abspath(path): + """ + special version of abspath + that will leave paths from jython jars alone + """ if path.startswith("__pyclasspath__"): - - return path - else: - return os.path.abspath(path) - - -def distribution_version(name): - """try to get the version of the named distribution, - returs None on failure""" - from pkg_resources import get_distribution, DistributionNotFound - - try: - dist = get_distribution(name) - except DistributionNotFound: - pass - else: - return dist.version - - + + return path + else: + return os.path.abspath(path) + + +def distribution_version(name): + """try to get the version of the named distribution, + returs None on failure""" + from pkg_resources import get_distribution, DistributionNotFound + + try: + dist = get_distribution(name) + except DistributionNotFound: + pass + else: + return dist.version + + def initpkg(pkgname, exportdefs, attr=None, eager=False): - """ initialize given package from the export definitions. """ + """ initialize given package from the export definitions. """ attr = attr or {} - oldmod = sys.modules.get(pkgname) - d = {} + oldmod = sys.modules.get(pkgname) + d = {} f = getattr(oldmod, "__file__", None) - if f: - f = _py_abspath(f) + if f: + f = _py_abspath(f) d["__file__"] = f if hasattr(oldmod, "__version__"): d["__version__"] = oldmod.__version__ @@ -57,79 +57,79 @@ def initpkg(pkgname, exportdefs, attr=None, eager=False): if "__doc__" not in exportdefs and getattr(oldmod, "__doc__", None): d["__doc__"] = oldmod.__doc__ d["__spec__"] = getattr(oldmod, "__spec__", None) - d.update(attr) - if hasattr(oldmod, "__dict__"): - oldmod.__dict__.update(d) - mod = ApiModule(pkgname, exportdefs, implprefix=pkgname, attr=d) - sys.modules[pkgname] = mod - # eagerload in bypthon to avoid their monkeypatching breaking packages + d.update(attr) + if hasattr(oldmod, "__dict__"): + oldmod.__dict__.update(d) + mod = ApiModule(pkgname, exportdefs, implprefix=pkgname, attr=d) + sys.modules[pkgname] = mod + # eagerload in bypthon to avoid their monkeypatching breaking packages if "bpython" in sys.modules or eager: for module in list(sys.modules.values()): - if isinstance(module, ApiModule): - module.__dict__ + if isinstance(module, ApiModule): + module.__dict__ return mod - - -def importobj(modpath, attrname): + + +def importobj(modpath, attrname): """imports a module, then resolves the attrname on it""" module = __import__(modpath, None, None, ["__doc__"]) - if not attrname: - return module - - retval = module - names = attrname.split(".") - for x in names: - retval = getattr(retval, x) - return retval - - -class ApiModule(ModuleType): + if not attrname: + return module + + retval = module + names = attrname.split(".") + for x in names: + retval = getattr(retval, x) + return retval + + +class ApiModule(ModuleType): """the magical lazy-loading module standing""" - def __docget(self): - try: - return self.__doc - except AttributeError: + def __docget(self): + try: + return self.__doc + except AttributeError: if "__doc__" in self.__map__: return self.__makeattr("__doc__") - - def __docset(self, value): - self.__doc = value - - __doc__ = property(__docget, __docset) - - def __init__(self, name, importspec, implprefix=None, attr=None): - self.__name__ = name + + def __docset(self, value): + self.__doc = value + + __doc__ = property(__docget, __docset) + + def __init__(self, name, importspec, implprefix=None, attr=None): + self.__name__ = name self.__all__ = [x for x in importspec if x != "__onfirstaccess__"] - self.__map__ = {} - self.__implprefix__ = implprefix or name - if attr: - for name, val in attr.items(): - # print "setting", self.__name__, name, val - setattr(self, name, val) - for name, importspec in importspec.items(): - if isinstance(importspec, dict): + self.__map__ = {} + self.__implprefix__ = implprefix or name + if attr: + for name, val in attr.items(): + # print "setting", self.__name__, name, val + setattr(self, name, val) + for name, importspec in importspec.items(): + if isinstance(importspec, dict): subname = "{}.{}".format(self.__name__, name) - apimod = ApiModule(subname, importspec, implprefix) - sys.modules[subname] = apimod - setattr(self, name, apimod) - else: + apimod = ApiModule(subname, importspec, implprefix) + sys.modules[subname] = apimod + setattr(self, name, apimod) + else: parts = importspec.split(":") - modpath = parts.pop(0) - attrname = parts and parts[0] or "" + modpath = parts.pop(0) + attrname = parts and parts[0] or "" if modpath[0] == ".": - modpath = implprefix + modpath - - if not attrname: + modpath = implprefix + modpath + + if not attrname: subname = "{}.{}".format(self.__name__, name) - apimod = AliasModule(subname, modpath) - sys.modules[subname] = apimod + apimod = AliasModule(subname, modpath) + sys.modules[subname] = apimod if "." not in name: - setattr(self, name, apimod) - else: - self.__map__[name] = (modpath, attrname) - - def __repr__(self): + setattr(self, name, apimod) + else: + self.__map__[name] = (modpath, attrname) + + def __repr__(self): repr_list = [] if hasattr(self, "__version__"): repr_list.append("version=" + repr(self.__version__)) @@ -138,80 +138,80 @@ class ApiModule(ModuleType): if repr_list: return "<ApiModule {!r} {}>".format(self.__name__, " ".join(repr_list)) return "<ApiModule {!r}>".format(self.__name__) - - def __makeattr(self, name): - """lazily compute value for name or raise AttributeError if unknown.""" - # print "makeattr", self.__name__, name - target = None + + def __makeattr(self, name): + """lazily compute value for name or raise AttributeError if unknown.""" + # print "makeattr", self.__name__, name + target = None if "__onfirstaccess__" in self.__map__: target = self.__map__.pop("__onfirstaccess__") - importobj(*target)() - try: - modpath, attrname = self.__map__[name] - except KeyError: + importobj(*target)() + try: + modpath, attrname = self.__map__[name] + except KeyError: if target is not None and name != "__onfirstaccess__": - # retry, onfirstaccess might have set attrs - return getattr(self, name) - raise AttributeError(name) - else: - result = importobj(modpath, attrname) - setattr(self, name, result) - try: - del self.__map__[name] - except KeyError: - pass # in a recursive-import situation a double-del can happen - return result - - __getattr__ = __makeattr - - @property - def __dict__(self): - # force all the content of the module - # to be loaded when __dict__ is read + # retry, onfirstaccess might have set attrs + return getattr(self, name) + raise AttributeError(name) + else: + result = importobj(modpath, attrname) + setattr(self, name, result) + try: + del self.__map__[name] + except KeyError: + pass # in a recursive-import situation a double-del can happen + return result + + __getattr__ = __makeattr + + @property + def __dict__(self): + # force all the content of the module + # to be loaded when __dict__ is read dictdescr = ModuleType.__dict__["__dict__"] - dict = dictdescr.__get__(self) - if dict is not None: + dict = dictdescr.__get__(self) + if dict is not None: hasattr(self, "some") - for name in self.__all__: - try: - self.__makeattr(name) - except AttributeError: - pass - return dict - - -def AliasModule(modname, modpath, attrname=None): - mod = [] - - def getmod(): - if not mod: - x = importobj(modpath, None) - if attrname is not None: - x = getattr(x, attrname) - mod.append(x) - return mod[0] - + for name in self.__all__: + try: + self.__makeattr(name) + except AttributeError: + pass + return dict + + +def AliasModule(modname, modpath, attrname=None): + mod = [] + + def getmod(): + if not mod: + x = importobj(modpath, None) + if attrname is not None: + x = getattr(x, attrname) + mod.append(x) + return mod[0] + x = modpath + ("." + attrname if attrname else "") repr_result = "<AliasModule {!r} for {!r}>".format(modname, x) - class AliasModule(ModuleType): - def __repr__(self): + class AliasModule(ModuleType): + def __repr__(self): return repr_result - - def __getattribute__(self, name): - try: - return getattr(getmod(), name) - except ImportError: + + def __getattribute__(self, name): + try: + return getattr(getmod(), name) + except ImportError: if modpath == "pytest" and attrname is None: # hack for pylibs py.test return None else: raise - - def __setattr__(self, name, value): - setattr(getmod(), name, value) - - def __delattr__(self, name): - delattr(getmod(), name) - - return AliasModule(str(modname)) + + def __setattr__(self, name, value): + setattr(getmod(), name, value) + + def __delattr__(self, name): + delattr(getmod(), name) + + return AliasModule(str(modname)) diff --git a/contrib/python/py/py/_vendored_packages/iniconfig/__init__.py b/contrib/python/py/py/_vendored_packages/iniconfig/__init__.py index 9272bbde9a..ebef1fd720 100644 --- a/contrib/python/py/py/_vendored_packages/iniconfig/__init__.py +++ b/contrib/python/py/py/_vendored_packages/iniconfig/__init__.py @@ -1,56 +1,56 @@ -""" brain-dead simple parser for ini-style files. -(C) Ronny Pfannschmidt, Holger Krekel -- MIT licensed -""" +""" brain-dead simple parser for ini-style files. +(C) Ronny Pfannschmidt, Holger Krekel -- MIT licensed +""" import io -__all__ = ['IniConfig', 'ParseError'] - -COMMENTCHARS = "#;" - - -class ParseError(Exception): - def __init__(self, path, lineno, msg): - Exception.__init__(self, path, lineno, msg) - self.path = path - self.lineno = lineno - self.msg = msg - - def __str__(self): - return "%s:%s: %s" % (self.path, self.lineno+1, self.msg) - - -class SectionWrapper(object): - def __init__(self, config, name): - self.config = config - self.name = name - - def lineof(self, name): - return self.config.lineof(self.name, name) - - def get(self, key, default=None, convert=str): - return self.config.get(self.name, key, - convert=convert, default=default) - - def __getitem__(self, key): - return self.config.sections[self.name][key] - - def __iter__(self): - section = self.config.sections.get(self.name, []) - - def lineof(key): - return self.config.lineof(self.name, key) - for name in sorted(section, key=lineof): - yield name - - def items(self): - for name in self: - yield name, self[name] - - -class IniConfig(object): - def __init__(self, path, data=None): - self.path = str(path) # convenience - if data is None: +__all__ = ['IniConfig', 'ParseError'] + +COMMENTCHARS = "#;" + + +class ParseError(Exception): + def __init__(self, path, lineno, msg): + Exception.__init__(self, path, lineno, msg) + self.path = path + self.lineno = lineno + self.msg = msg + + def __str__(self): + return "%s:%s: %s" % (self.path, self.lineno+1, self.msg) + + +class SectionWrapper(object): + def __init__(self, config, name): + self.config = config + self.name = name + + def lineof(self, name): + return self.config.lineof(self.name, name) + + def get(self, key, default=None, convert=str): + return self.config.get(self.name, key, + convert=convert, default=default) + + def __getitem__(self, key): + return self.config.sections[self.name][key] + + def __iter__(self): + section = self.config.sections.get(self.name, []) + + def lineof(key): + return self.config.lineof(self.name, key) + for name in sorted(section, key=lineof): + yield name + + def items(self): + for name in self: + yield name, self[name] + + +class IniConfig(object): + def __init__(self, path, data=None): + self.path = str(path) # convenience + if data is None: if self.path.startswith('pkg:'): import pkgutil @@ -59,116 +59,116 @@ class IniConfig(object): f = io.StringIO(content.decode('utf-8')) else: f = open(self.path) - try: - tokens = self._parse(iter(f)) - finally: - f.close() - else: - tokens = self._parse(data.splitlines(True)) - - self._sources = {} - self.sections = {} - - for lineno, section, name, value in tokens: - if section is None: - self._raise(lineno, 'no section header defined') - self._sources[section, name] = lineno - if name is None: - if section in self.sections: - self._raise(lineno, 'duplicate section %r' % (section, )) - self.sections[section] = {} - else: - if name in self.sections[section]: - self._raise(lineno, 'duplicate name %r' % (name, )) - self.sections[section][name] = value - - def _raise(self, lineno, msg): - raise ParseError(self.path, lineno, msg) - - def _parse(self, line_iter): - result = [] - section = None - for lineno, line in enumerate(line_iter): - name, data = self._parseline(line, lineno) - # new value - if name is not None and data is not None: - result.append((lineno, section, name, data)) - # new section - elif name is not None and data is None: - if not name: - self._raise(lineno, 'empty section name') - section = name - result.append((lineno, section, None, None)) - # continuation - elif name is None and data is not None: - if not result: - self._raise(lineno, 'unexpected value continuation') - last = result.pop() - last_name, last_data = last[-2:] - if last_name is None: - self._raise(lineno, 'unexpected value continuation') - - if last_data: - data = '%s\n%s' % (last_data, data) - result.append(last[:-1] + (data,)) - return result - - def _parseline(self, line, lineno): - # blank lines - if iscommentline(line): - line = "" - else: - line = line.rstrip() - if not line: - return None, None - # section - if line[0] == '[': - realline = line - for c in COMMENTCHARS: - line = line.split(c)[0].rstrip() - if line[-1] == "]": - return line[1:-1], None - return None, realline.strip() - # value - elif not line[0].isspace(): - try: - name, value = line.split('=', 1) - if ":" in name: - raise ValueError() - except ValueError: - try: - name, value = line.split(":", 1) - except ValueError: - self._raise(lineno, 'unexpected line: %r' % line) - return name.strip(), value.strip() - # continuation - else: - return None, line.strip() - - def lineof(self, section, name=None): - lineno = self._sources.get((section, name)) - if lineno is not None: - return lineno + 1 - - def get(self, section, name, default=None, convert=str): - try: - return convert(self.sections[section][name]) - except KeyError: - return default - - def __getitem__(self, name): - if name not in self.sections: - raise KeyError(name) - return SectionWrapper(self, name) - - def __iter__(self): - for name in sorted(self.sections, key=self.lineof): - yield SectionWrapper(self, name) - - def __contains__(self, arg): - return arg in self.sections - - -def iscommentline(line): - c = line.lstrip()[:1] - return c in COMMENTCHARS + try: + tokens = self._parse(iter(f)) + finally: + f.close() + else: + tokens = self._parse(data.splitlines(True)) + + self._sources = {} + self.sections = {} + + for lineno, section, name, value in tokens: + if section is None: + self._raise(lineno, 'no section header defined') + self._sources[section, name] = lineno + if name is None: + if section in self.sections: + self._raise(lineno, 'duplicate section %r' % (section, )) + self.sections[section] = {} + else: + if name in self.sections[section]: + self._raise(lineno, 'duplicate name %r' % (name, )) + self.sections[section][name] = value + + def _raise(self, lineno, msg): + raise ParseError(self.path, lineno, msg) + + def _parse(self, line_iter): + result = [] + section = None + for lineno, line in enumerate(line_iter): + name, data = self._parseline(line, lineno) + # new value + if name is not None and data is not None: + result.append((lineno, section, name, data)) + # new section + elif name is not None and data is None: + if not name: + self._raise(lineno, 'empty section name') + section = name + result.append((lineno, section, None, None)) + # continuation + elif name is None and data is not None: + if not result: + self._raise(lineno, 'unexpected value continuation') + last = result.pop() + last_name, last_data = last[-2:] + if last_name is None: + self._raise(lineno, 'unexpected value continuation') + + if last_data: + data = '%s\n%s' % (last_data, data) + result.append(last[:-1] + (data,)) + return result + + def _parseline(self, line, lineno): + # blank lines + if iscommentline(line): + line = "" + else: + line = line.rstrip() + if not line: + return None, None + # section + if line[0] == '[': + realline = line + for c in COMMENTCHARS: + line = line.split(c)[0].rstrip() + if line[-1] == "]": + return line[1:-1], None + return None, realline.strip() + # value + elif not line[0].isspace(): + try: + name, value = line.split('=', 1) + if ":" in name: + raise ValueError() + except ValueError: + try: + name, value = line.split(":", 1) + except ValueError: + self._raise(lineno, 'unexpected line: %r' % line) + return name.strip(), value.strip() + # continuation + else: + return None, line.strip() + + def lineof(self, section, name=None): + lineno = self._sources.get((section, name)) + if lineno is not None: + return lineno + 1 + + def get(self, section, name, default=None, convert=str): + try: + return convert(self.sections[section][name]) + except KeyError: + return default + + def __getitem__(self, name): + if name not in self.sections: + raise KeyError(name) + return SectionWrapper(self, name) + + def __iter__(self): + for name in sorted(self.sections, key=self.lineof): + yield SectionWrapper(self, name) + + def __contains__(self, arg): + return arg in self.sections + + +def iscommentline(line): + c = line.lstrip()[:1] + return c in COMMENTCHARS diff --git a/contrib/python/py/py/_version.py b/contrib/python/py/py/_version.py index 8e00d52a10..3d30fbec42 100644 --- a/contrib/python/py/py/_version.py +++ b/contrib/python/py/py/_version.py @@ -1,5 +1,5 @@ -# coding: utf-8 -# file generated by setuptools_scm -# don't change, don't track in version control +# coding: utf-8 +# file generated by setuptools_scm +# don't change, don't track in version control version = '1.11.0' version_tuple = (1, 11, 0) diff --git a/contrib/python/py/py/_xmlgen.py b/contrib/python/py/py/_xmlgen.py index 0831a9926e..1c83545884 100644 --- a/contrib/python/py/py/_xmlgen.py +++ b/contrib/python/py/py/_xmlgen.py @@ -74,18 +74,18 @@ class html(Namespace): __tagclass__ = HtmlTag __stickyname__ = True __tagspec__ = dict([(x,1) for x in ( - 'a,abbr,acronym,address,applet,area,article,aside,audio,b,' - 'base,basefont,bdi,bdo,big,blink,blockquote,body,br,button,' - 'canvas,caption,center,cite,code,col,colgroup,command,comment,' - 'datalist,dd,del,details,dfn,dir,div,dl,dt,em,embed,' - 'fieldset,figcaption,figure,footer,font,form,frame,frameset,h1,' - 'h2,h3,h4,h5,h6,head,header,hgroup,hr,html,i,iframe,img,input,' - 'ins,isindex,kbd,keygen,label,legend,li,link,listing,map,mark,' - 'marquee,menu,meta,meter,multicol,nav,nobr,noembed,noframes,' - 'noscript,object,ol,optgroup,option,output,p,param,pre,progress,' - 'q,rp,rt,ruby,s,samp,script,section,select,small,source,span,' - 'strike,strong,style,sub,summary,sup,table,tbody,td,textarea,' - 'tfoot,th,thead,time,title,tr,track,tt,u,ul,xmp,var,video,wbr' + 'a,abbr,acronym,address,applet,area,article,aside,audio,b,' + 'base,basefont,bdi,bdo,big,blink,blockquote,body,br,button,' + 'canvas,caption,center,cite,code,col,colgroup,command,comment,' + 'datalist,dd,del,details,dfn,dir,div,dl,dt,em,embed,' + 'fieldset,figcaption,figure,footer,font,form,frame,frameset,h1,' + 'h2,h3,h4,h5,h6,head,header,hgroup,hr,html,i,iframe,img,input,' + 'ins,isindex,kbd,keygen,label,legend,li,link,listing,map,mark,' + 'marquee,menu,meta,meter,multicol,nav,nobr,noembed,noframes,' + 'noscript,object,ol,optgroup,option,output,p,param,pre,progress,' + 'q,rp,rt,ruby,s,samp,script,section,select,small,source,span,' + 'strike,strong,style,sub,summary,sup,table,tbody,td,textarea,' + 'tfoot,th,thead,time,title,tr,track,tt,u,ul,xmp,var,video,wbr' ).split(',') if x]) class Style(object): diff --git a/contrib/python/py/ya.make b/contrib/python/py/ya.make index 870b852488..cc86cb7fa9 100644 --- a/contrib/python/py/ya.make +++ b/contrib/python/py/ya.make @@ -30,7 +30,7 @@ PY_SRCS( py/_code/source.py py/_error.py py/_io/__init__.py - py/_io/capture.py + py/_io/capture.py py/_io/saferepr.py py/_io/terminalwriter.py py/_log/__init__.py @@ -47,12 +47,12 @@ PY_SRCS( py/_process/forkedfunc.py py/_process/killproc.py py/_std.py - py/_vendored_packages/__init__.py + py/_vendored_packages/__init__.py py/_vendored_packages/apipkg/__init__.py py/_vendored_packages/apipkg/version.py py/_vendored_packages/iniconfig/__init__.py py/_vendored_packages/iniconfig/__init__.pyi - py/_version.py + py/_version.py py/_xmlgen.py py/error.pyi py/iniconfig.pyi |