Show More
@@ -35,7 +35,7 b' from IPython.utils import generics' | |||
|
35 | 35 | from IPython.utils.decorators import undoc |
|
36 | 36 | from IPython.utils.dir2 import dir2, get_real_method |
|
37 | 37 | from IPython.utils.process import arg_split |
|
38 |
from IPython.utils.py3compat import builtin_mod, |
|
|
38 | from IPython.utils.py3compat import builtin_mod, cast_unicode_py2 | |
|
39 | 39 | from traitlets import Bool, Enum, observe |
|
40 | 40 | |
|
41 | 41 | from functools import wraps |
@@ -1172,8 +1172,6 b' class IPCompleter(Completer):' | |||
|
1172 | 1172 | if self.use_main_ns: |
|
1173 | 1173 | self.namespace = __main__.__dict__ |
|
1174 | 1174 | |
|
1175 | if PY3: | |
|
1176 | ||
|
1177 | 1175 |
|
|
1178 | 1176 |
|
|
1179 | 1177 |
|
@@ -6,17 +6,12 b' This includes the machinery to recognise and transform ``%magic`` commands,' | |||
|
6 | 6 | import abc |
|
7 | 7 | import functools |
|
8 | 8 | import re |
|
9 | from io import StringIO | |
|
9 | 10 | |
|
10 | 11 | from IPython.core.splitinput import LineInfo |
|
11 | 12 | from IPython.utils import tokenize2 |
|
12 | from IPython.utils.py3compat import PY3 | |
|
13 | 13 | from IPython.utils.tokenize2 import generate_tokens, untokenize, TokenError |
|
14 | 14 | |
|
15 | if PY3: | |
|
16 | from io import StringIO | |
|
17 | else: | |
|
18 | from StringIO import StringIO | |
|
19 | ||
|
20 | 15 | #----------------------------------------------------------------------------- |
|
21 | 16 | # Globals |
|
22 | 17 | #----------------------------------------------------------------------------- |
@@ -36,7 +36,7 b' from IPython.core.magic import (Magics, magics_class, line_magic, cell_magic,' | |||
|
36 | 36 | line_cell_magic, on_off, needs_local_scope) |
|
37 | 37 | from IPython.testing.skipdoctest import skip_doctest |
|
38 | 38 | from IPython.utils import py3compat |
|
39 |
from IPython.utils.py3compat import builtin_mod |
|
|
39 | from IPython.utils.py3compat import builtin_mod | |
|
40 | 40 | from IPython.utils.contexts import preserve_keys |
|
41 | 41 | from IPython.utils.capture import capture_output |
|
42 | 42 | from IPython.utils.ipstruct import Struct |
@@ -45,11 +45,8 b' from IPython.utils.path import get_py_filename, shellglob' | |||
|
45 | 45 | from IPython.utils.timing import clock, clock2 |
|
46 | 46 | from warnings import warn |
|
47 | 47 | from logging import error |
|
48 | ||
|
49 | if PY3: | |
|
50 | 48 |
|
|
51 | else: | |
|
52 | from StringIO import StringIO | |
|
49 | ||
|
53 | 50 | |
|
54 | 51 | #----------------------------------------------------------------------------- |
|
55 | 52 | # Magic implementation classes |
@@ -652,9 +649,6 b' python-profiler package from non-free.""")' | |||
|
652 | 649 | args = shellglob(map(os.path.expanduser, arg_lst[1:])) |
|
653 | 650 | |
|
654 | 651 | sys.argv = [filename] + args # put in the proper filename |
|
655 | # protect sys.argv from potential unicode strings on Python 2: | |
|
656 | if not py3compat.PY3: | |
|
657 | sys.argv = [ py3compat.cast_bytes(a) for a in sys.argv ] | |
|
658 | 652 | |
|
659 | 653 | if 'i' in opts: |
|
660 | 654 | # Run in user's interactive namespace |
@@ -303,9 +303,6 b' class InteractiveShellApp(Configurable):' | |||
|
303 | 303 | # were run from a system shell. |
|
304 | 304 | save_argv = sys.argv |
|
305 | 305 | sys.argv = [full_filename] + self.extra_args[1:] |
|
306 | # protect sys.argv from potential unicode strings on Python 2: | |
|
307 | if not py3compat.PY3: | |
|
308 | sys.argv = [ py3compat.cast_bytes(a) for a in sys.argv ] | |
|
309 | 306 | try: |
|
310 | 307 | if os.path.isfile(full_filename): |
|
311 | 308 | self.log.info("Running file in user namespace: %s" % |
@@ -28,10 +28,7 b' tests = [' | |||
|
28 | 28 | ('??%%hist4', ('', '??', '%%hist4', '')), |
|
29 | 29 | ('?x*', ('', '?', 'x*', '')), |
|
30 | 30 | ] |
|
31 | if py3compat.PY3: | |
|
32 | 31 |
|
|
33 | else: | |
|
34 | tests.append((u"PΓ©rez Fernando", (u'', u'', u'P', u'Γ©rez Fernando'))) | |
|
35 | 32 | |
|
36 | 33 | def test_split_user_input(): |
|
37 | 34 | return tt.check_pairs(split_user_input, tests) |
@@ -298,7 +298,10 b' def getargs(co):' | |||
|
298 | 298 | |
|
299 | 299 | # Monkeypatch inspect to apply our bugfix. |
|
300 | 300 | def with_patch_inspect(f): |
|
301 | """decorator for monkeypatching inspect.findsource""" | |
|
301 | """ | |
|
302 | Deprecated since IPython 6.0 | |
|
303 | decorator for monkeypatching inspect.findsource | |
|
304 | """ | |
|
302 | 305 | |
|
303 | 306 | def wrapped(*args, **kwargs): |
|
304 | 307 | save_findsource = inspect.findsource |
@@ -314,16 +317,6 b' def with_patch_inspect(f):' | |||
|
314 | 317 | return wrapped |
|
315 | 318 | |
|
316 | 319 | |
|
317 | if py3compat.PY3: | |
|
318 | fixed_getargvalues = inspect.getargvalues | |
|
319 | else: | |
|
320 | # Fixes for https://github.com/ipython/ipython/issues/8293 | |
|
321 | # and https://github.com/ipython/ipython/issues/8205. | |
|
322 | # The relevant bug is caused by failure to correctly handle anonymous tuple | |
|
323 | # unpacking, which only exists in Python 2. | |
|
324 | fixed_getargvalues = with_patch_inspect(inspect.getargvalues) | |
|
325 | ||
|
326 | ||
|
327 | 320 | def fix_frame_records_filenames(records): |
|
328 | 321 | """Try to fix the filenames in each record from inspect.getinnerframes(). |
|
329 | 322 | |
@@ -878,7 +871,7 b' class VerboseTB(TBTools):' | |||
|
878 | 871 | |
|
879 | 872 | file = py3compat.cast_unicode(file, util_path.fs_encoding) |
|
880 | 873 | link = tpl_link % file |
|
881 |
args, varargs, varkw, locals = |
|
|
874 | args, varargs, varkw, locals = inspect.getargvalues(frame) | |
|
882 | 875 | |
|
883 | 876 | if func == '?': |
|
884 | 877 | call = '' |
@@ -10,8 +10,6 b' not to be used outside IPython.' | |||
|
10 | 10 | import unicodedata |
|
11 | 11 | from wcwidth import wcwidth |
|
12 | 12 | |
|
13 | from IPython.utils.py3compat import PY3 | |
|
14 | ||
|
15 | 13 | from IPython.core.completer import IPCompleter |
|
16 | 14 | from prompt_toolkit.completion import Completer, Completion |
|
17 | 15 | from prompt_toolkit.layout.lexers import Lexer |
@@ -78,7 +76,7 b' class IPythonPTLexer(Lexer):' | |||
|
78 | 76 | """ |
|
79 | 77 | def __init__(self): |
|
80 | 78 | l = pygments_lexers |
|
81 |
self.python_lexer = PygmentsLexer(l.Python3Lexer |
|
|
79 | self.python_lexer = PygmentsLexer(l.Python3Lexer) | |
|
82 | 80 | self.shell_lexer = PygmentsLexer(l.BashLexer) |
|
83 | 81 | |
|
84 | 82 | self.magic_lexers = { |
@@ -44,14 +44,8 b' import tokenize' | |||
|
44 | 44 | generate_tokens = tokenize.generate_tokens |
|
45 | 45 | |
|
46 | 46 | from IPython.utils.coloransi import TermColors, InputTermColors ,ColorScheme, ColorSchemeTable |
|
47 | from IPython.utils.py3compat import PY3 | |
|
48 | ||
|
49 | 47 | from .colorable import Colorable |
|
50 | ||
|
51 | if PY3: | |
|
52 | 48 |
|
|
53 | else: | |
|
54 | from StringIO import StringIO | |
|
55 | 49 | |
|
56 | 50 | ############################################################################# |
|
57 | 51 | ### Python Source Parser (does Highlighting) |
@@ -6,13 +6,7 b'' | |||
|
6 | 6 | |
|
7 | 7 | |
|
8 | 8 | import sys |
|
9 | ||
|
10 | from IPython.utils.py3compat import PY3 | |
|
11 | ||
|
12 | if PY3: | |
|
13 | 9 |
|
|
14 | else: | |
|
15 | from StringIO import StringIO | |
|
16 | 10 | |
|
17 | 11 | #----------------------------------------------------------------------------- |
|
18 | 12 | # Classes and functions |
@@ -17,7 +17,7 b' from warnings import warn' | |||
|
17 | 17 | |
|
18 | 18 | from IPython.utils.decorators import undoc |
|
19 | 19 | from .capture import CapturedIO, capture_output |
|
20 |
from .py3compat import input |
|
|
20 | from .py3compat import input | |
|
21 | 21 | |
|
22 | 22 | @undoc |
|
23 | 23 | class IOStream: |
@@ -9,6 +9,7 b' import io as stdlib_io' | |||
|
9 | 9 | import os.path |
|
10 | 10 | import stat |
|
11 | 11 | import sys |
|
12 | from io import StringIO | |
|
12 | 13 | |
|
13 | 14 | from subprocess import Popen, PIPE |
|
14 | 15 | import unittest |
@@ -17,14 +18,9 b' import nose.tools as nt' | |||
|
17 | 18 | |
|
18 | 19 | from IPython.testing.decorators import skipif, skip_win32 |
|
19 | 20 | from IPython.utils.io import Tee, capture_output |
|
20 |
from IPython.utils.py3compat import doctest_refactor_print |
|
|
21 | from IPython.utils.py3compat import doctest_refactor_print | |
|
21 | 22 | from IPython.utils.tempdir import TemporaryDirectory |
|
22 | 23 | |
|
23 | if PY3: | |
|
24 | from io import StringIO | |
|
25 | else: | |
|
26 | from StringIO import StringIO | |
|
27 | ||
|
28 | 24 | |
|
29 | 25 | def test_tee_simple(): |
|
30 | 26 | "Very simple check with stdout only" |
@@ -1,44 +1,25 b'' | |||
|
1 | """Wrapper around linecache which decodes files to unicode according to PEP 263. | |
|
1 | """ | |
|
2 | This module has been deprecated since IPython 6.0. | |
|
2 | 3 | |
|
3 | This is only needed for Python 2 - linecache in Python 3 does the same thing | |
|
4 | itself. | |
|
4 | Wrapper around linecache which decodes files to unicode according to PEP 263. | |
|
5 | 5 | """ |
|
6 | 6 | import functools |
|
7 | 7 | import linecache |
|
8 | 8 | import sys |
|
9 | from warnings import warn | |
|
9 | 10 | |
|
10 | 11 | from IPython.utils import py3compat |
|
11 | 12 | from IPython.utils import openpy |
|
12 | 13 | |
|
13 | if py3compat.PY3: | |
|
14 | 14 |
|
|
15 | 15 | |
|
16 | 16 |
|
|
17 | 17 |
|
|
18 | 18 |
|
|
19 | """ | |
|
20 | Deprecated since IPython 6.0 | |
|
21 | """ | |
|
22 | warn(("`IPython.utils.ulinecache.getlines` is deprecated since" | |
|
23 | " IPython 6.0 and will be removed in future versions."), | |
|
24 | DeprecationWarning, stacklevel=2) | |
|
19 | 25 |
|
|
20 | ||
|
21 | else: | |
|
22 | def getlines(filename, module_globals=None): | |
|
23 | """Get the lines (as unicode) for a file from the cache. | |
|
24 | Update the cache if it doesn't contain an entry for this file already.""" | |
|
25 | filename = py3compat.cast_bytes(filename, sys.getfilesystemencoding()) | |
|
26 | lines = linecache.getlines(filename, module_globals=module_globals) | |
|
27 | ||
|
28 | if (not lines) or isinstance(lines[0], str): | |
|
29 | return lines | |
|
30 | ||
|
31 | readline = openpy._list_readline(lines) | |
|
32 | try: | |
|
33 | encoding, _ = openpy.detect_encoding(readline) | |
|
34 | except SyntaxError: | |
|
35 | encoding = 'ascii' | |
|
36 | return [l.decode(encoding, 'replace') for l in lines] | |
|
37 | ||
|
38 | # This is a straight copy of linecache.getline | |
|
39 | def getline(filename, lineno, module_globals=None): | |
|
40 | lines = getlines(filename, module_globals) | |
|
41 | if 1 <= lineno <= len(lines): | |
|
42 | return lines[lineno-1] | |
|
43 | else: | |
|
44 | return '' |
General Comments 0
You need to be logged in to leave comments.
Login now