[py-svn] r7937 - py/dist/py/magic
hpk at codespeak.net
hpk at codespeak.net
Sun Dec 19 18:42:22 CET 2004
Author: hpk
Date: Sun Dec 19 18:42:22 2004
New Revision: 7937
Modified:
py/dist/py/magic/exprinfo.py
Log:
getting rid of dyncode part 3
Modified: py/dist/py/magic/exprinfo.py
==============================================================================
--- py/dist/py/magic/exprinfo.py (original)
+++ py/dist/py/magic/exprinfo.py Sun Dec 19 18:42:22 2004
@@ -1,7 +1,5 @@
from compiler import parse, ast, pycodegen
-from py import magic
-from py.__impl__.magic import dyncode
-from py.code import RunnerFrame
+import py
import __builtin__, sys
passthroughex = (KeyboardInterrupt, SystemExit, MemoryError)
@@ -13,7 +11,7 @@
#import traceback
#traceback.print_exc()
-class Interpretable(magic.View):
+class Interpretable(py.magic.View):
"""A parse tree node with a few extra methods."""
explanation = None
@@ -377,7 +375,7 @@
if frame is None:
import sys
frame = sys._getframe(1)
- frame = RunnerFrame(frame)
+ frame = py.code.RunnerFrame(frame)
expr = parse(s, 'eval')
assert isinstance(expr, ast.Expression)
node = Interpretable(expr.node)
@@ -396,24 +394,11 @@
# API / Entry points
# #########################################################
-def getframeline(f, lineno=None):
- if lineno is None:
- lineno = f.lineno
- co = f.code
-
- filename = co.co_filename
- line = magic.dyncode.getline(filename, lineno)
- if line:
- line = line.strip()
- else:
- line = None
- return line
-
def interpret(source, frame):
module = Interpretable(parse(source, 'exec').node)
#print "got module", module
- if not isinstance(frame, RunnerFrame):
- frame = RunnerFrame(frame)
+ if not isinstance(frame, py.code.RunnerFrame):
+ frame = py.code.RunnerFrame(frame)
try:
return module.run(frame) # None if no exception generated
except Failure, e:
@@ -424,21 +409,15 @@
import traceback
traceback.print_exc()
-def gettbline(tb, index=-1):
- tb = magic.dyncode.listtb(tb)[-1]
- f = tb.tb_frame
- return f, getframeline(f, tb.tb_lineno)
-
def getmsg((typ, val, tb)):
#frame, line = gettbline(tb)
- #frame = RunnerFrame(frame)
+ #frame = py.code.RunnerFrame(frame)
#return interpret(line, frame)
-
- tb = magic.dyncode.listtb(tb)[-1]
- source = dyncode.getparseablestartingblock(tb)
- frame = tb.tb_frame
- frame = RunnerFrame(frame)
- x = interpret(source, frame)
+
+ excinfo = py.code.ExceptionInfo((typ, val, tb))
+ tb = list(excinfo)[-1]
+ source = str(tb.statement).strip()
+ x = interpret(source, tb.frame)
if not isinstance(x, str):
raise TypeError, "interpret returned non-string %r" % (x,)
return x
@@ -454,7 +433,7 @@
if frame is None:
import sys
frame = sys._getframe(1)
- frame = RunnerFrame(frame)
+ frame = py.code.RunnerFrame(frame)
module = Interpretable(parse(s, 'exec').node)
try:
module.run(frame)
More information about the pytest-commit
mailing list