Show More
@@ -104,9 +104,9 b' from IPython.core.display_trap import DisplayTrap' | |||||
104 | from IPython.core.excolors import exception_colors |
|
104 | from IPython.core.excolors import exception_colors | |
105 | from IPython.utils import PyColorize |
|
105 | from IPython.utils import PyColorize | |
106 | from IPython.utils import io |
|
106 | from IPython.utils import io | |
|
107 | from IPython.utils import openpy | |||
107 | from IPython.utils import path as util_path |
|
108 | from IPython.utils import path as util_path | |
108 | from IPython.utils import py3compat |
|
109 | from IPython.utils import py3compat | |
109 | from IPython.utils import pyfile |
|
|||
110 | from IPython.utils import ulinecache |
|
110 | from IPython.utils import ulinecache | |
111 | from IPython.utils.data import uniq_stable |
|
111 | from IPython.utils.data import uniq_stable | |
112 | from IPython.utils.warn import info, error |
|
112 | from IPython.utils.warn import info, error | |
@@ -837,7 +837,7 b' class VerboseTB(TBTools):' | |||||
837 | continue |
|
837 | continue | |
838 | elif file.endswith(('.pyc','.pyo')): |
|
838 | elif file.endswith(('.pyc','.pyo')): | |
839 | # Look up the corresponding source file. |
|
839 | # Look up the corresponding source file. | |
840 |
file = p |
|
840 | file = openpy.source_from_cache(file) | |
841 |
|
841 | |||
842 | def linereader(file=file, lnum=[lnum], getline=ulinecache.getline): |
|
842 | def linereader(file=file, lnum=[lnum], getline=ulinecache.getline): | |
843 | line = getline(file, lnum[0]) |
|
843 | line = getline(file, lnum[0]) |
@@ -119,7 +119,7 b' try:' | |||||
119 | except NameError: |
|
119 | except NameError: | |
120 | from imp import reload |
|
120 | from imp import reload | |
121 |
|
121 | |||
122 |
from IPython.utils import p |
|
122 | from IPython.utils import openpy | |
123 | from IPython.utils.py3compat import PY3 |
|
123 | from IPython.utils.py3compat import PY3 | |
124 |
|
124 | |||
125 | #------------------------------------------------------------------------------ |
|
125 | #------------------------------------------------------------------------------ | |
@@ -207,12 +207,12 b' class ModuleReloader(object):' | |||||
207 | path, ext = os.path.splitext(filename) |
|
207 | path, ext = os.path.splitext(filename) | |
208 |
|
208 | |||
209 | if ext.lower() == '.py': |
|
209 | if ext.lower() == '.py': | |
210 |
pyc_filename = p |
|
210 | pyc_filename = openpy.cache_from_source(filename) | |
211 | py_filename = filename |
|
211 | py_filename = filename | |
212 | else: |
|
212 | else: | |
213 | pyc_filename = filename |
|
213 | pyc_filename = filename | |
214 | try: |
|
214 | try: | |
215 |
py_filename = p |
|
215 | py_filename = openpy.source_from_cache(filename) | |
216 | except ValueError: |
|
216 | except ValueError: | |
217 | continue |
|
217 | continue | |
218 |
|
218 |
@@ -8,6 +8,7 b' from __future__ import absolute_import' | |||||
8 |
|
8 | |||
9 | import io |
|
9 | import io | |
10 | from io import TextIOWrapper, BytesIO |
|
10 | from io import TextIOWrapper, BytesIO | |
|
11 | import os.path | |||
11 | import re |
|
12 | import re | |
12 |
|
13 | |||
13 | cookie_re = re.compile(ur"coding[:=]\s*([-\w.]+)", re.UNICODE) |
|
14 | cookie_re = re.compile(ur"coding[:=]\s*([-\w.]+)", re.UNICODE) | |
@@ -217,3 +218,22 b' def _list_readline(x):' | |||||
217 | def readline(): |
|
218 | def readline(): | |
218 | return next(x) |
|
219 | return next(x) | |
219 | return readline |
|
220 | return readline | |
|
221 | ||||
|
222 | # Code for going between .py files and cached .pyc files ---------------------- | |||
|
223 | ||||
|
224 | try: # Python 3.2, see PEP 3147 | |||
|
225 | from imp import source_from_cache, cache_from_source | |||
|
226 | except ImportError: | |||
|
227 | # Python <= 3.1: .pyc files go next to .py | |||
|
228 | def source_from_cache(path): | |||
|
229 | basename, ext = os.path.splitext(path) | |||
|
230 | if ext not in ('.pyc', '.pyo'): | |||
|
231 | raise ValueError('Not a cached Python file extension', ext) | |||
|
232 | # Should we look for .pyw files? | |||
|
233 | return basename + '.py' | |||
|
234 | ||||
|
235 | def cache_from_source(path, debug_override=None): | |||
|
236 | if debug_override is None: | |||
|
237 | debug_override = __debug__ | |||
|
238 | basename, ext = os.path.splitext(path) | |||
|
239 | return basename + '.pyc' if debug_override else '.pyo' |
1 | NO CONTENT: file was removed |
|
NO CONTENT: file was removed |
General Comments 0
You need to be logged in to leave comments.
Login now