aboutsummaryrefslogtreecommitdiffstats
path: root/contrib/python/ipython/py2/IPython/utils
diff options
context:
space:
mode:
authorsmosker <smosker@yandex-team.ru>2022-02-10 16:48:22 +0300
committerDaniil Cherednik <dcherednik@yandex-team.ru>2022-02-10 16:48:22 +0300
commit01fa2667d0e5e868b18424bc1906146e5ee340db (patch)
tree5d5cb817648f650d76cf1076100726fd9b8448e8 /contrib/python/ipython/py2/IPython/utils
parentdd14d17a747a9c259858faf2fcc3ea6b92df4e15 (diff)
downloadydb-01fa2667d0e5e868b18424bc1906146e5ee340db.tar.gz
Restoring authorship annotation for <smosker@yandex-team.ru>. Commit 2 of 2.
Diffstat (limited to 'contrib/python/ipython/py2/IPython/utils')
-rw-r--r--contrib/python/ipython/py2/IPython/utils/_get_terminal_size.py262
-rw-r--r--contrib/python/ipython/py2/IPython/utils/_signatures.py8
-rw-r--r--contrib/python/ipython/py2/IPython/utils/capture.py72
-rw-r--r--contrib/python/ipython/py2/IPython/utils/io.py12
-rw-r--r--contrib/python/ipython/py2/IPython/utils/path.py16
-rw-r--r--contrib/python/ipython/py2/IPython/utils/terminal.py12
6 files changed, 191 insertions, 191 deletions
diff --git a/contrib/python/ipython/py2/IPython/utils/_get_terminal_size.py b/contrib/python/ipython/py2/IPython/utils/_get_terminal_size.py
index 31eef93abd..b2c989e7aa 100644
--- a/contrib/python/ipython/py2/IPython/utils/_get_terminal_size.py
+++ b/contrib/python/ipython/py2/IPython/utils/_get_terminal_size.py
@@ -1,131 +1,131 @@
-# vendored version of backports.get_terminal_size as nemesapece package are a
-# mess and break, especially on ubuntu. This file is under MIT Licence.
-# See https://pypi.python.org/pypi/backports.shutil_get_terminal_size
-#
-# commit: afc5714b1545a5a3aa44cfb5e078d39165bf76ab (Feb 20, 2016)
-# from
-# https://github.com/chrippa/backports.shutil_get_terminal_size
-#
-# The MIT License (MIT)
-#
-# Copyright (c) 2014 Christopher Rosell
-#
-# Permission is hereby granted, free of charge, to any person obtaining a copy
-# of this software and associated documentation files (the "Software"), to deal
-# in the Software without restriction, including without limitation the rights
-# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
-# copies of the Software, and to permit persons to whom the Software is
-# furnished to do so, subject to the following conditions:
-#
-# The above copyright notice and this permission notice shall be included in
-# all copies or substantial portions of the Software.
-#
-# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
-# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
-# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
-# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
-# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
-# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
-# THE SOFTWARE.
-#
-"""This is a backport of shutil.get_terminal_size from Python 3.3.
-
-The original implementation is in C, but here we use the ctypes and
-fcntl modules to create a pure Python version of os.get_terminal_size.
-"""
-
-import os
-import struct
-import sys
-
-from collections import namedtuple
-
-__all__ = ["get_terminal_size"]
-
-
-terminal_size = namedtuple("terminal_size", "columns lines")
-
-try:
- from ctypes import windll, create_string_buffer, WinError
-
- _handle_ids = {
- 0: -10,
- 1: -11,
- 2: -12,
- }
-
- def _get_terminal_size(fd):
- handle = windll.kernel32.GetStdHandle(_handle_ids[fd])
- if handle == 0:
- raise OSError('handle cannot be retrieved')
- if handle == -1:
- raise WinError()
- csbi = create_string_buffer(22)
- res = windll.kernel32.GetConsoleScreenBufferInfo(handle, csbi)
- if res:
- res = struct.unpack("hhhhHhhhhhh", csbi.raw)
- left, top, right, bottom = res[5:9]
- columns = right - left + 1
- lines = bottom - top + 1
- return terminal_size(columns, lines)
- else:
- raise WinError()
-
-except ImportError:
- import fcntl
- import termios
-
- def _get_terminal_size(fd):
- try:
- res = fcntl.ioctl(fd, termios.TIOCGWINSZ, b"\x00" * 4)
- except IOError as e:
- raise OSError(e)
- lines, columns = struct.unpack("hh", res)
-
- return terminal_size(columns, lines)
-
-
-def get_terminal_size(fallback=(80, 24)):
- """Get the size of the terminal window.
-
- For each of the two dimensions, the environment variable, COLUMNS
- and LINES respectively, is checked. If the variable is defined and
- the value is a positive integer, it is used.
-
- When COLUMNS or LINES is not defined, which is the common case,
- the terminal connected to sys.__stdout__ is queried
- by invoking os.get_terminal_size.
-
- If the terminal size cannot be successfully queried, either because
- the system doesn't support querying, or because we are not
- connected to a terminal, the value given in fallback parameter
- is used. Fallback defaults to (80, 24) which is the default
- size used by many terminal emulators.
-
- The value returned is a named tuple of type os.terminal_size.
- """
- # Try the environment first
- try:
- columns = int(os.environ["COLUMNS"])
- except (KeyError, ValueError):
- columns = 0
-
- try:
- lines = int(os.environ["LINES"])
- except (KeyError, ValueError):
- lines = 0
-
- # Only query if necessary
- if columns <= 0 or lines <= 0:
- try:
- size = _get_terminal_size(sys.__stdout__.fileno())
- except (NameError, OSError):
- size = terminal_size(*fallback)
-
- if columns <= 0:
- columns = size.columns
- if lines <= 0:
- lines = size.lines
-
- return terminal_size(columns, lines)
-
+# vendored version of backports.get_terminal_size as nemesapece package are a
+# mess and break, especially on ubuntu. This file is under MIT Licence.
+# See https://pypi.python.org/pypi/backports.shutil_get_terminal_size
+#
+# commit: afc5714b1545a5a3aa44cfb5e078d39165bf76ab (Feb 20, 2016)
+# from
+# https://github.com/chrippa/backports.shutil_get_terminal_size
+#
+# The MIT License (MIT)
+#
+# Copyright (c) 2014 Christopher Rosell
+#
+# Permission is hereby granted, free of charge, to any person obtaining a copy
+# of this software and associated documentation files (the "Software"), to deal
+# in the Software without restriction, including without limitation the rights
+# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+# copies of the Software, and to permit persons to whom the Software is
+# furnished to do so, subject to the following conditions:
+#
+# The above copyright notice and this permission notice shall be included in
+# all copies or substantial portions of the Software.
+#
+# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
+# THE SOFTWARE.
+#
+"""This is a backport of shutil.get_terminal_size from Python 3.3.
+
+The original implementation is in C, but here we use the ctypes and
+fcntl modules to create a pure Python version of os.get_terminal_size.
+"""
+
+import os
+import struct
+import sys
+
+from collections import namedtuple
+
+__all__ = ["get_terminal_size"]
+
+
+terminal_size = namedtuple("terminal_size", "columns lines")
+
+try:
+ from ctypes import windll, create_string_buffer, WinError
+
+ _handle_ids = {
+ 0: -10,
+ 1: -11,
+ 2: -12,
+ }
+
+ def _get_terminal_size(fd):
+ handle = windll.kernel32.GetStdHandle(_handle_ids[fd])
+ if handle == 0:
+ raise OSError('handle cannot be retrieved')
+ if handle == -1:
+ raise WinError()
+ csbi = create_string_buffer(22)
+ res = windll.kernel32.GetConsoleScreenBufferInfo(handle, csbi)
+ if res:
+ res = struct.unpack("hhhhHhhhhhh", csbi.raw)
+ left, top, right, bottom = res[5:9]
+ columns = right - left + 1
+ lines = bottom - top + 1
+ return terminal_size(columns, lines)
+ else:
+ raise WinError()
+
+except ImportError:
+ import fcntl
+ import termios
+
+ def _get_terminal_size(fd):
+ try:
+ res = fcntl.ioctl(fd, termios.TIOCGWINSZ, b"\x00" * 4)
+ except IOError as e:
+ raise OSError(e)
+ lines, columns = struct.unpack("hh", res)
+
+ return terminal_size(columns, lines)
+
+
+def get_terminal_size(fallback=(80, 24)):
+ """Get the size of the terminal window.
+
+ For each of the two dimensions, the environment variable, COLUMNS
+ and LINES respectively, is checked. If the variable is defined and
+ the value is a positive integer, it is used.
+
+ When COLUMNS or LINES is not defined, which is the common case,
+ the terminal connected to sys.__stdout__ is queried
+ by invoking os.get_terminal_size.
+
+ If the terminal size cannot be successfully queried, either because
+ the system doesn't support querying, or because we are not
+ connected to a terminal, the value given in fallback parameter
+ is used. Fallback defaults to (80, 24) which is the default
+ size used by many terminal emulators.
+
+ The value returned is a named tuple of type os.terminal_size.
+ """
+ # Try the environment first
+ try:
+ columns = int(os.environ["COLUMNS"])
+ except (KeyError, ValueError):
+ columns = 0
+
+ try:
+ lines = int(os.environ["LINES"])
+ except (KeyError, ValueError):
+ lines = 0
+
+ # Only query if necessary
+ if columns <= 0 or lines <= 0:
+ try:
+ size = _get_terminal_size(sys.__stdout__.fileno())
+ except (NameError, OSError):
+ size = terminal_size(*fallback)
+
+ if columns <= 0:
+ columns = size.columns
+ if lines <= 0:
+ lines = size.lines
+
+ return terminal_size(columns, lines)
+
diff --git a/contrib/python/ipython/py2/IPython/utils/_signatures.py b/contrib/python/ipython/py2/IPython/utils/_signatures.py
index 9ffab265db..20f52b98ed 100644
--- a/contrib/python/ipython/py2/IPython/utils/_signatures.py
+++ b/contrib/python/ipython/py2/IPython/utils/_signatures.py
@@ -21,7 +21,7 @@ import itertools
import functools
import re
import types
-import inspect
+import inspect
# patch for single-file
@@ -72,7 +72,7 @@ def signature(obj):
if not callable(obj):
raise TypeError('{0!r} is not a callable object'.format(obj))
- if inspect.ismethod(obj):
+ if inspect.ismethod(obj):
if obj.__self__ is None:
# Unbound method - treat it as a function (no distinction in Py 3)
obj = obj.__func__
@@ -97,7 +97,7 @@ def signature(obj):
else:
return signature(wrapped)
- if inspect.isfunction(obj):
+ if inspect.isfunction(obj):
return Signature.from_function(obj)
if isinstance(obj, functools.partial):
@@ -512,7 +512,7 @@ class Signature(object):
def from_function(cls, func):
'''Constructs Signature for the given python function'''
- if not inspect.isfunction(func):
+ if not inspect.isfunction(func):
raise TypeError('{0!r} is not a Python function'.format(func))
Parameter = cls._parameter_cls
diff --git a/contrib/python/ipython/py2/IPython/utils/capture.py b/contrib/python/ipython/py2/IPython/utils/capture.py
index e09ff5543e..d8f919568c 100644
--- a/contrib/python/ipython/py2/IPython/utils/capture.py
+++ b/contrib/python/ipython/py2/IPython/utils/capture.py
@@ -21,17 +21,17 @@ else:
class RichOutput(object):
- def __init__(self, data=None, metadata=None, transient=None, update=False):
+ def __init__(self, data=None, metadata=None, transient=None, update=False):
self.data = data or {}
self.metadata = metadata or {}
- self.transient = transient or {}
- self.update = update
-
+ self.transient = transient or {}
+ self.update = update
+
def display(self):
from IPython.display import publish_display_data
- publish_display_data(data=self.data, metadata=self.metadata,
- transient=self.transient, update=self.update)
-
+ publish_display_data(data=self.data, metadata=self.metadata,
+ transient=self.transient, update=self.update)
+
def _repr_mime_(self, mime):
if mime not in self.data:
return
@@ -43,22 +43,22 @@ class RichOutput(object):
def _repr_html_(self):
return self._repr_mime_("text/html")
-
+
def _repr_latex_(self):
return self._repr_mime_("text/latex")
-
+
def _repr_json_(self):
return self._repr_mime_("application/json")
-
+
def _repr_javascript_(self):
return self._repr_mime_("application/javascript")
-
+
def _repr_png_(self):
return self._repr_mime_("image/png")
-
+
def _repr_jpeg_(self):
return self._repr_mime_("image/jpeg")
-
+
def _repr_svg_(self):
return self._repr_mime_("image/svg+xml")
@@ -75,35 +75,35 @@ class CapturedIO(object):
Additionally, there's a ``c.show()`` method which will print all of the
above in the same order, and can be invoked simply via ``c()``.
"""
-
+
def __init__(self, stdout, stderr, outputs=None):
self._stdout = stdout
self._stderr = stderr
if outputs is None:
outputs = []
self._outputs = outputs
-
+
def __str__(self):
return self.stdout
-
+
@property
def stdout(self):
"Captured standard output"
if not self._stdout:
return ''
return self._stdout.getvalue()
-
+
@property
def stderr(self):
"Captured standard error"
if not self._stderr:
return ''
return self._stderr.getvalue()
-
+
@property
def outputs(self):
"""A list of the captured rich display outputs, if any.
-
+
If you have a CapturedIO object ``c``, these can be displayed in IPython
using::
@@ -111,17 +111,17 @@ class CapturedIO(object):
for o in c.outputs:
display(o)
"""
- return [ RichOutput(**kargs) for kargs in self._outputs ]
-
+ return [ RichOutput(**kargs) for kargs in self._outputs ]
+
def show(self):
"""write my output to sys.stdout/err as appropriate"""
sys.stdout.write(self.stdout)
sys.stderr.write(self.stderr)
sys.stdout.flush()
sys.stderr.flush()
- for kargs in self._outputs:
- RichOutput(**kargs).display()
-
+ for kargs in self._outputs:
+ RichOutput(**kargs).display()
+
__call__ = show
@@ -130,27 +130,27 @@ class capture_output(object):
stdout = True
stderr = True
display = True
-
+
def __init__(self, stdout=True, stderr=True, display=True):
self.stdout = stdout
self.stderr = stderr
self.display = display
self.shell = None
-
+
def __enter__(self):
from IPython.core.getipython import get_ipython
from IPython.core.displaypub import CapturingDisplayPublisher
- from IPython.core.displayhook import CapturingDisplayHook
-
+ from IPython.core.displayhook import CapturingDisplayHook
+
self.sys_stdout = sys.stdout
self.sys_stderr = sys.stderr
-
+
if self.display:
self.shell = get_ipython()
if self.shell is None:
self.save_display_pub = None
self.display = False
-
+
stdout = stderr = outputs = None
if self.stdout:
stdout = sys.stdout = StringIO()
@@ -160,17 +160,17 @@ class capture_output(object):
self.save_display_pub = self.shell.display_pub
self.shell.display_pub = CapturingDisplayPublisher()
outputs = self.shell.display_pub.outputs
- self.save_display_hook = sys.displayhook
- sys.displayhook = CapturingDisplayHook(shell=self.shell,
- outputs=outputs)
-
+ self.save_display_hook = sys.displayhook
+ sys.displayhook = CapturingDisplayHook(shell=self.shell,
+ outputs=outputs)
+
return CapturedIO(stdout, stderr, outputs)
-
+
def __exit__(self, exc_type, exc_value, traceback):
sys.stdout = self.sys_stdout
sys.stderr = self.sys_stderr
if self.display and self.shell:
self.shell.display_pub = self.save_display_pub
- sys.displayhook = self.save_display_hook
+ sys.displayhook = self.save_display_hook
diff --git a/contrib/python/ipython/py2/IPython/utils/io.py b/contrib/python/ipython/py2/IPython/utils/io.py
index cbbd094017..036d6e3926 100644
--- a/contrib/python/ipython/py2/IPython/utils/io.py
+++ b/contrib/python/ipython/py2/IPython/utils/io.py
@@ -39,12 +39,12 @@ class IOStream:
def clone(meth):
return not hasattr(self, meth) and not meth.startswith('_')
for meth in filter(clone, dir(stream)):
- try:
- val = getattr(stream, meth)
- except AttributeError:
- pass
- else:
- setattr(self, meth, val)
+ try:
+ val = getattr(stream, meth)
+ except AttributeError:
+ pass
+ else:
+ setattr(self, meth, val)
def __repr__(self):
cls = self.__class__
diff --git a/contrib/python/ipython/py2/IPython/utils/path.py b/contrib/python/ipython/py2/IPython/utils/path.py
index e4489a71e0..fa850812c7 100644
--- a/contrib/python/ipython/py2/IPython/utils/path.py
+++ b/contrib/python/ipython/py2/IPython/utils/path.py
@@ -77,7 +77,7 @@ def unquote_filename(name, win32=(sys.platform=='win32')):
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 "
- "be used anymore", DeprecationWarning, stacklevel=2)
+ "be used anymore", DeprecationWarning, stacklevel=2)
if win32:
if name.startswith(("'", '"')) and name.endswith(("'", '"')):
name = name[1:-1]
@@ -104,7 +104,7 @@ def get_py_filename(name, force_win32=None):
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)
+ DeprecationWarning, stacklevel=2)
if not os.path.isfile(name) and not name.endswith('.py'):
name += '.py'
if os.path.isfile(name):
@@ -255,31 +255,31 @@ def get_xdg_cache_dir():
@undoc
def get_ipython_dir():
- warn("get_ipython_dir has moved to the IPython.paths module since IPython 4.0.", stacklevel=2)
+ warn("get_ipython_dir has moved to the IPython.paths module since IPython 4.0.", stacklevel=2)
from IPython.paths import get_ipython_dir
return get_ipython_dir()
@undoc
def get_ipython_cache_dir():
- warn("get_ipython_cache_dir has moved to the IPython.paths module since IPython 4.0.", stacklevel=2)
+ warn("get_ipython_cache_dir has moved to the IPython.paths module since IPython 4.0.", stacklevel=2)
from IPython.paths import get_ipython_cache_dir
return get_ipython_cache_dir()
@undoc
def get_ipython_package_dir():
- warn("get_ipython_package_dir has moved to the IPython.paths module since IPython 4.0.", stacklevel=2)
+ warn("get_ipython_package_dir has moved to the IPython.paths module since IPython 4.0.", stacklevel=2)
from IPython.paths import get_ipython_package_dir
return get_ipython_package_dir()
@undoc
def get_ipython_module_path(module_str):
- warn("get_ipython_module_path has moved to the IPython.paths module since IPython 4.0.", stacklevel=2)
+ warn("get_ipython_module_path has moved to the IPython.paths module since IPython 4.0.", stacklevel=2)
from IPython.paths import get_ipython_module_path
return get_ipython_module_path(module_str)
@undoc
def locate_profile(profile='default'):
- warn("locate_profile has moved to the IPython.paths module since IPython 4.0.", stacklevel=2)
+ warn("locate_profile has moved to the IPython.paths module since IPython 4.0.", stacklevel=2)
from IPython.paths import locate_profile
return locate_profile(profile=profile)
@@ -370,7 +370,7 @@ def target_update(target,deps,cmd):
def filehash(path):
"""Make an MD5 hash of a file, ignoring any differences in line
ending characters."""
- warn("filehash() is deprecated since IPython 4.0", DeprecationWarning, stacklevel=2)
+ warn("filehash() is deprecated since IPython 4.0", DeprecationWarning, stacklevel=2)
with open(path, "rU") as f:
return md5(py3compat.str_to_bytes(f.read())).hexdigest()
diff --git a/contrib/python/ipython/py2/IPython/utils/terminal.py b/contrib/python/ipython/py2/IPython/utils/terminal.py
index afebe10e52..e92c410c79 100644
--- a/contrib/python/ipython/py2/IPython/utils/terminal.py
+++ b/contrib/python/ipython/py2/IPython/utils/terminal.py
@@ -9,8 +9,8 @@ Authors:
* Alexander Belchenko (e-mail: bialix AT ukr.net)
"""
-from __future__ import absolute_import
-
+from __future__ import absolute_import
+
# Copyright (c) IPython Development Team.
# Distributed under the terms of the Modified BSD License.
@@ -21,10 +21,10 @@ 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:
- from ._get_terminal_size import get_terminal_size as _get_terminal_size
+ try:
+ from backports.shutil_get_terminal_size import get_terminal_size as _get_terminal_size
+ except ImportError:
+ from ._get_terminal_size import get_terminal_size as _get_terminal_size
from . import py3compat