Show More
@@ -146,7 +146,7 b' class Tracer(object):' | |||||
146 | # at least raise that limit to 80 chars, which should be enough for |
|
146 | # at least raise that limit to 80 chars, which should be enough for | |
147 | # most interactive uses. |
|
147 | # most interactive uses. | |
148 | try: |
|
148 | try: | |
149 | from repr import aRepr |
|
149 | from reprlib import aRepr | |
150 | aRepr.maxstring = 80 |
|
150 | aRepr.maxstring = 80 | |
151 | except: |
|
151 | except: | |
152 | # This is only a user-facing convenience, so any error we encounter |
|
152 | # This is only a user-facing convenience, so any error we encounter | |
@@ -331,7 +331,7 b' class Pdb(OldPdb):' | |||||
331 | # vds: << |
|
331 | # vds: << | |
332 |
|
332 | |||
333 | def format_stack_entry(self, frame_lineno, lprefix=': ', context = 3): |
|
333 | def format_stack_entry(self, frame_lineno, lprefix=': ', context = 3): | |
334 | import repr |
|
334 | import reprlib | |
335 |
|
335 | |||
336 | ret = [] |
|
336 | ret = [] | |
337 |
|
337 | |||
@@ -349,7 +349,7 b' class Pdb(OldPdb):' | |||||
349 | if '__return__' in frame.f_locals: |
|
349 | if '__return__' in frame.f_locals: | |
350 | rv = frame.f_locals['__return__'] |
|
350 | rv = frame.f_locals['__return__'] | |
351 | #return_value += '->' |
|
351 | #return_value += '->' | |
352 | return_value += repr.repr(rv) + '\n' |
|
352 | return_value += reprlib.repr(rv) + '\n' | |
353 | ret.append(return_value) |
|
353 | ret.append(return_value) | |
354 |
|
354 | |||
355 | #s = filename + '(' + `lineno` + ')' |
|
355 | #s = filename + '(' + `lineno` + ')' | |
@@ -364,7 +364,7 b' class Pdb(OldPdb):' | |||||
364 | call = '' |
|
364 | call = '' | |
365 | if func != '?': |
|
365 | if func != '?': | |
366 | if '__args__' in frame.f_locals: |
|
366 | if '__args__' in frame.f_locals: | |
367 | args = repr.repr(frame.f_locals['__args__']) |
|
367 | args = reprlib.repr(frame.f_locals['__args__']) | |
368 | else: |
|
368 | else: | |
369 | args = '()' |
|
369 | args = '()' | |
370 | call = tpl_call % (func, args) |
|
370 | call = tpl_call % (func, args) |
@@ -170,6 +170,9 b' class ExtensionManager(Configurable):' | |||||
170 | copy = copyfile |
|
170 | copy = copyfile | |
171 | else: |
|
171 | else: | |
172 | from urllib import urlretrieve # Deferred imports |
|
172 | from urllib import urlretrieve # Deferred imports | |
|
173 | try: | |||
|
174 | from urllib.parse import urlparse # Py3 | |||
|
175 | except ImportError: | |||
173 | from urlparse import urlparse |
|
176 | from urlparse import urlparse | |
174 | src_filename = urlparse(url).path.split('/')[-1] |
|
177 | src_filename = urlparse(url).path.split('/')[-1] | |
175 | copy = urlretrieve |
|
178 | copy = urlretrieve |
@@ -28,7 +28,7 b' import abc' | |||||
28 | import sys |
|
28 | import sys | |
29 | import warnings |
|
29 | import warnings | |
30 | # We must use StringIO, as cStringIO doesn't handle unicode properly. |
|
30 | # We must use StringIO, as cStringIO doesn't handle unicode properly. | |
31 |
from |
|
31 | from io import StringIO | |
32 |
|
32 | |||
33 | # Our own imports |
|
33 | # Our own imports | |
34 | from IPython.config.configurable import Configurable |
|
34 | from IPython.config.configurable import Configurable |
@@ -1,7 +1,7 b'' | |||||
1 | import abc |
|
1 | import abc | |
2 | import functools |
|
2 | import functools | |
3 | import re |
|
3 | import re | |
4 |
from |
|
4 | from io import StringIO | |
5 |
|
5 | |||
6 | from IPython.core.splitinput import LineInfo |
|
6 | from IPython.core.splitinput import LineInfo | |
7 | from IPython.utils import tokenize2 |
|
7 | from IPython.utils import tokenize2 |
@@ -20,7 +20,7 b' import bdb' | |||||
20 | import os |
|
20 | import os | |
21 | import sys |
|
21 | import sys | |
22 | import time |
|
22 | import time | |
23 |
from |
|
23 | from io import StringIO | |
24 |
|
24 | |||
25 | # cProfile was added in Python2.5 |
|
25 | # cProfile was added in Python2.5 | |
26 | try: |
|
26 | try: |
@@ -58,7 +58,7 b' class PdbTestInput(object):' | |||||
58 | #----------------------------------------------------------------------------- |
|
58 | #----------------------------------------------------------------------------- | |
59 |
|
59 | |||
60 | def test_longer_repr(): |
|
60 | def test_longer_repr(): | |
61 | from repr import repr as trepr |
|
61 | from reprlib import repr as trepr | |
62 |
|
62 | |||
63 | a = '1234567890'* 7 |
|
63 | a = '1234567890'* 7 | |
64 | ar = "'1234567890123456789012345678901234567890123456789012345678901234567890'" |
|
64 | ar = "'1234567890123456789012345678901234567890123456789012345678901234567890'" |
@@ -28,7 +28,7 b' import sys' | |||||
28 | import tempfile |
|
28 | import tempfile | |
29 | import unittest |
|
29 | import unittest | |
30 | from os.path import join |
|
30 | from os.path import join | |
31 |
from |
|
31 | from io import StringIO | |
32 |
|
32 | |||
33 | # third-party |
|
33 | # third-party | |
34 | import nose.tools as nt |
|
34 | import nose.tools as nt | |
@@ -155,7 +155,7 b' class InteractiveShellTestCase(unittest.TestCase):' | |||||
155 | " list.__init__(self,x)")) |
|
155 | " list.__init__(self,x)")) | |
156 | ip.run_cell("w=Mylist([1,2,3])") |
|
156 | ip.run_cell("w=Mylist([1,2,3])") | |
157 |
|
157 | |||
158 |
from |
|
158 | from pickle import dumps | |
159 |
|
159 | |||
160 | # We need to swap in our main module - this is only necessary |
|
160 | # We need to swap in our main module - this is only necessary | |
161 | # inside the test framework, because IPython puts the interactive module |
|
161 | # inside the test framework, because IPython puts the interactive module |
@@ -12,7 +12,7 b' from __future__ import absolute_import' | |||||
12 | import io |
|
12 | import io | |
13 | import os |
|
13 | import os | |
14 | import sys |
|
14 | import sys | |
15 |
from |
|
15 | from io import StringIO | |
16 | from unittest import TestCase |
|
16 | from unittest import TestCase | |
17 |
|
17 | |||
18 | try: |
|
18 | try: |
@@ -9,7 +9,7 b' from __future__ import absolute_import' | |||||
9 | #----------------------------------------------------------------------------- |
|
9 | #----------------------------------------------------------------------------- | |
10 |
|
10 | |||
11 | import sys |
|
11 | import sys | |
12 |
from |
|
12 | from io import StringIO | |
13 | from unittest import TestCase |
|
13 | from unittest import TestCase | |
14 |
|
14 | |||
15 | import nose.tools as nt |
|
15 | import nose.tools as nt |
@@ -18,7 +18,7 b' import tempfile' | |||||
18 | import shutil |
|
18 | import shutil | |
19 | import random |
|
19 | import random | |
20 | import time |
|
20 | import time | |
21 |
from |
|
21 | from io import StringIO | |
22 |
|
22 | |||
23 | import nose.tools as nt |
|
23 | import nose.tools as nt | |
24 | import IPython.testing.tools as tt |
|
24 | import IPython.testing.tools as tt |
@@ -1,4 +1,4 b'' | |||||
1 |
from |
|
1 | from io import StringIO | |
2 |
|
2 | |||
3 | import numpy as np |
|
3 | import numpy as np | |
4 | from IPython.testing.decorators import skip_without |
|
4 | from IPython.testing.decorators import skip_without |
@@ -16,7 +16,10 b' Authors:' | |||||
16 | # Imports |
|
16 | # Imports | |
17 | #----------------------------------------------------------------------------- |
|
17 | #----------------------------------------------------------------------------- | |
18 |
|
18 | |||
19 | import Cookie |
|
19 | try: | |
|
20 | from http.cookies import SimpleCookie # Py 3 | |||
|
21 | except ImportError: | |||
|
22 | from Cookie import SimpleCookie # Py 2 | |||
20 | import logging |
|
23 | import logging | |
21 | from tornado import web |
|
24 | from tornado import web | |
22 | from tornado import websocket |
|
25 | from tornado import websocket | |
@@ -102,7 +105,7 b' class AuthenticatedZMQStreamHandler(ZMQStreamHandler, IPythonHandler):' | |||||
102 | logging.error("First ws message didn't have the form 'identity:[cookie]' - %r", msg) |
|
105 | logging.error("First ws message didn't have the form 'identity:[cookie]' - %r", msg) | |
103 |
|
106 | |||
104 | try: |
|
107 | try: | |
105 |
self.request._cookies = |
|
108 | self.request._cookies = SimpleCookie(msg) | |
106 | except: |
|
109 | except: | |
107 | self.log.warn("couldn't parse cookie string: %s",msg, exc_info=True) |
|
110 | self.log.warn("couldn't parse cookie string: %s",msg, exc_info=True) | |
108 |
|
111 |
@@ -13,7 +13,10 b' Useful for test suites and blocking terminal interfaces.' | |||||
13 | # Imports |
|
13 | # Imports | |
14 | #----------------------------------------------------------------------------- |
|
14 | #----------------------------------------------------------------------------- | |
15 |
|
15 | |||
16 | import Queue |
|
16 | try: | |
|
17 | from queue import Queue, Empty # Py 3 | |||
|
18 | except ImportError: | |||
|
19 | from Queue import Queue, Empty # Py 2 | |||
17 |
|
20 | |||
18 | from IPython.kernel.channels import IOPubChannel, HBChannel, \ |
|
21 | from IPython.kernel.channels import IOPubChannel, HBChannel, \ | |
19 | ShellChannel, StdInChannel |
|
22 | ShellChannel, StdInChannel | |
@@ -27,7 +30,7 b' class BlockingChannelMixin(object):' | |||||
27 |
|
30 | |||
28 | def __init__(self, *args, **kwds): |
|
31 | def __init__(self, *args, **kwds): | |
29 | super(BlockingChannelMixin, self).__init__(*args, **kwds) |
|
32 | super(BlockingChannelMixin, self).__init__(*args, **kwds) | |
30 |
self._in_queue = Queue |
|
33 | self._in_queue = Queue() | |
31 |
|
34 | |||
32 | def call_handlers(self, msg): |
|
35 | def call_handlers(self, msg): | |
33 | self._in_queue.put(msg) |
|
36 | self._in_queue.put(msg) | |
@@ -46,7 +49,7 b' class BlockingChannelMixin(object):' | |||||
46 | while True: |
|
49 | while True: | |
47 | try: |
|
50 | try: | |
48 | msgs.append(self.get_msg(block=False)) |
|
51 | msgs.append(self.get_msg(block=False)) | |
49 |
except |
|
52 | except Empty: | |
50 | break |
|
53 | break | |
51 | return msgs |
|
54 | return msgs | |
52 |
|
55 |
@@ -13,7 +13,10 b'' | |||||
13 |
|
13 | |||
14 | # Standard library imports. |
|
14 | # Standard library imports. | |
15 | import abc |
|
15 | import abc | |
16 | import Queue |
|
16 | try: | |
|
17 | from queue import Queue # Py 3 | |||
|
18 | except ImportError: | |||
|
19 | from Queue import Queue # Py 2 | |||
17 |
|
20 | |||
18 | # System library imports. |
|
21 | # System library imports. | |
19 | import zmq |
|
22 | import zmq | |
@@ -45,7 +48,7 b' SocketABC.register(zmq.Socket)' | |||||
45 | class DummySocket(HasTraits): |
|
48 | class DummySocket(HasTraits): | |
46 | """ A dummy socket implementing (part of) the zmq.Socket interface. """ |
|
49 | """ A dummy socket implementing (part of) the zmq.Socket interface. """ | |
47 |
|
50 | |||
48 |
queue = Instance(Queue |
|
51 | queue = Instance(Queue, ()) | |
49 | message_sent = Int(0) # Should be an Event |
|
52 | message_sent = Int(0) # Should be an Event | |
50 |
|
53 | |||
51 | #------------------------------------------------------------------------- |
|
54 | #------------------------------------------------------------------------- |
@@ -11,7 +11,7 b'' | |||||
11 | from __future__ import print_function |
|
11 | from __future__ import print_function | |
12 |
|
12 | |||
13 | # Standard library imports |
|
13 | # Standard library imports | |
14 |
from |
|
14 | from io import StringIO | |
15 | import sys |
|
15 | import sys | |
16 | import unittest |
|
16 | import unittest | |
17 |
|
17 |
@@ -9,7 +9,10 b'' | |||||
9 |
|
9 | |||
10 | import re |
|
10 | import re | |
11 | from subprocess import PIPE |
|
11 | from subprocess import PIPE | |
12 | from Queue import Empty |
|
12 | try: | |
|
13 | from queue import Empty # Py 3 | |||
|
14 | except ImportError: | |||
|
15 | from Queue import Empty # Py 2 | |||
13 |
|
16 | |||
14 | import nose.tools as nt |
|
17 | import nose.tools as nt | |
15 |
|
18 |
@@ -15,7 +15,10 b' import atexit' | |||||
15 |
|
15 | |||
16 | from contextlib import contextmanager |
|
16 | from contextlib import contextmanager | |
17 | from subprocess import PIPE, STDOUT |
|
17 | from subprocess import PIPE, STDOUT | |
18 | from Queue import Empty |
|
18 | try: | |
|
19 | from queue import Empty # Py 3 | |||
|
20 | except ImportError: | |||
|
21 | from Queue import Empty # Py 2 | |||
19 |
|
22 | |||
20 | import nose |
|
23 | import nose | |
21 | import nose.tools as nt |
|
24 | import nose.tools as nt |
@@ -92,14 +92,17 b' def loop_wx(kernel):' | |||||
92 | def loop_tk(kernel): |
|
92 | def loop_tk(kernel): | |
93 | """Start a kernel with the Tk event loop.""" |
|
93 | """Start a kernel with the Tk event loop.""" | |
94 |
|
94 | |||
95 | import Tkinter |
|
95 | try: | |
|
96 | from tkinter import Tk # Py 3 | |||
|
97 | except ImportError: | |||
|
98 | from Tkinter import Tk # Py 2 | |||
96 | doi = kernel.do_one_iteration |
|
99 | doi = kernel.do_one_iteration | |
97 | # Tk uses milliseconds |
|
100 | # Tk uses milliseconds | |
98 | poll_interval = int(1000*kernel._poll_interval) |
|
101 | poll_interval = int(1000*kernel._poll_interval) | |
99 | # For Tkinter, we create a Tk object and call its withdraw method. |
|
102 | # For Tkinter, we create a Tk object and call its withdraw method. | |
100 | class Timer(object): |
|
103 | class Timer(object): | |
101 | def __init__(self, func): |
|
104 | def __init__(self, func): | |
102 |
self.app = |
|
105 | self.app = Tk() | |
103 | self.app.withdraw() |
|
106 | self.app.withdraw() | |
104 | self.func = func |
|
107 | self.func = func | |
105 |
|
108 |
@@ -6,7 +6,10 b' except:' | |||||
6 | import os |
|
6 | import os | |
7 | import platform |
|
7 | import platform | |
8 | import time |
|
8 | import time | |
9 | from thread import interrupt_main |
|
9 | try: | |
|
10 | from _thread import interrupt_main # Py 3 | |||
|
11 | except ImportError: | |||
|
12 | from thread import interrupt_main # Py 2 | |||
10 | from threading import Thread |
|
13 | from threading import Thread | |
11 |
|
14 | |||
12 | from IPython.utils.warn import warn |
|
15 | from IPython.utils.warn import warn |
@@ -41,11 +41,14 b' def tkinter_clipboard_get():' | |||||
41 | implementation that uses that toolkit. |
|
41 | implementation that uses that toolkit. | |
42 | """ |
|
42 | """ | |
43 | try: |
|
43 | try: | |
44 | import Tkinter |
|
44 | from tkinter import Tk # Py 3 | |
|
45 | except ImportError: | |||
|
46 | try: | |||
|
47 | from Tkinter import Tk # Py 2 | |||
45 | except ImportError: |
|
48 | except ImportError: | |
46 | raise TryNext("Getting text from the clipboard on this platform " |
|
49 | raise TryNext("Getting text from the clipboard on this platform " | |
47 | "requires Tkinter.") |
|
50 | "requires Tkinter.") | |
48 |
root = |
|
51 | root = Tk() | |
49 | root.withdraw() |
|
52 | root.withdraw() | |
50 | text = root.clipboard_get() |
|
53 | text = root.clipboard_get() | |
51 | root.destroy() |
|
54 | root.destroy() |
@@ -320,8 +320,8 b' class InputHookManager(object):' | |||||
320 | """ |
|
320 | """ | |
321 | self._current_gui = GUI_TK |
|
321 | self._current_gui = GUI_TK | |
322 | if app is None: |
|
322 | if app is None: | |
323 |
import |
|
323 | import tkinter | |
324 |
app = |
|
324 | app = tkinter.Tk() | |
325 | app.withdraw() |
|
325 | app.withdraw() | |
326 | self._apps[GUI_TK] = app |
|
326 | self._apps[GUI_TK] = app | |
327 | return app |
|
327 | return app |
@@ -109,7 +109,7 b' import sys' | |||||
109 | import types |
|
109 | import types | |
110 | import re |
|
110 | import re | |
111 | import datetime |
|
111 | import datetime | |
112 |
from |
|
112 | from io import StringIO | |
113 | from collections import deque |
|
113 | from collections import deque | |
114 |
|
114 | |||
115 |
|
115 |
@@ -8,7 +8,7 b' from __future__ import print_function' | |||||
8 | VERBOSE = True |
|
8 | VERBOSE = True | |
9 |
|
9 | |||
10 | # stdlib imports |
|
10 | # stdlib imports | |
11 |
import |
|
11 | import io | |
12 | import sys |
|
12 | import sys | |
13 | import unittest |
|
13 | import unittest | |
14 |
|
14 | |||
@@ -20,7 +20,7 b' from IPython.utils.py3compat import doctest_refactor_print' | |||||
20 | class RunnerTestCase(unittest.TestCase): |
|
20 | class RunnerTestCase(unittest.TestCase): | |
21 |
|
21 | |||
22 | def setUp(self): |
|
22 | def setUp(self): | |
23 |
self.out = |
|
23 | self.out = io.StringIO() | |
24 | #self.out = sys.stdout |
|
24 | #self.out = sys.stdout | |
25 |
|
25 | |||
26 | def _test_runner(self,runner,source,output): |
|
26 | def _test_runner(self,runner,source,output): |
@@ -7,7 +7,7 b' from __future__ import print_function' | |||||
7 | VERBOSE = True |
|
7 | VERBOSE = True | |
8 |
|
8 | |||
9 | # stdlib imports |
|
9 | # stdlib imports | |
10 |
import |
|
10 | import io | |
11 | import sys |
|
11 | import sys | |
12 | import unittest |
|
12 | import unittest | |
13 | import re |
|
13 | import re | |
@@ -28,7 +28,7 b' def pylab_not_importable():' | |||||
28 | class RunnerTestCase(unittest.TestCase): |
|
28 | class RunnerTestCase(unittest.TestCase): | |
29 |
|
29 | |||
30 | def setUp(self): |
|
30 | def setUp(self): | |
31 |
self.out = |
|
31 | self.out = io.StringIO() | |
32 | #self.out = sys.stdout |
|
32 | #self.out = sys.stdout | |
33 |
|
33 | |||
34 | def _test_runner(self,runner,source,output): |
|
34 | def _test_runner(self,runner,source,output): |
@@ -15,7 +15,7 b' Module with tests for debug' | |||||
15 | #----------------------------------------------------------------------------- |
|
15 | #----------------------------------------------------------------------------- | |
16 |
|
16 | |||
17 | import sys |
|
17 | import sys | |
18 |
from |
|
18 | from io import StringIO | |
19 |
|
19 | |||
20 | from ...tests.base import TestsBase |
|
20 | from ...tests.base import TestsBase | |
21 | from ..debug import DebugWriter |
|
21 | from ..debug import DebugWriter |
@@ -16,7 +16,7 b' Module with tests for files' | |||||
16 |
|
16 | |||
17 | import sys |
|
17 | import sys | |
18 | import os |
|
18 | import os | |
19 |
from |
|
19 | from io import StringIO | |
20 |
|
20 | |||
21 | from ...tests.base import TestsBase |
|
21 | from ...tests.base import TestsBase | |
22 | from ..files import FilesWriter |
|
22 | from ..files import FilesWriter |
@@ -15,7 +15,7 b' Module with tests for stdout' | |||||
15 | #----------------------------------------------------------------------------- |
|
15 | #----------------------------------------------------------------------------- | |
16 |
|
16 | |||
17 | import sys |
|
17 | import sys | |
18 |
from |
|
18 | from io import StringIO | |
19 |
|
19 | |||
20 | from ...tests.base import TestsBase |
|
20 | from ...tests.base import TestsBase | |
21 | from ..stdout import StdoutWriter |
|
21 | from ..stdout import StdoutWriter |
@@ -13,7 +13,10 b' Authors:' | |||||
13 |
|
13 | |||
14 | import json |
|
14 | import json | |
15 | import os |
|
15 | import os | |
|
16 | try: | |||
16 | import cPickle as pickle |
|
17 | import cPickle as pickle | |
|
18 | except ImportError: | |||
|
19 | import pickle | |||
17 | from datetime import datetime |
|
20 | from datetime import datetime | |
18 |
|
21 | |||
19 | try: |
|
22 | try: |
@@ -16,7 +16,7 b' from __future__ import print_function' | |||||
16 | import sys |
|
16 | import sys | |
17 | import tempfile |
|
17 | import tempfile | |
18 | import time |
|
18 | import time | |
19 |
from |
|
19 | from io import StringIO | |
20 |
|
20 | |||
21 | from nose import SkipTest |
|
21 | from nose import SkipTest | |
22 |
|
22 |
@@ -58,7 +58,7 b' from __future__ import print_function' | |||||
58 | #----------------------------------------------------------------------------- |
|
58 | #----------------------------------------------------------------------------- | |
59 |
|
59 | |||
60 | # Stdlib |
|
60 | # Stdlib | |
61 |
import |
|
61 | import io | |
62 | import os |
|
62 | import os | |
63 | import re |
|
63 | import re | |
64 | import sys |
|
64 | import sys | |
@@ -193,7 +193,7 b' class EmbeddedSphinxShell(object):' | |||||
193 |
|
193 | |||
194 | def __init__(self): |
|
194 | def __init__(self): | |
195 |
|
195 | |||
196 |
self.cout = |
|
196 | self.cout = io.StringIO() | |
197 |
|
197 | |||
198 |
|
198 | |||
199 | # Create config object for IPython |
|
199 | # Create config object for IPython |
@@ -1,6 +1,9 b'' | |||||
1 | # -*- coding: utf-8 -*- |
|
1 | # -*- coding: utf-8 -*- | |
2 | import readline |
|
2 | import readline | |
3 | from Queue import Empty |
|
3 | try: | |
|
4 | from queue import Empty # Py 3 | |||
|
5 | except ImportError: | |||
|
6 | from Queue import Empty # Py 2 | |||
4 |
|
7 | |||
5 | from IPython.config import Configurable |
|
8 | from IPython.config import Configurable | |
6 | from IPython.utils.traitlets import Float |
|
9 | from IPython.utils.traitlets import Float |
@@ -23,7 +23,10 b' import subprocess' | |||||
23 | from io import BytesIO |
|
23 | from io import BytesIO | |
24 | import base64 |
|
24 | import base64 | |
25 |
|
25 | |||
26 | from Queue import Empty |
|
26 | try: | |
|
27 | from queue import Empty # Py 3 | |||
|
28 | except ImportError: | |||
|
29 | from Queue import Empty # Py 2 | |||
27 |
|
30 | |||
28 | from IPython.core import page |
|
31 | from IPython.core import page | |
29 | from IPython.utils.warn import warn, error |
|
32 | from IPython.utils.warn import warn, error |
@@ -19,7 +19,6 b' Limitations:' | |||||
19 | # Module imports |
|
19 | # Module imports | |
20 |
|
20 | |||
21 | # From the standard library |
|
21 | # From the standard library | |
22 | import commands |
|
|||
23 | import doctest |
|
22 | import doctest | |
24 | import inspect |
|
23 | import inspect | |
25 | import logging |
|
24 | import logging | |
@@ -30,7 +29,7 b' import traceback' | |||||
30 | import unittest |
|
29 | import unittest | |
31 |
|
30 | |||
32 | from inspect import getmodule |
|
31 | from inspect import getmodule | |
33 |
from |
|
32 | from io import StringIO | |
34 |
|
33 | |||
35 | # We are overriding the default doctest runner, so we need to import a few |
|
34 | # We are overriding the default doctest runner, so we need to import a few | |
36 | # things from doctest directly |
|
35 | # things from doctest directly |
@@ -38,7 +38,7 b" _scheme_default = 'Linux'" | |||||
38 |
|
38 | |||
39 |
|
39 | |||
40 | # Imports |
|
40 | # Imports | |
41 |
import |
|
41 | import io | |
42 | import keyword |
|
42 | import keyword | |
43 | import os |
|
43 | import os | |
44 | import sys |
|
44 | import sys | |
@@ -143,13 +143,13 b' class Parser:' | |||||
143 |
|
143 | |||
144 | string_output = 0 |
|
144 | string_output = 0 | |
145 | if out == 'str' or self.out == 'str' or \ |
|
145 | if out == 'str' or self.out == 'str' or \ | |
146 |
isinstance(self.out, |
|
146 | isinstance(self.out,io.StringIO): | |
147 | # XXX - I don't really like this state handling logic, but at this |
|
147 | # XXX - I don't really like this state handling logic, but at this | |
148 | # point I don't want to make major changes, so adding the |
|
148 | # point I don't want to make major changes, so adding the | |
149 | # isinstance() check is the simplest I can do to ensure correct |
|
149 | # isinstance() check is the simplest I can do to ensure correct | |
150 | # behavior. |
|
150 | # behavior. | |
151 | out_old = self.out |
|
151 | out_old = self.out | |
152 |
self.out = |
|
152 | self.out = io.StringIO() | |
153 | string_output = 1 |
|
153 | string_output = 1 | |
154 | elif out is not None: |
|
154 | elif out is not None: | |
155 | self.out = out |
|
155 | self.out = out | |
@@ -183,7 +183,7 b' class Parser:' | |||||
183 |
|
183 | |||
184 | # parse the source and write it |
|
184 | # parse the source and write it | |
185 | self.pos = 0 |
|
185 | self.pos = 0 | |
186 |
text = |
|
186 | text = io.StringIO(self.raw) | |
187 |
|
187 | |||
188 | error = False |
|
188 | error = False | |
189 | try: |
|
189 | try: |
@@ -16,7 +16,7 b' from __future__ import print_function' | |||||
16 | #----------------------------------------------------------------------------- |
|
16 | #----------------------------------------------------------------------------- | |
17 |
|
17 | |||
18 | import sys |
|
18 | import sys | |
19 |
from |
|
19 | from io import StringIO | |
20 |
|
20 | |||
21 | #----------------------------------------------------------------------------- |
|
21 | #----------------------------------------------------------------------------- | |
22 | # Classes and functions |
|
22 | # Classes and functions |
@@ -24,7 +24,11 b' __docformat__ = "restructuredtext en"' | |||||
24 | #------------------------------------------------------------------------------- |
|
24 | #------------------------------------------------------------------------------- | |
25 |
|
25 | |||
26 | import sys |
|
26 | import sys | |
27 |
import types |
|
27 | import types | |
|
28 | try: | |||
|
29 | import copyreg # Py 3 | |||
|
30 | except ImportError: | |||
|
31 | import copy_reg as copyreg # Py 2 | |||
28 |
|
32 | |||
29 | def code_ctor(*args): |
|
33 | def code_ctor(*args): | |
30 | return types.CodeType(*args) |
|
34 | return types.CodeType(*args) | |
@@ -40,4 +44,4 b' def reduce_code(co):' | |||||
40 | args.insert(1, co.co_kwonlyargcount) |
|
44 | args.insert(1, co.co_kwonlyargcount) | |
41 | return code_ctor, tuple(args) |
|
45 | return code_ctor, tuple(args) | |
42 |
|
46 | |||
43 |
copy |
|
47 | copyreg.pickle(types.CodeType, reduce_code) No newline at end of file |
@@ -17,7 +17,6 b' from __future__ import print_function' | |||||
17 | import os |
|
17 | import os | |
18 | import sys |
|
18 | import sys | |
19 | import tempfile |
|
19 | import tempfile | |
20 | from StringIO import StringIO |
|
|||
21 | from .capture import CapturedIO, capture_output |
|
20 | from .capture import CapturedIO, capture_output | |
22 | from .py3compat import string_types |
|
21 | from .py3compat import string_types | |
23 |
|
22 |
@@ -206,7 +206,10 b' def get_home_dir(require_writable=False):' | |||||
206 | if not _writable_dir(homedir) and os.name == 'nt': |
|
206 | if not _writable_dir(homedir) and os.name == 'nt': | |
207 | # expanduser failed, use the registry to get the 'My Documents' folder. |
|
207 | # expanduser failed, use the registry to get the 'My Documents' folder. | |
208 | try: |
|
208 | try: | |
209 | import _winreg as wreg |
|
209 | try: | |
|
210 | import winreg as wreg # Py 3 | |||
|
211 | except ImportError: | |||
|
212 | import _winreg as wreg # Py 2 | |||
210 | key = wreg.OpenKey( |
|
213 | key = wreg.OpenKey( | |
211 | wreg.HKEY_CURRENT_USER, |
|
214 | wreg.HKEY_CURRENT_USER, | |
212 | "Software\Microsoft\Windows\CurrentVersion\Explorer\Shell Folders" |
|
215 | "Software\Microsoft\Windows\CurrentVersion\Explorer\Shell Folders" |
@@ -37,7 +37,10 b' from __future__ import print_function' | |||||
37 | from IPython.external.path import path as Path |
|
37 | from IPython.external.path import path as Path | |
38 | import os,stat,time |
|
38 | import os,stat,time | |
39 | import collections |
|
39 | import collections | |
|
40 | try: | |||
40 | import cPickle as pickle |
|
41 | import cPickle as pickle | |
|
42 | except ImportError: | |||
|
43 | import pickle | |||
41 | import glob |
|
44 | import glob | |
42 |
|
45 | |||
43 | def gethashfile(key): |
|
46 | def gethashfile(key): |
@@ -15,7 +15,7 b' from __future__ import print_function' | |||||
15 |
|
15 | |||
16 | import sys |
|
16 | import sys | |
17 |
|
17 | |||
18 |
from |
|
18 | from io import StringIO | |
19 | from subprocess import Popen, PIPE |
|
19 | from subprocess import Popen, PIPE | |
20 | import unittest |
|
20 | import unittest | |
21 |
|
21 |
@@ -37,12 +37,18 b' from IPython.utils.tempdir import TemporaryDirectory' | |||||
37 |
|
37 | |||
38 | # Platform-dependent imports |
|
38 | # Platform-dependent imports | |
39 | try: |
|
39 | try: | |
40 |
import |
|
40 | import winreg as wreg # Py 3 | |
|
41 | except ImportError: | |||
|
42 | try: | |||
|
43 | import _winreg as wreg # Py 2 | |||
41 | except ImportError: |
|
44 | except ImportError: | |
42 | #Fake _winreg module on none windows platforms |
|
45 | #Fake _winreg module on none windows platforms | |
43 | import types |
|
46 | import types | |
44 | wr_name = "winreg" if py3compat.PY3 else "_winreg" |
|
47 | wr_name = "winreg" if py3compat.PY3 else "_winreg" | |
45 | sys.modules[wr_name] = types.ModuleType(wr_name) |
|
48 | sys.modules[wr_name] = types.ModuleType(wr_name) | |
|
49 | try: | |||
|
50 | import winreg as wreg | |||
|
51 | except ImportError: | |||
46 | import _winreg as wreg |
|
52 | import _winreg as wreg | |
47 | #Add entries that needs to be stubbed by the testing code |
|
53 | #Add entries that needs to be stubbed by the testing code | |
48 | (wreg.OpenKey, wreg.QueryValueEx,) = (None, None) |
|
54 | (wreg.OpenKey, wreg.QueryValueEx,) = (None, None) |
General Comments 0
You need to be logged in to leave comments.
Login now