diff options
author | Nikita Slyusarev <nslus@yandex-team.com> | 2022-02-10 16:46:52 +0300 |
---|---|---|
committer | Daniil Cherednik <dcherednik@yandex-team.ru> | 2022-02-10 16:46:52 +0300 |
commit | cd77cecfc03a3eaf87816af28a33067c4f0cdb59 (patch) | |
tree | 1308e0bae862d52e0020d881fe758080437fe389 /contrib/python/ipython/py2/IPython/utils | |
parent | cdae02d225fb5b3afbb28990e79a7ac6c9125327 (diff) | |
download | ydb-cd77cecfc03a3eaf87816af28a33067c4f0cdb59.tar.gz |
Restoring authorship annotation for Nikita Slyusarev <nslus@yandex-team.com>. Commit 1 of 2.
Diffstat (limited to 'contrib/python/ipython/py2/IPython/utils')
12 files changed, 191 insertions, 191 deletions
diff --git a/contrib/python/ipython/py2/IPython/utils/PyColorize.py b/contrib/python/ipython/py2/IPython/utils/PyColorize.py index 124eb2d4e3c..66d52f34ddf 100644 --- a/contrib/python/ipython/py2/IPython/utils/PyColorize.py +++ b/contrib/python/ipython/py2/IPython/utils/PyColorize.py @@ -54,8 +54,8 @@ except AttributeError: from IPython.utils.coloransi import TermColors, InputTermColors ,ColorScheme, ColorSchemeTable from IPython.utils.py3compat import PY3 -from .colorable import Colorable - +from .colorable import Colorable + if PY3: from io import StringIO else: @@ -122,40 +122,40 @@ LinuxColors = ColorScheme( 'normal' : Colors.Normal # color off (usu. Colors.Normal) } ) -NeutralColors = ColorScheme( - 'Neutral',{ - 'header' : Colors.Red, - token.NUMBER : Colors.Cyan, - token.OP : Colors.Blue, - token.STRING : Colors.Blue, - tokenize.COMMENT : Colors.Red, - token.NAME : Colors.Normal, - token.ERRORTOKEN : Colors.Red, - - _KEYWORD : Colors.Green, - _TEXT : Colors.Blue, - - 'in_prompt' : InputTermColors.Blue, - 'in_number' : InputTermColors.LightBlue, - 'in_prompt2' : InputTermColors.Blue, - 'in_normal' : InputTermColors.Normal, # color off (usu. Colors.Normal) - - 'out_prompt' : Colors.Red, - 'out_number' : Colors.LightRed, - - 'normal' : Colors.Normal # color off (usu. Colors.Normal) - } ) - -# Hack: the 'neutral' colours are not very visible on a dark background on -# Windows. Since Windows command prompts have a dark background by default, and -# relatively few users are likely to alter that, we will use the 'Linux' colours, -# designed for a dark background, as the default on Windows. Changing it here -# avoids affecting the prompt colours rendered by prompt_toolkit, where the -# neutral defaults do work OK. - -if os.name == 'nt': - NeutralColors = LinuxColors.copy(name='Neutral') - +NeutralColors = ColorScheme( + 'Neutral',{ + 'header' : Colors.Red, + token.NUMBER : Colors.Cyan, + token.OP : Colors.Blue, + token.STRING : Colors.Blue, + tokenize.COMMENT : Colors.Red, + token.NAME : Colors.Normal, + token.ERRORTOKEN : Colors.Red, + + _KEYWORD : Colors.Green, + _TEXT : Colors.Blue, + + 'in_prompt' : InputTermColors.Blue, + 'in_number' : InputTermColors.LightBlue, + 'in_prompt2' : InputTermColors.Blue, + 'in_normal' : InputTermColors.Normal, # color off (usu. Colors.Normal) + + 'out_prompt' : Colors.Red, + 'out_number' : Colors.LightRed, + + 'normal' : Colors.Normal # color off (usu. Colors.Normal) + } ) + +# Hack: the 'neutral' colours are not very visible on a dark background on +# Windows. Since Windows command prompts have a dark background by default, and +# relatively few users are likely to alter that, we will use the 'Linux' colours, +# designed for a dark background, as the default on Windows. Changing it here +# avoids affecting the prompt colours rendered by prompt_toolkit, where the +# neutral defaults do work OK. + +if os.name == 'nt': + NeutralColors = LinuxColors.copy(name='Neutral') + LightBGColors = ColorScheme( 'LightBG',{ 'header' : Colors.Red, @@ -166,7 +166,7 @@ LightBGColors = ColorScheme( token.NAME : Colors.Normal, token.ERRORTOKEN : Colors.Red, - + _KEYWORD : Colors.Green, _TEXT : Colors.Blue, @@ -182,21 +182,21 @@ LightBGColors = ColorScheme( } ) # Build table of color schemes (needed by the parser) -ANSICodeColors = ColorSchemeTable([NoColor,LinuxColors,LightBGColors, NeutralColors], +ANSICodeColors = ColorSchemeTable([NoColor,LinuxColors,LightBGColors, NeutralColors], _scheme_default) -class Parser(Colorable): +class Parser(Colorable): """ Format colored Python source. """ - def __init__(self, color_table=None, out = sys.stdout, parent=None, style=None): + def __init__(self, color_table=None, out = sys.stdout, parent=None, style=None): """ Create a parser with a specified color table and output channel. Call format() to process code. """ - - super(Parser, self).__init__(parent=parent) - + + super(Parser, self).__init__(parent=parent) + self.color_table = color_table and color_table or ANSICodeColors self.out = out diff --git a/contrib/python/ipython/py2/IPython/utils/_process_common.py b/contrib/python/ipython/py2/IPython/utils/_process_common.py index 9ede30d3f8a..e1b305f7349 100644 --- a/contrib/python/ipython/py2/IPython/utils/_process_common.py +++ b/contrib/python/ipython/py2/IPython/utils/_process_common.py @@ -17,7 +17,7 @@ of subprocess utilities, and it contains tools that are common to all of them. import subprocess import shlex import sys -import os +import os from IPython.utils import py3compat @@ -70,14 +70,14 @@ def process_handler(cmd, callback, stderr=subprocess.PIPE): sys.stderr.flush() # On win32, close_fds can't be true when using pipes for stdin/out/err close_fds = sys.platform != 'win32' - # Determine if cmd should be run with system shell. - shell = isinstance(cmd, py3compat.string_types) - # On POSIX systems run shell commands with user-preferred shell. - executable = None - if shell and os.name == 'posix' and 'SHELL' in os.environ: - executable = os.environ['SHELL'] - p = subprocess.Popen(cmd, shell=shell, - executable=executable, + # Determine if cmd should be run with system shell. + shell = isinstance(cmd, py3compat.string_types) + # On POSIX systems run shell commands with user-preferred shell. + executable = None + if shell and os.name == 'posix' and 'SHELL' in os.environ: + executable = os.environ['SHELL'] + p = subprocess.Popen(cmd, shell=shell, + executable=executable, stdin=subprocess.PIPE, stdout=subprocess.PIPE, stderr=stderr, diff --git a/contrib/python/ipython/py2/IPython/utils/colorable.py b/contrib/python/ipython/py2/IPython/utils/colorable.py index 9f7c5ac213c..1d5b6b4abee 100644 --- a/contrib/python/ipython/py2/IPython/utils/colorable.py +++ b/contrib/python/ipython/py2/IPython/utils/colorable.py @@ -1,26 +1,26 @@ -#***************************************************************************** -# Copyright (C) 2016 The IPython Team <ipython-dev@scipy.org> -# -# Distributed under the terms of the BSD License. The full license is in -# the file COPYING, distributed as part of this software. -#***************************************************************************** -from __future__ import absolute_import - -""" -Color managing related utilities -""" - -import pygments - -from traitlets.config import Configurable -from traitlets import Unicode - - -available_themes = lambda : [s for s in pygments.styles.get_all_styles()]+['NoColor','LightBG','Linux', 'Neutral'] - -class Colorable(Configurable): - """ - A subclass of configurable for all the classes that have a `default_scheme` - """ - default_style=Unicode('lightbg').tag(config=True) - +#***************************************************************************** +# Copyright (C) 2016 The IPython Team <ipython-dev@scipy.org> +# +# Distributed under the terms of the BSD License. The full license is in +# the file COPYING, distributed as part of this software. +#***************************************************************************** +from __future__ import absolute_import + +""" +Color managing related utilities +""" + +import pygments + +from traitlets.config import Configurable +from traitlets import Unicode + + +available_themes = lambda : [s for s in pygments.styles.get_all_styles()]+['NoColor','LightBG','Linux', 'Neutral'] + +class Colorable(Configurable): + """ + A subclass of configurable for all the classes that have a `default_scheme` + """ + default_style=Unicode('lightbg').tag(config=True) + diff --git a/contrib/python/ipython/py2/IPython/utils/contexts.py b/contrib/python/ipython/py2/IPython/utils/contexts.py index 4d379b0eda1..14f4b47ba6c 100644 --- a/contrib/python/ipython/py2/IPython/utils/contexts.py +++ b/contrib/python/ipython/py2/IPython/utils/contexts.py @@ -2,8 +2,8 @@ """Miscellaneous context managers. """ -import warnings - +import warnings + # Copyright (c) IPython Development Team. # Distributed under the terms of the Modified BSD License. @@ -61,14 +61,14 @@ class preserve_keys(object): class NoOpContext(object): - """ - Deprecated - - Context manager that does nothing.""" - - def __init__(self): - warnings.warn("""NoOpContext is deprecated since IPython 5.0 """, - DeprecationWarning, stacklevel=2) - + """ + Deprecated + + Context manager that does nothing.""" + + def __init__(self): + warnings.warn("""NoOpContext is deprecated since IPython 5.0 """, + DeprecationWarning, stacklevel=2) + def __enter__(self): pass def __exit__(self, type, value, traceback): pass diff --git a/contrib/python/ipython/py2/IPython/utils/dir2.py b/contrib/python/ipython/py2/IPython/utils/dir2.py index f6f164f9b12..352c079178e 100644 --- a/contrib/python/ipython/py2/IPython/utils/dir2.py +++ b/contrib/python/ipython/py2/IPython/utils/dir2.py @@ -2,10 +2,10 @@ """A fancy version of Python's builtin :func:`dir` function. """ -# Copyright (c) IPython Development Team. -# Distributed under the terms of the Modified BSD License. +# Copyright (c) IPython Development Team. +# Distributed under the terms of the Modified BSD License. -import inspect +import inspect from .py3compat import string_types @@ -46,36 +46,36 @@ def dir2(obj): words = [w for w in words if isinstance(w, string_types)] return sorted(words) - - -def get_real_method(obj, name): - """Like getattr, but with a few extra sanity checks: - - - If obj is a class, ignore its methods - - Check if obj is a proxy that claims to have all attributes - - Catch attribute access failing with any exception - - Check that the attribute is a callable object - - Returns the method or None. - """ - if inspect.isclass(obj): - return None - - try: - canary = getattr(obj, '_ipython_canary_method_should_not_exist_', None) - except Exception: - return None - - if canary is not None: - # It claimed to have an attribute it should never have - return None - - try: - m = getattr(obj, name, None) - except Exception: - return None - - if callable(m): - return m - - return None + + +def get_real_method(obj, name): + """Like getattr, but with a few extra sanity checks: + + - If obj is a class, ignore its methods + - Check if obj is a proxy that claims to have all attributes + - Catch attribute access failing with any exception + - Check that the attribute is a callable object + + Returns the method or None. + """ + if inspect.isclass(obj): + return None + + try: + canary = getattr(obj, '_ipython_canary_method_should_not_exist_', None) + except Exception: + return None + + if canary is not None: + # It claimed to have an attribute it should never have + return None + + try: + m = getattr(obj, name, None) + except Exception: + return None + + if callable(m): + return m + + return None diff --git a/contrib/python/ipython/py2/IPython/utils/io.py b/contrib/python/ipython/py2/IPython/utils/io.py index 036d6e3926a..817ecff2789 100644 --- a/contrib/python/ipython/py2/IPython/utils/io.py +++ b/contrib/python/ipython/py2/IPython/utils/io.py @@ -14,19 +14,19 @@ import atexit import os import sys import tempfile -import warnings +import warnings from warnings import warn - -from IPython.utils.decorators import undoc + +from IPython.utils.decorators import undoc from .capture import CapturedIO, capture_output from .py3compat import string_types, input, PY3 -@undoc +@undoc class IOStream: - def __init__(self, stream, fallback=None): - warn('IOStream is deprecated since IPython 5.0, use sys.{stdin,stdout,stderr} instead', - DeprecationWarning, stacklevel=2) + def __init__(self, stream, fallback=None): + warn('IOStream is deprecated since IPython 5.0, use sys.{stdin,stdout,stderr} instead', + DeprecationWarning, stacklevel=2) if not hasattr(stream,'write') or not hasattr(stream,'flush'): if fallback is not None: stream = fallback @@ -52,8 +52,8 @@ class IOStream: return tpl.format(mod=cls.__module__, cls=cls.__name__, args=self.stream) def write(self,data): - warn('IOStream is deprecated since IPython 5.0, use sys.{stdin,stdout,stderr} instead', - DeprecationWarning, stacklevel=2) + warn('IOStream is deprecated since IPython 5.0, use sys.{stdin,stdout,stderr} instead', + DeprecationWarning, stacklevel=2) try: self._swrite(data) except: @@ -68,8 +68,8 @@ class IOStream: file=sys.stderr) def writelines(self, lines): - warn('IOStream is deprecated since IPython 5.0, use sys.{stdin,stdout,stderr} instead', - DeprecationWarning, stacklevel=2) + warn('IOStream is deprecated since IPython 5.0, use sys.{stdin,stdout,stderr} instead', + DeprecationWarning, stacklevel=2) if isinstance(lines, string_types): lines = [lines] for line in lines: @@ -87,17 +87,17 @@ class IOStream: pass # setup stdin/stdout/stderr to sys.stdin/sys.stdout/sys.stderr -devnull = open(os.devnull, 'w') +devnull = open(os.devnull, 'w') atexit.register(devnull.close) -# io.std* are deprecated, but don't show our own deprecation warnings -# during initialization of the deprecated API. -with warnings.catch_warnings(): - warnings.simplefilter('ignore', DeprecationWarning) - stdin = IOStream(sys.stdin, fallback=devnull) - stdout = IOStream(sys.stdout, fallback=devnull) - stderr = IOStream(sys.stderr, fallback=devnull) - +# io.std* are deprecated, but don't show our own deprecation warnings +# during initialization of the deprecated API. +with warnings.catch_warnings(): + warnings.simplefilter('ignore', DeprecationWarning) + stdin = IOStream(sys.stdin, fallback=devnull) + stdout = IOStream(sys.stdout, fallback=devnull) + stderr = IOStream(sys.stderr, fallback=devnull) + class Tee(object): """A class to duplicate an output stream to stdout/err. diff --git a/contrib/python/ipython/py2/IPython/utils/path.py b/contrib/python/ipython/py2/IPython/utils/path.py index fa850812c7f..f7b76666421 100644 --- a/contrib/python/ipython/py2/IPython/utils/path.py +++ b/contrib/python/ipython/py2/IPython/utils/path.py @@ -72,21 +72,21 @@ def get_long_path_name(path): def unquote_filename(name, win32=(sys.platform=='win32')): """ On Windows, remove leading and trailing quotes from filenames. - - This function has been deprecated and should not be used any more: - unquoting is now taken care of by :func:`IPython.utils.process.arg_split`. + + This function has been deprecated and should not be used any more: + unquoting is now taken care of by :func:`IPython.utils.process.arg_split`. """ - warn("'unquote_filename' is deprecated since IPython 5.0 and should not " + warn("'unquote_filename' is deprecated since IPython 5.0 and should not " "be used anymore", DeprecationWarning, stacklevel=2) if win32: if name.startswith(("'", '"')) and name.endswith(("'", '"')): name = name[1:-1] return name - + def compress_user(path): """Reverse of :func:`os.path.expanduser` - """ + """ path = py3compat.unicode_to_str(path, sys.getfilesystemencoding()) home = os.path.expanduser('~') if path.startswith(home): @@ -101,9 +101,9 @@ def get_py_filename(name, force_win32=None): """ name = os.path.expanduser(name) - if force_win32 is not None: - warn("The 'force_win32' argument to 'get_py_filename' is deprecated " - "since IPython 5.0 and should not be used anymore", + if force_win32 is not None: + warn("The 'force_win32' argument to 'get_py_filename' is deprecated " + "since IPython 5.0 and should not be used anymore", DeprecationWarning, stacklevel=2) if not os.path.isfile(name) and not name.endswith('.py'): name += '.py' diff --git a/contrib/python/ipython/py2/IPython/utils/py3compat.py b/contrib/python/ipython/py2/IPython/utils/py3compat.py index 88602e5342d..4d370545595 100644 --- a/contrib/python/ipython/py2/IPython/utils/py3compat.py +++ b/contrib/python/ipython/py2/IPython/utils/py3compat.py @@ -6,7 +6,7 @@ import sys import re import shutil import types -import platform +import platform from .encoding import DEFAULT_ENCODING @@ -293,7 +293,7 @@ else: PY2 = not PY3 -PYPY = platform.python_implementation() == "PyPy" +PYPY = platform.python_implementation() == "PyPy" def annotate(**kwargs): diff --git a/contrib/python/ipython/py2/IPython/utils/terminal.py b/contrib/python/ipython/py2/IPython/utils/terminal.py index e92c410c79f..397a3e86fb1 100644 --- a/contrib/python/ipython/py2/IPython/utils/terminal.py +++ b/contrib/python/ipython/py2/IPython/utils/terminal.py @@ -11,16 +11,16 @@ Authors: from __future__ import absolute_import -# Copyright (c) IPython Development Team. -# Distributed under the terms of the Modified BSD License. +# Copyright (c) IPython Development Team. +# Distributed under the terms of the Modified BSD License. import os import sys import warnings -try: - from shutil import get_terminal_size as _get_terminal_size -except ImportError: - # use backport on Python 2 +try: + from shutil import get_terminal_size as _get_terminal_size +except ImportError: + # use backport on Python 2 try: from backports.shutil_get_terminal_size import get_terminal_size as _get_terminal_size except ImportError: @@ -121,5 +121,5 @@ def freeze_term_title(): ignore_termtitle = True -def get_terminal_size(defaultx=80, defaulty=25): - return _get_terminal_size((defaultx, defaulty)) +def get_terminal_size(defaultx=80, defaulty=25): + return _get_terminal_size((defaultx, defaulty)) diff --git a/contrib/python/ipython/py2/IPython/utils/text.py b/contrib/python/ipython/py2/IPython/utils/text.py index 5ed1a845e35..63588fb3223 100644 --- a/contrib/python/ipython/py2/IPython/utils/text.py +++ b/contrib/python/ipython/py2/IPython/utils/text.py @@ -14,11 +14,11 @@ import re import sys import textwrap from string import Formatter -try: - from pathlib import Path -except ImportError: - # Python 2 backport - from pathlib2 import Path +try: + from pathlib import Path +except ImportError: + # Python 2 backport + from pathlib2 import Path from IPython.testing.skipdoctest import skip_doctest_py3, skip_doctest from IPython.utils import py3compat @@ -72,7 +72,7 @@ class LSString(str): try: return self.__paths except AttributeError: - self.__paths = [Path(p) for p in self.split('\n') if os.path.exists(p)] + self.__paths = [Path(p) for p in self.split('\n') if os.path.exists(p)] return self.__paths p = paths = property(get_paths) @@ -130,7 +130,7 @@ class SList(list): try: return self.__paths except AttributeError: - self.__paths = [Path(p) for p in self if os.path.exists(p)] + self.__paths = [Path(p) for p in self if os.path.exists(p)] return self.__paths p = paths = property(get_paths) diff --git a/contrib/python/ipython/py2/IPython/utils/tokenutil.py b/contrib/python/ipython/py2/IPython/utils/tokenutil.py index f52d3b76583..e01f5e7b324 100644 --- a/contrib/python/ipython/py2/IPython/utils/tokenutil.py +++ b/contrib/python/ipython/py2/IPython/utils/tokenutil.py @@ -31,7 +31,7 @@ def line_at_cursor(cell, cursor_pos=0): Parameters ---------- - cell: str + cell: str multiline block of text cursor_pos: integer the cursor position diff --git a/contrib/python/ipython/py2/IPython/utils/warn.py b/contrib/python/ipython/py2/IPython/utils/warn.py index dd4852227ba..ae5424a0389 100644 --- a/contrib/python/ipython/py2/IPython/utils/warn.py +++ b/contrib/python/ipython/py2/IPython/utils/warn.py @@ -9,17 +9,17 @@ Utilities for warnings. Shoudn't we just use the built in warnings module. from __future__ import print_function import sys -import warnings +import warnings -warnings.warn("The module IPython.utils.warn is deprecated since IPython 4.0, use the standard warnings module instead", DeprecationWarning) +warnings.warn("The module IPython.utils.warn is deprecated since IPython 4.0, use the standard warnings module instead", DeprecationWarning) def warn(msg,level=2,exit_val=1): - """Deprecated - - Standard warning printer. Gives formatting consistency. + """Deprecated - Output is sent to sys.stderr. + Standard warning printer. Gives formatting consistency. + Output is sent to sys.stderr. + Options: -level(2): allows finer control: @@ -31,35 +31,35 @@ def warn(msg,level=2,exit_val=1): -exit_val (1): exit value returned by sys.exit() for a level 4 warning. Ignored for all other levels.""" - - warnings.warn("The module IPython.utils.warn is deprecated since IPython 4.0, use the standard warnings module instead", DeprecationWarning) + + warnings.warn("The module IPython.utils.warn is deprecated since IPython 4.0, use the standard warnings module instead", DeprecationWarning) if level>0: header = ['','','WARNING: ','ERROR: ','FATAL ERROR: '] - print(header[level], msg, sep='', file=sys.stderr) + print(header[level], msg, sep='', file=sys.stderr) if level == 4: - print('Exiting.\n', file=sys.stderr) + print('Exiting.\n', file=sys.stderr) sys.exit(exit_val) def info(msg): - """Deprecated - - Equivalent to warn(msg,level=1).""" + """Deprecated + + Equivalent to warn(msg,level=1).""" warn(msg,level=1) def error(msg): - """Deprecated - - Equivalent to warn(msg,level=3).""" + """Deprecated + + Equivalent to warn(msg,level=3).""" warn(msg,level=3) def fatal(msg,exit_val=1): - """Deprecated - - Equivalent to warn(msg,exit_val=exit_val,level=4).""" + """Deprecated + + Equivalent to warn(msg,exit_val=exit_val,level=4).""" warn(msg,exit_val=exit_val,level=4) |