##// END OF EJS Templates
Using R. Kern's code to try to get better tracebacks....
Fernando Perez -
Show More
@@ -137,6 +137,38 b' class MultipleInstanceError(Exception):'
137 #-----------------------------------------------------------------------------
137 #-----------------------------------------------------------------------------
138
138
139
139
140 ######## Code to be moved later if it works, meant to try to get proper
141 ######## tracebacks
142
143 import hashlib
144 import linecache
145 import time
146 import types
147
148 def code_name(code):
149 """ Compute a (probably) unique name for code for caching.
150 """
151 hash_digest = hashlib.md5(code).hexdigest()
152 return '<code %s>' % hash_digest
153
154
155 class CachingCompiler(codeop.CommandCompiler):
156
157 def __call__(self, code, filename, symbol):
158 """ Compile some code while caching its contents such that the inspect
159 module can find it later.
160 """
161 #code += '\n'
162 name = code_name(code)
163 code_obj = codeop.CommandCompiler.__call__(self, code, name, symbol)
164 linecache.cache[name] = (len(code),
165 time.time(),
166 [line+'\n' for line in code.splitlines()],
167 name)
168 return code_obj
169
170 #############
171
140 class InteractiveShell(Configurable, Magic):
172 class InteractiveShell(Configurable, Magic):
141 """An enhanced, interactive shell for Python."""
173 """An enhanced, interactive shell for Python."""
142
174
@@ -369,8 +401,9 b' class InteractiveShell(Configurable, Magic):'
369 self.more = False
401 self.more = False
370
402
371 # command compiler
403 # command compiler
372 self.compile = codeop.CommandCompiler()
404 #self.compile = codeop.CommandCompiler()
373
405 self.compile = CachingCompiler()
406
374 # User input buffers
407 # User input buffers
375 # NOTE: these variables are slated for full removal, once we are 100%
408 # NOTE: these variables are slated for full removal, once we are 100%
376 # sure that the new execution logic is solid. We will delte runlines,
409 # sure that the new execution logic is solid. We will delte runlines,
General Comments 0
You need to be logged in to leave comments. Login now