Show More
@@ -21,5 +21,6 b' __pycache__' | |||
|
21 | 21 | .DS_Store |
|
22 | 22 | \#*# |
|
23 | 23 | .#* |
|
24 | .cache | |
|
24 | 25 | .coverage |
|
25 | 26 | *.swp |
@@ -218,8 +218,8 b' class ScriptMagics(Magics):' | |||
|
218 | 218 | print("Error while terminating subprocess (pid=%i): %s" \ |
|
219 | 219 | % (p.pid, e)) |
|
220 | 220 | return |
|
221 |
out = py3compat. |
|
|
222 |
err = py3compat. |
|
|
221 | out = py3compat.decode(out) | |
|
222 | err = py3compat.decode(err) | |
|
223 | 223 | if args.out: |
|
224 | 224 | self.shell.user_ns[args.out] = out |
|
225 | 225 | else: |
@@ -10,7 +10,6 b' from traitlets import Unicode' | |||
|
10 | 10 | |
|
11 | 11 | from IPython.core.application import BaseIPythonApplication |
|
12 | 12 | from IPython.testing import decorators as dec |
|
13 | from IPython.utils import py3compat | |
|
14 | 13 | from IPython.utils.tempdir import TemporaryDirectory |
|
15 | 14 | |
|
16 | 15 |
@@ -22,7 +22,6 b' import nose.tools as nt' | |||
|
22 | 22 | |
|
23 | 23 | # Our own imports |
|
24 | 24 | from IPython.core import compilerop |
|
25 | from IPython.utils import py3compat | |
|
26 | 25 | |
|
27 | 26 | #----------------------------------------------------------------------------- |
|
28 | 27 | # Test functions |
@@ -17,7 +17,6 b' from os.path import join' | |||
|
17 | 17 | import nose.tools as nt |
|
18 | 18 | |
|
19 | 19 | from IPython.core.completerlib import magic_run_completer, module_completion |
|
20 | from IPython.utils import py3compat | |
|
21 | 20 | from IPython.utils.tempdir import TemporaryDirectory |
|
22 | 21 | from IPython.testing.decorators import onlyif_unicode_paths |
|
23 | 22 |
@@ -19,7 +19,6 b' import nose.tools as nt' | |||
|
19 | 19 | from traitlets.config.loader import Config |
|
20 | 20 | from IPython.utils.tempdir import TemporaryDirectory |
|
21 | 21 | from IPython.core.history import HistoryManager, extract_hist_ranges |
|
22 | from IPython.utils import py3compat | |
|
23 | 22 | |
|
24 | 23 | def setUp(): |
|
25 | 24 | nt.assert_equal(sys.getdefaultencoding(), "utf-8") |
@@ -17,7 +17,6 b' import sys' | |||
|
17 | 17 | import tempfile |
|
18 | 18 | import unittest |
|
19 | 19 | from unittest import mock |
|
20 | from io import StringIO | |
|
21 | 20 | |
|
22 | 21 | from os.path import join |
|
23 | 22 | |
@@ -30,7 +29,6 b' from IPython.testing.decorators import (' | |||
|
30 | 29 | ) |
|
31 | 30 | from IPython.testing import tools as tt |
|
32 | 31 | from IPython.utils.process import find_cmd |
|
33 | from IPython.utils import py3compat | |
|
34 | 32 | |
|
35 | 33 | #----------------------------------------------------------------------------- |
|
36 | 34 | # Globals |
@@ -19,10 +19,8 b' from IPython.core.magic import (Magics, magics_class, line_magic,' | |||
|
19 | 19 | register_line_cell_magic) |
|
20 | 20 | from decorator import decorator |
|
21 | 21 | from IPython import get_ipython |
|
22 | from IPython.testing.decorators import skipif | |
|
23 | 22 | from IPython.testing.tools import AssertPrints, AssertNotPrints |
|
24 | 23 | from IPython.utils.path import compress_user |
|
25 | from IPython.utils import py3compat | |
|
26 | 24 | |
|
27 | 25 | |
|
28 | 26 | #----------------------------------------------------------------------------- |
@@ -40,14 +38,14 b' ip = get_ipython()' | |||
|
40 | 38 | # defined, if any code is inserted above, the following line will need to be |
|
41 | 39 | # updated. Do NOT insert any whitespace between the next line and the function |
|
42 | 40 | # definition below. |
|
43 |
THIS_LINE_NUMBER = 4 |
|
|
41 | THIS_LINE_NUMBER = 41 # Put here the actual number of this line | |
|
44 | 42 | |
|
45 | 43 | from unittest import TestCase |
|
46 | 44 | |
|
47 | 45 | class Test(TestCase): |
|
48 | 46 | |
|
49 | 47 | def test_find_source_lines(self): |
|
50 |
self.assertEqual(oinspect.find_source_lines(Test.test_find_source_lines), |
|
|
48 | self.assertEqual(oinspect.find_source_lines(Test.test_find_source_lines), | |
|
51 | 49 | THIS_LINE_NUMBER+6) |
|
52 | 50 | |
|
53 | 51 |
@@ -3,7 +3,6 b' import nose.tools as nt' | |||
|
3 | 3 | |
|
4 | 4 | from IPython.core.splitinput import split_user_input, LineInfo |
|
5 | 5 | from IPython.testing import tools as tt |
|
6 | from IPython.utils import py3compat | |
|
7 | 6 | |
|
8 | 7 | tests = [ |
|
9 | 8 | ('x=1', ('', '', 'x', '=1')), |
@@ -1136,35 +1136,32 b' class VerboseTB(TBTools):' | |||
|
1136 | 1136 | colorsnormal = colors.Normal # used a lot |
|
1137 | 1137 | head = '%s%s%s' % (colors.topline, '-' * min(75, get_terminal_size()[0]), colorsnormal) |
|
1138 | 1138 | structured_traceback_parts = [head] |
|
1139 | if py3compat.PY3: | |
|
1140 | chained_exceptions_tb_offset = 0 | |
|
1141 | lines_of_context = 3 | |
|
1142 | formatted_exceptions = formatted_exception | |
|
1139 | chained_exceptions_tb_offset = 0 | |
|
1140 | lines_of_context = 3 | |
|
1141 | formatted_exceptions = formatted_exception | |
|
1142 | exception = self.get_parts_of_chained_exception(evalue) | |
|
1143 | if exception: | |
|
1144 | formatted_exceptions += self.prepare_chained_exception_message(evalue.__cause__) | |
|
1145 | etype, evalue, etb = exception | |
|
1146 | else: | |
|
1147 | evalue = None | |
|
1148 | chained_exc_ids = set() | |
|
1149 | while evalue: | |
|
1150 | formatted_exceptions += self.format_exception_as_a_whole(etype, evalue, etb, lines_of_context, | |
|
1151 | chained_exceptions_tb_offset) | |
|
1143 | 1152 | exception = self.get_parts_of_chained_exception(evalue) |
|
1144 | if exception: | |
|
1153 | ||
|
1154 | if exception and not id(exception[1]) in chained_exc_ids: | |
|
1155 | chained_exc_ids.add(id(exception[1])) # trace exception to avoid infinite 'cause' loop | |
|
1145 | 1156 | formatted_exceptions += self.prepare_chained_exception_message(evalue.__cause__) |
|
1146 | 1157 | etype, evalue, etb = exception |
|
1147 | 1158 | else: |
|
1148 | 1159 | evalue = None |
|
1149 | chained_exc_ids = set() | |
|
1150 | while evalue: | |
|
1151 | formatted_exceptions += self.format_exception_as_a_whole(etype, evalue, etb, lines_of_context, | |
|
1152 | chained_exceptions_tb_offset) | |
|
1153 | exception = self.get_parts_of_chained_exception(evalue) | |
|
1154 | ||
|
1155 | if exception and not id(exception[1]) in chained_exc_ids: | |
|
1156 | chained_exc_ids.add(id(exception[1])) # trace exception to avoid infinite 'cause' loop | |
|
1157 | formatted_exceptions += self.prepare_chained_exception_message(evalue.__cause__) | |
|
1158 | etype, evalue, etb = exception | |
|
1159 | else: | |
|
1160 | evalue = None | |
|
1161 | 1160 | |
|
1162 |
|
|
|
1163 |
|
|
|
1164 |
|
|
|
1165 |
|
|
|
1166 | else: | |
|
1167 | structured_traceback_parts += formatted_exception[0] | |
|
1161 | # we want to see exceptions in a reversed order: | |
|
1162 | # the first exception should be on top | |
|
1163 | for formatted_exception in reversed(formatted_exceptions): | |
|
1164 | structured_traceback_parts += formatted_exception | |
|
1168 | 1165 | |
|
1169 | 1166 | return structured_traceback_parts |
|
1170 | 1167 |
@@ -116,7 +116,6 b' import traceback' | |||
|
116 | 116 | import types |
|
117 | 117 | import weakref |
|
118 | 118 | from importlib import import_module |
|
119 | from IPython.utils.py3compat import PY3 | |
|
120 | 119 | from imp import reload |
|
121 | 120 | |
|
122 | 121 | from IPython.utils import openpy |
@@ -11,7 +11,7 b' import random' | |||
|
11 | 11 | |
|
12 | 12 | # Our own |
|
13 | 13 | from IPython.core.error import UsageError |
|
14 |
from IPython.utils.py3compat import |
|
|
14 | from IPython.utils.py3compat import encode | |
|
15 | 15 | |
|
16 | 16 | #----------------------------------------------------------------------------- |
|
17 | 17 | # Globals |
@@ -65,7 +65,7 b" def passwd(passphrase=None, algorithm='sha1'):" | |||
|
65 | 65 | |
|
66 | 66 | h = hashlib.new(algorithm) |
|
67 | 67 | salt = ('%0' + str(salt_len) + 'x') % random.getrandbits(4 * salt_len) |
|
68 |
h.update( |
|
|
68 | h.update(encode(passphrase, 'utf-8') + encode(salt, 'ascii')) | |
|
69 | 69 | |
|
70 | 70 | return ':'.join((algorithm, salt, h.hexdigest())) |
|
71 | 71 | |
@@ -109,6 +109,6 b' def passwd_check(hashed_passphrase, passphrase):' | |||
|
109 | 109 | if len(pw_digest) == 0: |
|
110 | 110 | return False |
|
111 | 111 | |
|
112 |
h.update( |
|
|
112 | h.update(encode(passphrase, 'utf-8') + encode(salt, 'ascii')) | |
|
113 | 113 | |
|
114 | 114 | return h.hexdigest() == pw_digest |
@@ -7,7 +7,7 b' from warnings import warn' | |||
|
7 | 7 | |
|
8 | 8 | from IPython.core.interactiveshell import InteractiveShell, InteractiveShellABC |
|
9 | 9 | from IPython.utils import io |
|
10 |
from IPython.utils.py3compat import input |
|
|
10 | from IPython.utils.py3compat import input | |
|
11 | 11 | from IPython.utils.terminal import toggle_set_term_title, set_term_title |
|
12 | 12 | from IPython.utils.process import abbrev_cwd |
|
13 | 13 | from traitlets import ( |
@@ -233,7 +233,7 b' class TerminalInteractiveShell(InteractiveShell):' | |||
|
233 | 233 | prompt_text = "".join(x[1] for x in self.prompts.in_prompt_tokens()) |
|
234 | 234 | prompt_continuation = "".join(x[1] for x in self.prompts.continuation_prompt_tokens()) |
|
235 | 235 | while isp.push_accepts_more(): |
|
236 |
line = |
|
|
236 | line = input(prompt_text) | |
|
237 | 237 | isp.push(line) |
|
238 | 238 | prompt_text = prompt_continuation |
|
239 | 239 | return isp.source_reset() |
@@ -31,8 +31,9 b" we've copied verbatim from numpy." | |||
|
31 | 31 | # Copyright (c) IPython Development Team. |
|
32 | 32 | # Distributed under the terms of the Modified BSD License. |
|
33 | 33 | |
|
34 | import sys | |
|
35 | 34 | import os |
|
35 | import shutil | |
|
36 | import sys | |
|
36 | 37 | import tempfile |
|
37 | 38 | import unittest |
|
38 | 39 | import warnings |
@@ -48,9 +49,6 b' from .ipunittest import ipdoctest, ipdocstring' | |||
|
48 | 49 | # numpy.testing.decorators, we expose all of it here. |
|
49 | 50 | from IPython.external.decorators import * |
|
50 | 51 | |
|
51 | # For onlyif_cmd_exists decorator | |
|
52 | from IPython.utils.py3compat import which | |
|
53 | ||
|
54 | 52 | #----------------------------------------------------------------------------- |
|
55 | 53 | # Classes and functions |
|
56 | 54 | #----------------------------------------------------------------------------- |
@@ -360,7 +358,7 b' def onlyif_cmds_exist(*commands):' | |||
|
360 | 358 | Decorator to skip test when at least one of `commands` is not found. |
|
361 | 359 | """ |
|
362 | 360 | for cmd in commands: |
|
363 | if not which(cmd): | |
|
361 | if not shutil.which(cmd): | |
|
364 | 362 | return skip("This test runs only if command '{0}' " |
|
365 | 363 | "is installed".format(cmd)) |
|
366 | 364 | return null_deco |
@@ -372,7 +370,7 b' def onlyif_any_cmd_exists(*commands):' | |||
|
372 | 370 | warnings.warn("The function `onlyif_any_cmd_exists` is deprecated since IPython 4.0", |
|
373 | 371 | DeprecationWarning, stacklevel=2) |
|
374 | 372 | for cmd in commands: |
|
375 | if which(cmd): | |
|
373 | if shutil.which(cmd): | |
|
376 | 374 | return null_deco |
|
377 | 375 | return skip("This test runs only if one of the commands {0} " |
|
378 | 376 | "is installed".format(commands)) |
@@ -11,13 +11,13 b' done.' | |||
|
11 | 11 | |
|
12 | 12 | import builtins as builtin_mod |
|
13 | 13 | import sys |
|
14 | import types | |
|
14 | 15 | import warnings |
|
15 | 16 | |
|
16 | 17 | from . import tools |
|
17 | 18 | |
|
18 | 19 | from IPython.core import page |
|
19 | 20 | from IPython.utils import io |
|
20 | from IPython.utils import py3compat | |
|
21 | 21 | from IPython.terminal.interactiveshell import TerminalInteractiveShell |
|
22 | 22 | |
|
23 | 23 | |
@@ -104,9 +104,9 b' def start_ipython():' | |||
|
104 | 104 | # Modify the IPython system call with one that uses getoutput, so that we |
|
105 | 105 | # can capture subcommands and print them to Python's stdout, otherwise the |
|
106 | 106 | # doctest machinery would miss them. |
|
107 |
shell.system = |
|
|
108 | ||
|
109 |
shell._showtraceback = |
|
|
107 | shell.system = types.MethodType(xsys, shell) | |
|
108 | ||
|
109 | shell._showtraceback = types.MethodType(_showtraceback, shell) | |
|
110 | 110 | |
|
111 | 111 | # IPython is ready, now clean up some global state... |
|
112 | 112 |
@@ -34,7 +34,7 b' from nose.plugins import Plugin' | |||
|
34 | 34 | from nose.util import safe_str |
|
35 | 35 | |
|
36 | 36 | from IPython import version_info |
|
37 |
from IPython.utils.py3compat import |
|
|
37 | from IPython.utils.py3compat import decode | |
|
38 | 38 | from IPython.utils.importstring import import_item |
|
39 | 39 | from IPython.testing.plugin.ipdoctest import IPythonDoctest |
|
40 | 40 | from IPython.external.decorators import KnownFailure, knownfailureif |
@@ -299,8 +299,8 b' class StreamCapturer(Thread):' | |||
|
299 | 299 | with self.buffer_lock: |
|
300 | 300 | self.buffer.write(chunk) |
|
301 | 301 | if self.echo: |
|
302 |
sys.stdout.write( |
|
|
303 | ||
|
302 | sys.stdout.write(decode(chunk)) | |
|
303 | ||
|
304 | 304 | os.close(self.readfd) |
|
305 | 305 | os.close(self.writefd) |
|
306 | 306 |
@@ -24,7 +24,7 b' from .iptest import (' | |||
|
24 | 24 | have, test_group_names as py_test_group_names, test_sections, StreamCapturer, |
|
25 | 25 | ) |
|
26 | 26 | from IPython.utils.path import compress_user |
|
27 |
from IPython.utils.py3compat import |
|
|
27 | from IPython.utils.py3compat import decode | |
|
28 | 28 | from IPython.utils.sysinfo import get_sys_info |
|
29 | 29 | from IPython.utils.tempdir import TemporaryDirectory |
|
30 | 30 | |
@@ -371,7 +371,7 b' def run_iptestall(options):' | |||
|
371 | 371 | print(justify('Test group: ' + controller.section, res_string)) |
|
372 | 372 | if res: |
|
373 | 373 | controller.print_extra_info() |
|
374 |
print( |
|
|
374 | print(decode(controller.stdout)) | |
|
375 | 375 | failed.append(controller) |
|
376 | 376 | if res == -signal.SIGINT: |
|
377 | 377 | print("Interrupted") |
@@ -33,7 +33,6 b' from IPython.utils.process import get_output_error_code' | |||
|
33 | 33 | from IPython.utils.text import list_strings |
|
34 | 34 | from IPython.utils.io import temp_pyfile, Tee |
|
35 | 35 | from IPython.utils import py3compat |
|
36 | from IPython.utils.encoding import DEFAULT_ENCODING | |
|
37 | 36 | |
|
38 | 37 | from . import decorators as dec |
|
39 | 38 | from . import skipdoctest |
@@ -210,8 +209,8 b' def ipexec(fname, options=None, commands=()):' | |||
|
210 | 209 | if not isinstance(v, str): |
|
211 | 210 | print(k, v) |
|
212 | 211 | p = Popen(full_cmd, stdout=PIPE, stderr=PIPE, stdin=PIPE, env=env) |
|
213 |
out, err = p.communicate(input=py3compat. |
|
|
214 |
out, err = py3compat. |
|
|
212 | out, err = p.communicate(input=py3compat.encode('\n'.join(commands)) or None) | |
|
213 | out, err = py3compat.decode(out), py3compat.decode(err) | |
|
215 | 214 | # `import readline` causes 'ESC[?1034h' to be output sometimes, |
|
216 | 215 | # so strip that out before doing comparisons |
|
217 | 216 | if out: |
@@ -28,7 +28,7 b' def _find_cmd(cmd):' | |||
|
28 | 28 | for path in paths: |
|
29 | 29 | filename = os.path.join(path, cmd) |
|
30 | 30 | if System.IO.File.Exists(filename): |
|
31 |
return py3compat. |
|
|
31 | return py3compat.decode(filename) | |
|
32 | 32 | raise OSError("command %r not found" % cmd) |
|
33 | 33 | |
|
34 | 34 | def system(cmd): |
@@ -130,7 +130,7 b' def getoutput(cmd):' | |||
|
130 | 130 | out = process_handler(cmd, lambda p: p.communicate()[0], subprocess.STDOUT) |
|
131 | 131 | if out is None: |
|
132 | 132 | return '' |
|
133 |
return py3compat. |
|
|
133 | return py3compat.decode(out) | |
|
134 | 134 | |
|
135 | 135 | |
|
136 | 136 | def getoutputerror(cmd): |
@@ -172,7 +172,7 b' def get_output_error_code(cmd):' | |||
|
172 | 172 | if out_err is None: |
|
173 | 173 | return '', '', p.returncode |
|
174 | 174 | out, err = out_err |
|
175 |
return py3compat. |
|
|
175 | return py3compat.decode(out), py3compat.decode(err), p.returncode | |
|
176 | 176 | |
|
177 | 177 | def arg_split(s, posix=False, strict=True): |
|
178 | 178 | """Split a command line's arguments in a shell-like manner. |
@@ -36,7 +36,7 b' def _find_cmd(cmd):' | |||
|
36 | 36 | |
|
37 | 37 | path = sp.Popen(['/usr/bin/env', 'which', cmd], |
|
38 | 38 | stdout=sp.PIPE, stderr=sp.PIPE).communicate()[0] |
|
39 |
return py3compat. |
|
|
39 | return py3compat.decode(path) | |
|
40 | 40 | |
|
41 | 41 | |
|
42 | 42 | class ProcessHandler(object): |
@@ -152,7 +152,7 b' def getoutput(cmd):' | |||
|
152 | 152 | |
|
153 | 153 | if out is None: |
|
154 | 154 | out = b'' |
|
155 |
return py3compat. |
|
|
155 | return py3compat.decode(out) | |
|
156 | 156 | |
|
157 | 157 | try: |
|
158 | 158 | CommandLineToArgvW = ctypes.windll.shell32.CommandLineToArgvW |
@@ -15,9 +15,6 b' This file is meant to be used by process.py' | |||
|
15 | 15 | import os, sys, threading |
|
16 | 16 | import ctypes, msvcrt |
|
17 | 17 | |
|
18 | # local imports | |
|
19 | from . import py3compat | |
|
20 | ||
|
21 | 18 | # Win32 API types needed for the API calls |
|
22 | 19 | from ctypes import POINTER |
|
23 | 20 | from ctypes.wintypes import HANDLE, HLOCAL, LPVOID, WORD, DWORD, BOOL, \ |
@@ -8,6 +8,7 b' Utilities for working with external processes.' | |||
|
8 | 8 | |
|
9 | 9 | |
|
10 | 10 | import os |
|
11 | import shutil | |
|
11 | 12 | import sys |
|
12 | 13 | |
|
13 | 14 | if sys.platform == 'win32': |
@@ -18,7 +19,6 b' else:' | |||
|
18 | 19 | from ._process_posix import system, getoutput, arg_split, check_pid |
|
19 | 20 | |
|
20 | 21 | from ._process_common import getoutputerror, get_output_error_code, process_handler |
|
21 | from . import py3compat | |
|
22 | 22 | |
|
23 | 23 | |
|
24 | 24 | class FindCmdError(Exception): |
@@ -44,7 +44,7 b' def find_cmd(cmd):' | |||
|
44 | 44 | cmd : str |
|
45 | 45 | The command line program to look for. |
|
46 | 46 | """ |
|
47 |
path = |
|
|
47 | path = shutil.which(cmd) | |
|
48 | 48 | if path is None: |
|
49 | 49 | raise FindCmdError('command could not be found: %s' % cmd) |
|
50 | 50 | return path |
@@ -143,153 +143,72 b' def _shutil_which(cmd, mode=os.F_OK | os.X_OK, path=None):' | |||
|
143 | 143 | return name |
|
144 | 144 | return None |
|
145 | 145 | |
|
146 | if sys.version_info[0] >= 3: | |
|
147 | PY3 = True | |
|
148 | ||
|
149 | # keep reference to builtin_mod because the kernel overrides that value | |
|
150 | # to forward requests to a frontend. | |
|
151 | def input(prompt=''): | |
|
152 | return builtin_mod.input(prompt) | |
|
153 | ||
|
154 | builtin_mod_name = "builtins" | |
|
155 | import builtins as builtin_mod | |
|
156 | ||
|
157 |
|
|
|
158 | unicode_to_str = no_code | |
|
159 | str_to_bytes = encode | |
|
160 | bytes_to_str = decode | |
|
161 |
|
|
|
162 | cast_unicode_py2 = no_code | |
|
163 | buffer_to_bytes_py2 = no_code | |
|
164 | ||
|
165 | string_types = (str,) | |
|
166 | unicode_type = str | |
|
167 | ||
|
168 | which = shutil.which | |
|
169 | ||
|
170 | def isidentifier(s, dotted=False): | |
|
171 | if dotted: | |
|
172 | return all(isidentifier(a) for a in s.split(".")) | |
|
173 | return s.isidentifier() | |
|
174 | ||
|
175 | xrange = range | |
|
176 |
|
|
|
177 | def itervalues(d): return iter(d.values()) | |
|
178 | getcwd = os.getcwd | |
|
179 | ||
|
180 | MethodType = types.MethodType | |
|
181 | ||
|
182 | def execfile(fname, glob, loc=None, compiler=None): | |
|
183 | loc = loc if (loc is not None) else glob | |
|
184 | with open(fname, 'rb') as f: | |
|
185 | compiler = compiler or compile | |
|
186 | exec(compiler(f.read(), fname, 'exec'), glob, loc) | |
|
187 | ||
|
188 | # Refactor print statements in doctests. | |
|
189 | _print_statement_re = re.compile(r"\bprint (?P<expr>.*)$", re.MULTILINE) | |
|
190 | def _print_statement_sub(match): | |
|
191 | expr = match.groups('expr') | |
|
192 | return "print(%s)" % expr | |
|
193 | ||
|
194 | @_modify_str_or_docstring | |
|
195 | def doctest_refactor_print(doc): | |
|
196 | """Refactor 'print x' statements in a doctest to print(x) style. 2to3 | |
|
197 | unfortunately doesn't pick up on our doctests. | |
|
198 | ||
|
199 | Can accept a string or a function, so it can be used as a decorator.""" | |
|
200 | return _print_statement_re.sub(_print_statement_sub, doc) | |
|
201 | ||
|
202 | # Abstract u'abc' syntax: | |
|
203 | @_modify_str_or_docstring | |
|
204 | def u_format(s): | |
|
205 | """"{u}'abc'" --> "'abc'" (Python 3) | |
|
206 | ||
|
207 | Accepts a string or a function, so it can be used as a decorator.""" | |
|
208 | return s.format(u='') | |
|
209 | ||
|
210 | def get_closure(f): | |
|
211 | """Get a function's closure attribute""" | |
|
212 | return f.__closure__ | |
|
213 | ||
|
214 | else: | |
|
215 | PY3 = False | |
|
216 | ||
|
217 | # keep reference to builtin_mod because the kernel overrides that value | |
|
218 | # to forward requests to a frontend. | |
|
219 | def input(prompt=''): | |
|
220 | return builtin_mod.raw_input(prompt) | |
|
221 | ||
|
222 | builtin_mod_name = "__builtin__" | |
|
223 | import __builtin__ as builtin_mod | |
|
224 | ||
|
225 | str_to_unicode = decode | |
|
226 | unicode_to_str = encode | |
|
227 | str_to_bytes = no_code | |
|
228 | bytes_to_str = no_code | |
|
229 | cast_bytes_py2 = cast_bytes | |
|
230 | cast_unicode_py2 = cast_unicode | |
|
231 | buffer_to_bytes_py2 = buffer_to_bytes | |
|
232 | ||
|
233 | string_types = (str, unicode) | |
|
234 | unicode_type = unicode | |
|
235 | ||
|
236 | import re | |
|
237 | _name_re = re.compile(r"[a-zA-Z_][a-zA-Z0-9_]*$") | |
|
238 | def isidentifier(s, dotted=False): | |
|
239 | if dotted: | |
|
240 | return all(isidentifier(a) for a in s.split(".")) | |
|
241 | return bool(_name_re.match(s)) | |
|
242 | ||
|
243 | xrange = xrange | |
|
244 | def iteritems(d): return d.iteritems() | |
|
245 | def itervalues(d): return d.itervalues() | |
|
246 | getcwd = os.getcwdu | |
|
247 | ||
|
248 | def MethodType(func, instance): | |
|
249 | return types.MethodType(func, instance, type(instance)) | |
|
250 | ||
|
251 | def doctest_refactor_print(func_or_str): | |
|
252 | return func_or_str | |
|
253 | ||
|
254 | def get_closure(f): | |
|
255 | """Get a function's closure attribute""" | |
|
256 | return f.func_closure | |
|
257 | ||
|
258 | which = _shutil_which | |
|
259 | ||
|
260 | # Abstract u'abc' syntax: | |
|
261 | @_modify_str_or_docstring | |
|
262 | def u_format(s): | |
|
263 | """"{u}'abc'" --> "u'abc'" (Python 2) | |
|
264 | ||
|
265 | Accepts a string or a function, so it can be used as a decorator.""" | |
|
266 | return s.format(u='u') | |
|
267 | ||
|
268 | if sys.platform == 'win32': | |
|
269 | def execfile(fname, glob=None, loc=None, compiler=None): | |
|
270 | loc = loc if (loc is not None) else glob | |
|
271 | scripttext = builtin_mod.open(fname).read()+ '\n' | |
|
272 | # compile converts unicode filename to str assuming | |
|
273 | # ascii. Let's do the conversion before calling compile | |
|
274 | if isinstance(fname, unicode): | |
|
275 | filename = unicode_to_str(fname) | |
|
276 | else: | |
|
277 | filename = fname | |
|
278 | compiler = compiler or compile | |
|
279 | exec(compiler(scripttext, filename, 'exec'), glob, loc) | |
|
280 | ||
|
281 | else: | |
|
282 | def execfile(fname, glob=None, loc=None, compiler=None): | |
|
283 | if isinstance(fname, unicode): | |
|
284 | filename = fname.encode(sys.getfilesystemencoding()) | |
|
285 | else: | |
|
286 | filename = fname | |
|
287 | where = [ns for ns in [glob, loc] if ns is not None] | |
|
288 | if compiler is None: | |
|
289 | builtin_mod.execfile(filename, *where) | |
|
290 | else: | |
|
291 | scripttext = builtin_mod.open(fname).read().rstrip() + '\n' | |
|
292 | exec(compiler(scripttext, filename, 'exec'), glob, loc) | |
|
146 | PY3 = True | |
|
147 | ||
|
148 | # keep reference to builtin_mod because the kernel overrides that value | |
|
149 | # to forward requests to a frontend. | |
|
150 | def input(prompt=''): | |
|
151 | return builtin_mod.input(prompt) | |
|
152 | ||
|
153 | builtin_mod_name = "builtins" | |
|
154 | import builtins as builtin_mod | |
|
155 | ||
|
156 | str_to_unicode = no_code | |
|
157 | unicode_to_str = no_code | |
|
158 | str_to_bytes = encode | |
|
159 | bytes_to_str = decode | |
|
160 | cast_bytes_py2 = no_code | |
|
161 | cast_unicode_py2 = no_code | |
|
162 | buffer_to_bytes_py2 = no_code | |
|
163 | ||
|
164 | string_types = (str,) | |
|
165 | unicode_type = str | |
|
166 | ||
|
167 | which = shutil.which | |
|
168 | ||
|
169 | def isidentifier(s, dotted=False): | |
|
170 | if dotted: | |
|
171 | return all(isidentifier(a) for a in s.split(".")) | |
|
172 | return s.isidentifier() | |
|
173 | ||
|
174 | xrange = range | |
|
175 | def iteritems(d): return iter(d.items()) | |
|
176 | def itervalues(d): return iter(d.values()) | |
|
177 | getcwd = os.getcwd | |
|
178 | ||
|
179 | MethodType = types.MethodType | |
|
180 | ||
|
181 | def execfile(fname, glob, loc=None, compiler=None): | |
|
182 | loc = loc if (loc is not None) else glob | |
|
183 | with open(fname, 'rb') as f: | |
|
184 | compiler = compiler or compile | |
|
185 | exec(compiler(f.read(), fname, 'exec'), glob, loc) | |
|
186 | ||
|
187 | # Refactor print statements in doctests. | |
|
188 | _print_statement_re = re.compile(r"\bprint (?P<expr>.*)$", re.MULTILINE) | |
|
189 | def _print_statement_sub(match): | |
|
190 | expr = match.groups('expr') | |
|
191 | return "print(%s)" % expr | |
|
192 | ||
|
193 | @_modify_str_or_docstring | |
|
194 | def doctest_refactor_print(doc): | |
|
195 | """Refactor 'print x' statements in a doctest to print(x) style. 2to3 | |
|
196 | unfortunately doesn't pick up on our doctests. | |
|
197 | ||
|
198 | Can accept a string or a function, so it can be used as a decorator.""" | |
|
199 | return _print_statement_re.sub(_print_statement_sub, doc) | |
|
200 | ||
|
201 | # Abstract u'abc' syntax: | |
|
202 | @_modify_str_or_docstring | |
|
203 | def u_format(s): | |
|
204 | """"{u}'abc'" --> "'abc'" (Python 3) | |
|
205 | ||
|
206 | Accepts a string or a function, so it can be used as a decorator.""" | |
|
207 | return s.format(u='') | |
|
208 | ||
|
209 | def get_closure(f): | |
|
210 | """Get a function's closure attribute""" | |
|
211 | return f.__closure__ | |
|
293 | 212 | |
|
294 | 213 | |
|
295 | 214 | PY2 = not PY3 |
@@ -91,11 +91,7 b" Expfloat = r'[0-9]+' + Exponent" | |||
|
91 | 91 | Floatnumber = group(Pointfloat, Expfloat) |
|
92 | 92 | Imagnumber = group(r'[0-9]+[jJ]', Floatnumber + r'[jJ]') |
|
93 | 93 | Number = group(Imagnumber, Floatnumber, Intnumber) |
|
94 | ||
|
95 | if sys.version_info.minor >= 3: | |
|
96 | StringPrefix = r'(?:[bB][rR]?|[rR][bB]?|[uU])?' | |
|
97 | else: | |
|
98 | StringPrefix = r'(?:[bB]?[rR]?)?' | |
|
94 | StringPrefix = r'(?:[bB][rR]?|[rR][bB]?|[uU])?' | |
|
99 | 95 | |
|
100 | 96 | # Tail end of ' string. |
|
101 | 97 | Single = r"[^'\\]*(?:\\.[^'\\]*)*'" |
@@ -165,20 +161,18 b' for t in ("\'", \'"\',' | |||
|
165 | 161 | "bR'", 'bR"', "BR'", 'BR"' ): |
|
166 | 162 | single_quoted[t] = t |
|
167 | 163 | |
|
168 | if sys.version_info.minor >= 3: | |
|
169 | # Python 3.3 | |
|
170 | for _prefix in ['rb', 'rB', 'Rb', 'RB', 'u', 'U']: | |
|
171 | _t2 = _prefix+'"""' | |
|
172 | endprogs[_t2] = double3prog | |
|
173 | triple_quoted[_t2] = _t2 | |
|
174 | _t1 = _prefix + "'''" | |
|
175 | endprogs[_t1] = single3prog | |
|
176 | triple_quoted[_t1] = _t1 | |
|
177 | single_quoted[_prefix+'"'] = _prefix+'"' | |
|
178 | single_quoted[_prefix+"'"] = _prefix+"'" | |
|
179 | del _prefix, _t2, _t1 | |
|
180 | endprogs['u'] = None | |
|
181 | endprogs['U'] = None | |
|
164 | for _prefix in ['rb', 'rB', 'Rb', 'RB', 'u', 'U']: | |
|
165 | _t2 = _prefix+'"""' | |
|
166 | endprogs[_t2] = double3prog | |
|
167 | triple_quoted[_t2] = _t2 | |
|
168 | _t1 = _prefix + "'''" | |
|
169 | endprogs[_t1] = single3prog | |
|
170 | triple_quoted[_t1] = _t1 | |
|
171 | single_quoted[_prefix+'"'] = _prefix+'"' | |
|
172 | single_quoted[_prefix+"'"] = _prefix+"'" | |
|
173 | del _prefix, _t2, _t1 | |
|
174 | endprogs['u'] = None | |
|
175 | endprogs['U'] = None | |
|
182 | 176 | |
|
183 | 177 | del _compile |
|
184 | 178 |
@@ -40,15 +40,9 b' def oscmd(s):' | |||
|
40 | 40 | print(">", s) |
|
41 | 41 | os.system(s) |
|
42 | 42 | |
|
43 | # Py3 compatibility hacks, without assuming IPython itself is installed with | |
|
44 | # the full py3compat machinery. | |
|
45 | ||
|
46 | try: | |
|
47 | execfile | |
|
48 | except NameError: | |
|
49 | def execfile(fname, globs, locs=None): | |
|
50 | locs = locs or globs | |
|
51 | exec(compile(open(fname).read(), fname, "exec"), globs, locs) | |
|
43 | def execfile(fname, globs, locs=None): | |
|
44 | locs = locs or globs | |
|
45 | exec(compile(open(fname).read(), fname, "exec"), globs, locs) | |
|
52 | 46 | |
|
53 | 47 | # A little utility we'll need below, since glob() does NOT allow you to do |
|
54 | 48 | # exclusion on multiple endings! |
@@ -10,7 +10,7 b'' | |||
|
10 | 10 | ; tox -- --all -j # Runs "iptest --all -j" in every environment |
|
11 | 11 | |
|
12 | 12 | [tox] |
|
13 |
envlist = py{36,35,34,33, |
|
|
13 | envlist = py{36,35,34,33,py} | |
|
14 | 14 | skip_missing_interpreters = True |
|
15 | 15 | toxworkdir = /tmp/tox_ipython |
|
16 | 16 | |
@@ -19,7 +19,7 b' toxworkdir = /tmp/tox_ipython' | |||
|
19 | 19 | ; Other IPython/testing dependencies should be in setup.py, not here |
|
20 | 20 | deps = |
|
21 | 21 | pypy: https://bitbucket.org/pypy/numpy/get/master.zip |
|
22 |
py{36,35,34,33 |
|
|
22 | py{36,35,34,33}: matplotlib | |
|
23 | 23 | .[test] |
|
24 | 24 | |
|
25 | 25 | ; It's just to avoid loading the IPython package in the current directory |
General Comments 0
You need to be logged in to leave comments.
Login now