[pypy-svn] r8632 - in pypy/dist/pypy: interpreter tool
sanxiyn at codespeak.net
sanxiyn at codespeak.net
Thu Jan 27 13:30:04 CET 2005
Author: sanxiyn
Date: Thu Jan 27 13:30:04 2005
New Revision: 8632
Modified:
pypy/dist/pypy/interpreter/error.py
pypy/dist/pypy/interpreter/interactive.py
pypy/dist/pypy/interpreter/main.py
pypy/dist/pypy/interpreter/py.py
pypy/dist/pypy/tool/option.py
pypy/dist/pypy/tool/pytestsupport.py
Log:
1) pypy -v was not used and broken
2) So let's use -v for PYPY_TB
3) pypy.interpreter.error.PyPyError removed
4) Use errorstr() in both interp and appl level traceback
5) pypy.main has main() no more used
Modified: pypy/dist/pypy/interpreter/error.py
==============================================================================
--- pypy/dist/pypy/interpreter/error.py (original)
+++ pypy/dist/pypy/interpreter/error.py Thu Jan 27 13:30:04 2005
@@ -1,14 +1,6 @@
import os, sys
AUTO_DEBUG = os.getenv('PYPY_DEBUG')
-INTERP_LEVEL_TRACEBACK = os.getenv('PYPY_TB')
-
-
-class PyPyError(Exception):
- "Raise this when you encounter an exceptional situation in PyPy itself."
- def __init__(self, space, operationerr):
- self.space = space
- self.operationerr = operationerr
class OperationError(Exception):
@@ -44,10 +36,24 @@
def errorstr(self, space):
"NOT_RPYTHON: The exception class and value, as a string."
- exc_type = space.str_w(
- space.getattr(self.w_type, space.wrap('__name__')))
- exc_value = space.str_w(space.str(self.w_value))
- return '%s: %s' % (exc_type, exc_value)
+ if space is None:
+ exc_typename = str(self.w_type)
+ exc_value = self.w_value
+ else:
+ w = space.wrap
+ if space.is_true(space.is_(space.type(self.w_type), space.w_str)):
+ exc_typename = space.str_w(self.w_type)
+ else:
+ exc_typename = space.str_w(
+ space.getattr(self.w_type, w('__name__')))
+ if self.w_value == space.w_None:
+ exc_value = None
+ else:
+ exc_value = space.str_w(space.str(self.w_value))
+ if not exc_value:
+ return exc_typename
+ else:
+ return '%s: %s' % (exc_typename, exc_value)
def getframe(self):
"The frame this exception was raised in, or None."
@@ -101,38 +107,16 @@
import traceback, cStringIO
if file is None: file = sys.stderr
f = cStringIO.StringIO()
- if not INTERP_LEVEL_TRACEBACK:
- print >> f, ("Traceback (interpreter-level): "
- "hidden ($PYPY_TB not set)")
- else:
- for i in range(len(self.debug_excs)-1, -1, -1):
- print >> f, "Traceback (interpreter-level):"
- traceback.print_tb(self.debug_excs[i][2], file=f)
+ for i in range(len(self.debug_excs)-1, -1, -1):
+ print >> f, "Traceback (interpreter-level):"
+ traceback.print_tb(self.debug_excs[i][2], file=f)
f.seek(0)
debug_print(''.join(['|| ' + line for line in f.readlines()]), file)
if self.debug_excs:
from pypy.tool import tb_server
tb_server.publish_exc(self.debug_excs[-1])
self.print_app_tb_only(file)
- if space is None:
- exc_typename = str(self.w_type)
- exc_value = self.w_value
- else:
- w = space.wrap
- if space.is_true(space.is_(space.type(self.w_type), space.w_str)):
- exc_typename = space.str_w(self.w_type)
- else:
- exc_typename = space.str_w(
- space.getattr(self.w_type, w('__name__')))
- if self.w_value == space.w_None:
- exc_value = None
- else:
- exc_value = space.str_w(space.str(self.w_value))
- print >> file, '(application-level)',
- if not exc_value:
- print >> file, exc_typename
- else:
- print >> file, exc_typename+':', exc_value
+ print >> file, '(application-level)', self.errorstr(space)
if AUTO_DEBUG:
import debug
debug.fire(self)
Modified: pypy/dist/pypy/interpreter/interactive.py
==============================================================================
--- pypy/dist/pypy/interpreter/interactive.py (original)
+++ pypy/dist/pypy/interpreter/interactive.py Thu Jan 27 13:30:04 2005
@@ -1,14 +1,16 @@
import autopath
+from pypy.interpreter import error
from pypy.interpreter import executioncontext, baseobjspace
import sys
import code
class PyPyConsole(code.InteractiveConsole):
- def __init__(self, objspace):
+ def __init__(self, objspace, verbose=0):
code.InteractiveConsole.__init__(self)
self.space = objspace
+ self.verbose = verbose
self.ec = executioncontext.ExecutionContext(self.space)
self.w_globals = self.ec.make_standard_w_globals()
self.space.setitem(self.w_globals,
@@ -54,13 +56,16 @@
pycode = PyCode(self.space)._from_code(code)
try:
pycode.exec_code(self.space, self.w_globals, self.w_globals)
- except baseobjspace.OperationError, operationerr:
+ except error.OperationError, operationerr:
space = self.space
if operationerr.match(space, space.w_SystemExit):
# XXX fetch the exit code from somewhere inside the w_SystemExit
raise SystemExit
# XXX insert exception info into the application-level sys.last_xxx
- operationerr.print_detailed_traceback(space)
+ if self.verbose:
+ operationerr.print_detailed_traceback(space)
+ else:
+ operationerr.print_application_traceback(space)
# for debugging convenience we also insert the exception into
# the interpreter-level sys.last_xxx
sys.last_type, sys.last_value, sys.last_traceback = sys.exc_info()
Modified: pypy/dist/pypy/interpreter/main.py
==============================================================================
--- pypy/dist/pypy/interpreter/main.py (original)
+++ pypy/dist/pypy/interpreter/main.py Thu Jan 27 13:30:04 2005
@@ -1,7 +1,6 @@
import autopath
-from pypy.tool import option
from pypy.interpreter import executioncontext, module
-from pypy.interpreter.error import OperationError, PyPyError
+from pypy.interpreter.error import OperationError
import sys
def _run_eval_string(source, filename, space, eval):
@@ -9,7 +8,7 @@
cmd = 'eval'
else:
cmd = 'exec'
-
+
try:
if space is None:
from pypy.objspace.std import StdObjSpace
@@ -31,7 +30,7 @@
except OperationError, operationerr:
operationerr.record_interpreter_traceback()
- raise PyPyError(space, operationerr)
+ raise
def run_string(source, filename='<string>', space=None):
_run_eval_string(source, filename, space, False)
@@ -44,19 +43,3 @@
print "Running %r with %r" % (filename, space)
istring = open(filename).read()
run_string(istring, filename, space)
-
-def main(argv=None):
- if argv is None:
- argv = sys.argv
-
- argv = option.process_options(option.get_standard_options(),
- option.Options)
- space = option.objspace()
- try:
- run_file(argv[0], space)
- except PyPyError, pypyerr:
- pypyerr.operationerr.print_detailed_traceback(pypyerr.space)
-
-if __name__ == '__main__':
- main(sys.argv)
-
Modified: pypy/dist/pypy/interpreter/py.py
==============================================================================
--- pypy/dist/pypy/interpreter/py.py (original)
+++ pypy/dist/pypy/interpreter/py.py Thu Jan 27 13:30:04 2005
@@ -8,14 +8,20 @@
from pypy.tool import option
from pypy.tool.optik import make_option
from pypy.interpreter import main, interactive, error
-import sys
+import os, sys
class Options(option.Options):
+ verbose = os.getenv('PYPY_TB')
interactive = 0
command = []
def get_main_options():
options = option.get_standard_options()
+
+ options.append(make_option(
+ '-v', action='store_true', dest='verbose',
+ help='show verbose interpreter-level traceback'))
+
options.append(make_option(
'-i', action="store_true", dest="interactive",
help="inspect interactively after running script"))
@@ -48,22 +54,22 @@
args = ['-c'] + Options.command[1:]
for arg in args:
space.call_method(space.sys.w_argv, 'append', space.wrap(arg))
- if Options.command:
- try:
+ try:
+ if Options.command:
main.run_string(Options.command[0], '<string>', space)
- except error.PyPyError, pypyerr:
- pypyerr.operationerr.print_detailed_traceback(pypyerr.space)
- elif args:
- try:
+ elif args:
main.run_file(args[0], space)
- except error.PyPyError, pypyerr:
- pypyerr.operationerr.print_detailed_traceback(pypyerr.space)
- else:
- space.call_method(space.sys.w_argv, 'append', space.wrap(''))
- go_interactive = 1
- banner = None
+ else:
+ space.call_method(space.sys.w_argv, 'append', space.wrap(''))
+ go_interactive = 1
+ banner = None
+ except error.OperationError, operationerr:
+ if Options.verbose:
+ operationerr.print_detailed_traceback(space)
+ else:
+ operationerr.print_application_traceback(space)
if go_interactive:
- con = interactive.PyPyConsole(space)
+ con = interactive.PyPyConsole(space, Options.verbose)
if banner == '':
banner = '%s / %s'%(con.__class__.__name__,
space.__class__.__name__)
Modified: pypy/dist/pypy/tool/option.py
==============================================================================
--- pypy/dist/pypy/tool/option.py (original)
+++ pypy/dist/pypy/tool/option.py Thu Jan 27 13:30:04 2005
@@ -3,7 +3,6 @@
make_option = optik.make_option
class Options:
- verbose = 0
showwarning = 0
spaces = []
@@ -26,9 +25,6 @@
callback=objspace_callback, callback_args=("trivial",),
help="run in trivial object space"))
options.append(make_option(
- '-v', action="count", dest="verbose",
- help="verbose"))
- options.append(make_option(
'-w', action="store_true", dest="showwarning",
help="enable warnings (disabled by default)"))
options.append(make_option(
Modified: pypy/dist/pypy/tool/pytestsupport.py
==============================================================================
--- pypy/dist/pypy/tool/pytestsupport.py (original)
+++ pypy/dist/pypy/tool/pytestsupport.py Thu Jan 27 13:30:04 2005
@@ -44,7 +44,7 @@
self.traceback = AppTraceback(self.operr.application_traceback)
def __str__(self):
- return '[app-level] ' + self.operr.errorstr(self.space)
+ return '(application-level) ' + self.operr.errorstr(self.space)
class AppTracebackEntry(py.code.Traceback.Entry):
exprinfo = None
More information about the Pypy-commit
mailing list