Show More
@@ -35,7 +35,7 b' from IPython.utils import generics' | |||||
35 | from IPython.utils.decorators import undoc |
|
35 | from IPython.utils.decorators import undoc | |
36 | from IPython.utils.dir2 import dir2, get_real_method |
|
36 | from IPython.utils.dir2 import dir2, get_real_method | |
37 | from IPython.utils.process import arg_split |
|
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 | from traitlets import Bool, Enum, observe |
|
39 | from traitlets import Bool, Enum, observe | |
40 |
|
40 | |||
41 | from functools import wraps |
|
41 | from functools import wraps | |
@@ -1172,8 +1172,6 b' class IPCompleter(Completer):' | |||||
1172 | if self.use_main_ns: |
|
1172 | if self.use_main_ns: | |
1173 | self.namespace = __main__.__dict__ |
|
1173 | self.namespace = __main__.__dict__ | |
1174 |
|
1174 | |||
1175 | if PY3: |
|
|||
1176 |
|
||||
1177 |
|
|
1175 | base_text = text if not line_buffer else line_buffer[:cursor_pos] | |
1178 |
|
|
1176 | latex_text, latex_matches = self.latex_matches(base_text) | |
1179 |
|
|
1177 | if latex_matches: |
@@ -6,17 +6,12 b' This includes the machinery to recognise and transform ``%magic`` commands,' | |||||
6 | import abc |
|
6 | import abc | |
7 | import functools |
|
7 | import functools | |
8 | import re |
|
8 | import re | |
|
9 | from io import StringIO | |||
9 |
|
10 | |||
10 | from IPython.core.splitinput import LineInfo |
|
11 | from IPython.core.splitinput import LineInfo | |
11 | from IPython.utils import tokenize2 |
|
12 | from IPython.utils import tokenize2 | |
12 | from IPython.utils.py3compat import PY3 |
|
|||
13 | from IPython.utils.tokenize2 import generate_tokens, untokenize, TokenError |
|
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 | # Globals |
|
16 | # Globals | |
22 | #----------------------------------------------------------------------------- |
|
17 | #----------------------------------------------------------------------------- |
@@ -36,7 +36,7 b' from IPython.core.magic import (Magics, magics_class, line_magic, cell_magic,' | |||||
36 | line_cell_magic, on_off, needs_local_scope) |
|
36 | line_cell_magic, on_off, needs_local_scope) | |
37 | from IPython.testing.skipdoctest import skip_doctest |
|
37 | from IPython.testing.skipdoctest import skip_doctest | |
38 | from IPython.utils import py3compat |
|
38 | from IPython.utils import py3compat | |
39 |
from IPython.utils.py3compat import builtin_mod |
|
39 | from IPython.utils.py3compat import builtin_mod | |
40 | from IPython.utils.contexts import preserve_keys |
|
40 | from IPython.utils.contexts import preserve_keys | |
41 | from IPython.utils.capture import capture_output |
|
41 | from IPython.utils.capture import capture_output | |
42 | from IPython.utils.ipstruct import Struct |
|
42 | from IPython.utils.ipstruct import Struct | |
@@ -45,11 +45,8 b' from IPython.utils.path import get_py_filename, shellglob' | |||||
45 | from IPython.utils.timing import clock, clock2 |
|
45 | from IPython.utils.timing import clock, clock2 | |
46 | from warnings import warn |
|
46 | from warnings import warn | |
47 | from logging import error |
|
47 | from logging import error | |
48 |
|
||||
49 | if PY3: |
|
|||
50 |
|
|
48 | from io import StringIO | |
51 | else: |
|
49 | ||
52 | from StringIO import StringIO |
|
|||
53 |
|
50 | |||
54 | #----------------------------------------------------------------------------- |
|
51 | #----------------------------------------------------------------------------- | |
55 | # Magic implementation classes |
|
52 | # Magic implementation classes | |
@@ -652,9 +649,6 b' python-profiler package from non-free.""")' | |||||
652 | args = shellglob(map(os.path.expanduser, arg_lst[1:])) |
|
649 | args = shellglob(map(os.path.expanduser, arg_lst[1:])) | |
653 |
|
650 | |||
654 | sys.argv = [filename] + args # put in the proper filename |
|
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 | if 'i' in opts: |
|
653 | if 'i' in opts: | |
660 | # Run in user's interactive namespace |
|
654 | # Run in user's interactive namespace |
@@ -303,9 +303,6 b' class InteractiveShellApp(Configurable):' | |||||
303 | # were run from a system shell. |
|
303 | # were run from a system shell. | |
304 | save_argv = sys.argv |
|
304 | save_argv = sys.argv | |
305 | sys.argv = [full_filename] + self.extra_args[1:] |
|
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 | try: |
|
306 | try: | |
310 | if os.path.isfile(full_filename): |
|
307 | if os.path.isfile(full_filename): | |
311 | self.log.info("Running file in user namespace: %s" % |
|
308 | self.log.info("Running file in user namespace: %s" % |
@@ -28,10 +28,7 b' tests = [' | |||||
28 | ('??%%hist4', ('', '??', '%%hist4', '')), |
|
28 | ('??%%hist4', ('', '??', '%%hist4', '')), | |
29 | ('?x*', ('', '?', 'x*', '')), |
|
29 | ('?x*', ('', '?', 'x*', '')), | |
30 | ] |
|
30 | ] | |
31 | if py3compat.PY3: |
|
|||
32 |
|
|
31 | tests.append((u"PΓ©rez Fernando", (u'', u'', u'PΓ©rez', u'Fernando'))) | |
33 | else: |
|
|||
34 | tests.append((u"PΓ©rez Fernando", (u'', u'', u'P', u'Γ©rez Fernando'))) |
|
|||
35 |
|
32 | |||
36 | def test_split_user_input(): |
|
33 | def test_split_user_input(): | |
37 | return tt.check_pairs(split_user_input, tests) |
|
34 | return tt.check_pairs(split_user_input, tests) |
@@ -298,7 +298,10 b' def getargs(co):' | |||||
298 |
|
298 | |||
299 | # Monkeypatch inspect to apply our bugfix. |
|
299 | # Monkeypatch inspect to apply our bugfix. | |
300 | def with_patch_inspect(f): |
|
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 | def wrapped(*args, **kwargs): |
|
306 | def wrapped(*args, **kwargs): | |
304 | save_findsource = inspect.findsource |
|
307 | save_findsource = inspect.findsource | |
@@ -314,16 +317,6 b' def with_patch_inspect(f):' | |||||
314 | return wrapped |
|
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 | def fix_frame_records_filenames(records): |
|
320 | def fix_frame_records_filenames(records): | |
328 | """Try to fix the filenames in each record from inspect.getinnerframes(). |
|
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 | file = py3compat.cast_unicode(file, util_path.fs_encoding) |
|
872 | file = py3compat.cast_unicode(file, util_path.fs_encoding) | |
880 | link = tpl_link % file |
|
873 | link = tpl_link % file | |
881 |
args, varargs, varkw, locals = |
|
874 | args, varargs, varkw, locals = inspect.getargvalues(frame) | |
882 |
|
875 | |||
883 | if func == '?': |
|
876 | if func == '?': | |
884 | call = '' |
|
877 | call = '' |
@@ -10,8 +10,6 b' not to be used outside IPython.' | |||||
10 | import unicodedata |
|
10 | import unicodedata | |
11 | from wcwidth import wcwidth |
|
11 | from wcwidth import wcwidth | |
12 |
|
12 | |||
13 | from IPython.utils.py3compat import PY3 |
|
|||
14 |
|
||||
15 | from IPython.core.completer import IPCompleter |
|
13 | from IPython.core.completer import IPCompleter | |
16 | from prompt_toolkit.completion import Completer, Completion |
|
14 | from prompt_toolkit.completion import Completer, Completion | |
17 | from prompt_toolkit.layout.lexers import Lexer |
|
15 | from prompt_toolkit.layout.lexers import Lexer | |
@@ -78,7 +76,7 b' class IPythonPTLexer(Lexer):' | |||||
78 | """ |
|
76 | """ | |
79 | def __init__(self): |
|
77 | def __init__(self): | |
80 | l = pygments_lexers |
|
78 | l = pygments_lexers | |
81 |
self.python_lexer = PygmentsLexer(l.Python3Lexer |
|
79 | self.python_lexer = PygmentsLexer(l.Python3Lexer) | |
82 | self.shell_lexer = PygmentsLexer(l.BashLexer) |
|
80 | self.shell_lexer = PygmentsLexer(l.BashLexer) | |
83 |
|
81 | |||
84 | self.magic_lexers = { |
|
82 | self.magic_lexers = { |
@@ -44,14 +44,8 b' import tokenize' | |||||
44 | generate_tokens = tokenize.generate_tokens |
|
44 | generate_tokens = tokenize.generate_tokens | |
45 |
|
45 | |||
46 | from IPython.utils.coloransi import TermColors, InputTermColors ,ColorScheme, ColorSchemeTable |
|
46 | from IPython.utils.coloransi import TermColors, InputTermColors ,ColorScheme, ColorSchemeTable | |
47 | from IPython.utils.py3compat import PY3 |
|
|||
48 |
|
||||
49 | from .colorable import Colorable |
|
47 | from .colorable import Colorable | |
50 |
|
||||
51 | if PY3: |
|
|||
52 |
|
|
48 | from io import StringIO | |
53 | else: |
|
|||
54 | from StringIO import StringIO |
|
|||
55 |
|
49 | |||
56 | ############################################################################# |
|
50 | ############################################################################# | |
57 | ### Python Source Parser (does Highlighting) |
|
51 | ### Python Source Parser (does Highlighting) |
@@ -6,13 +6,7 b'' | |||||
6 |
|
6 | |||
7 |
|
7 | |||
8 | import sys |
|
8 | import sys | |
9 |
|
||||
10 | from IPython.utils.py3compat import PY3 |
|
|||
11 |
|
||||
12 | if PY3: |
|
|||
13 |
|
|
9 | from io import StringIO | |
14 | else: |
|
|||
15 | from StringIO import StringIO |
|
|||
16 |
|
10 | |||
17 | #----------------------------------------------------------------------------- |
|
11 | #----------------------------------------------------------------------------- | |
18 | # Classes and functions |
|
12 | # Classes and functions |
@@ -17,7 +17,7 b' from warnings import warn' | |||||
17 |
|
17 | |||
18 | from IPython.utils.decorators import undoc |
|
18 | from IPython.utils.decorators import undoc | |
19 | from .capture import CapturedIO, capture_output |
|
19 | from .capture import CapturedIO, capture_output | |
20 |
from .py3compat import input |
|
20 | from .py3compat import input | |
21 |
|
21 | |||
22 | @undoc |
|
22 | @undoc | |
23 | class IOStream: |
|
23 | class IOStream: |
@@ -9,6 +9,7 b' import io as stdlib_io' | |||||
9 | import os.path |
|
9 | import os.path | |
10 | import stat |
|
10 | import stat | |
11 | import sys |
|
11 | import sys | |
|
12 | from io import StringIO | |||
12 |
|
13 | |||
13 | from subprocess import Popen, PIPE |
|
14 | from subprocess import Popen, PIPE | |
14 | import unittest |
|
15 | import unittest | |
@@ -17,14 +18,9 b' import nose.tools as nt' | |||||
17 |
|
18 | |||
18 | from IPython.testing.decorators import skipif, skip_win32 |
|
19 | from IPython.testing.decorators import skipif, skip_win32 | |
19 | from IPython.utils.io import Tee, capture_output |
|
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 | from IPython.utils.tempdir import TemporaryDirectory |
|
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 | def test_tee_simple(): |
|
25 | def test_tee_simple(): | |
30 | "Very simple check with stdout only" |
|
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 | Wrapper around linecache which decodes files to unicode according to PEP 263. | |
4 | itself. |
|
|||
5 | """ |
|
5 | """ | |
6 | import functools |
|
6 | import functools | |
7 | import linecache |
|
7 | import linecache | |
8 | import sys |
|
8 | import sys | |
|
9 | from warnings import warn | |||
9 |
|
10 | |||
10 | from IPython.utils import py3compat |
|
11 | from IPython.utils import py3compat | |
11 | from IPython.utils import openpy |
|
12 | from IPython.utils import openpy | |
12 |
|
13 | |||
13 | if py3compat.PY3: |
|
|||
14 |
|
|
14 | getline = linecache.getline | |
15 |
|
15 | |||
16 |
|
|
16 | # getlines has to be looked up at runtime, because doctests monkeypatch it. | |
17 |
|
|
17 | @functools.wraps(linecache.getlines) | |
18 |
|
|
18 | def getlines(filename, module_globals=None): | |
|
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 | return linecache.getlines(filename, module_globals=module_globals) | |
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