diff options
author | Mikhail Borisov <borisov.mikhail@gmail.com> | 2022-02-10 16:45:39 +0300 |
---|---|---|
committer | Daniil Cherednik <dcherednik@yandex-team.ru> | 2022-02-10 16:45:39 +0300 |
commit | a6a92afe03e02795227d2641b49819b687f088f8 (patch) | |
tree | f6984a1d27d5a7ec88a6fdd6e20cd5b7693b6ece /contrib/python/ipython/py2/IPython/utils/ulinecache.py | |
parent | c6dc8b8bd530985bc4cce0137e9a5de32f1087cb (diff) | |
download | ydb-a6a92afe03e02795227d2641b49819b687f088f8.tar.gz |
Restoring authorship annotation for Mikhail Borisov <borisov.mikhail@gmail.com>. Commit 1 of 2.
Diffstat (limited to 'contrib/python/ipython/py2/IPython/utils/ulinecache.py')
-rw-r--r-- | contrib/python/ipython/py2/IPython/utils/ulinecache.py | 90 |
1 files changed, 45 insertions, 45 deletions
diff --git a/contrib/python/ipython/py2/IPython/utils/ulinecache.py b/contrib/python/ipython/py2/IPython/utils/ulinecache.py index f53b0dde69..886454c267 100644 --- a/contrib/python/ipython/py2/IPython/utils/ulinecache.py +++ b/contrib/python/ipython/py2/IPython/utils/ulinecache.py @@ -1,45 +1,45 @@ -"""Wrapper around linecache which decodes files to unicode according to PEP 263. - -This is only needed for Python 2 - linecache in Python 3 does the same thing -itself. -""" -import functools -import linecache -import sys - -from IPython.utils import py3compat -from IPython.utils import openpy - -if py3compat.PY3: - getline = linecache.getline - - # getlines has to be looked up at runtime, because doctests monkeypatch it. - @functools.wraps(linecache.getlines) - def getlines(filename, module_globals=None): - return linecache.getlines(filename, module_globals=module_globals) - -else: - def getlines(filename, module_globals=None): - """Get the lines (as unicode) for a file from the cache. - Update the cache if it doesn't contain an entry for this file already.""" - filename = py3compat.cast_bytes(filename, sys.getfilesystemencoding()) - lines = linecache.getlines(filename, module_globals=module_globals) - - # The bits we cache ourselves can be unicode. - if (not lines) or isinstance(lines[0], py3compat.unicode_type): - return lines - - readline = openpy._list_readline(lines) - try: - encoding, _ = openpy.detect_encoding(readline) - except SyntaxError: - encoding = 'ascii' - return [l.decode(encoding, 'replace') for l in lines] - - # This is a straight copy of linecache.getline - def getline(filename, lineno, module_globals=None): - lines = getlines(filename, module_globals) - if 1 <= lineno <= len(lines): - return lines[lineno-1] - else: - return '' +"""Wrapper around linecache which decodes files to unicode according to PEP 263. + +This is only needed for Python 2 - linecache in Python 3 does the same thing +itself. +""" +import functools +import linecache +import sys + +from IPython.utils import py3compat +from IPython.utils import openpy + +if py3compat.PY3: + getline = linecache.getline + + # getlines has to be looked up at runtime, because doctests monkeypatch it. + @functools.wraps(linecache.getlines) + def getlines(filename, module_globals=None): + return linecache.getlines(filename, module_globals=module_globals) + +else: + def getlines(filename, module_globals=None): + """Get the lines (as unicode) for a file from the cache. + Update the cache if it doesn't contain an entry for this file already.""" + filename = py3compat.cast_bytes(filename, sys.getfilesystemencoding()) + lines = linecache.getlines(filename, module_globals=module_globals) + + # The bits we cache ourselves can be unicode. + if (not lines) or isinstance(lines[0], py3compat.unicode_type): + return lines + + readline = openpy._list_readline(lines) + try: + encoding, _ = openpy.detect_encoding(readline) + except SyntaxError: + encoding = 'ascii' + return [l.decode(encoding, 'replace') for l in lines] + + # This is a straight copy of linecache.getline + def getline(filename, lineno, module_globals=None): + lines = getlines(filename, module_globals) + if 1 <= lineno <= len(lines): + return lines[lineno-1] + else: + return '' |