[pypy-svn] r8629 - in pypy/dist/pypy: interpreter objspace/std
arigo at codespeak.net
arigo at codespeak.net
Thu Jan 27 11:19:26 CET 2005
Author: arigo
Date: Thu Jan 27 11:19:26 2005
New Revision: 8629
Modified:
pypy/dist/pypy/interpreter/error.py
pypy/dist/pypy/objspace/std/fake.py
Log:
- hide the interp-level traceback unless the environment variable PYPY_TB is
defined.
- added a debug_print() function that prints "internal stuff" in red :-)
Modified: pypy/dist/pypy/interpreter/error.py
==============================================================================
--- pypy/dist/pypy/interpreter/error.py (original)
+++ pypy/dist/pypy/interpreter/error.py Thu Jan 27 11:19:26 2005
@@ -1,6 +1,7 @@
import os, sys
AUTO_DEBUG = os.getenv('PYPY_DEBUG')
+INTERP_LEVEL_TRACEBACK = os.getenv('PYPY_TB')
class PyPyError(Exception):
@@ -97,12 +98,18 @@
def print_detailed_traceback(self, space=None, file=None):
"""NOT_RPYTHON: Dump a nice detailed interpreter- and
application-level traceback, useful to debug the interpreter."""
+ import traceback, cStringIO
if file is None: file = sys.stderr
- for i in range(len(self.debug_excs)-1, -1, -1):
- import traceback
- interpr_file = LinePrefixer(file, '||')
- print >> interpr_file, "Traceback (interpreter-level):"
- traceback.print_tb(self.debug_excs[i][2], file=interpr_file)
+ 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)
+ 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])
@@ -143,24 +150,15 @@
return compile(source, '<inline>\n%s'%source, symbol, 0, 0)
-class LinePrefixer:
- """File-like class that inserts a prefix string
- at the beginning of each line it prints."""
- def __init__(self, file, prefix):
- self.file = file
- self.prefix = prefix
- self.linestart = True
- def write(self, data):
- if self.linestart:
- self.file.write(self.prefix)
- if data.endswith('\n'):
- data = data[:-1]
- self.linestart = True
- else:
- self.linestart = False
- self.file.write(data.replace('\n', '\n'+self.prefix))
- if self.linestart:
- self.file.write('\n')
+def debug_print(text, file=None):
+ if file is None: file = sys.stderr
+ text = text.rstrip()
+ if file.isatty():
+ text = ('\x1b[31m' + # ANSI color code "red"
+ text +
+ '\x1b[0m') # ANSI color code "reset"
+ file.write(text + '\n')
+
### installing the excepthook for OperationErrors
##def operr_excepthook(exctype, value, traceback):
Modified: pypy/dist/pypy/objspace/std/fake.py
==============================================================================
--- pypy/dist/pypy/objspace/std/fake.py (original)
+++ pypy/dist/pypy/objspace/std/fake.py Thu Jan 27 11:19:26 2005
@@ -1,4 +1,4 @@
-from pypy.interpreter.error import OperationError
+from pypy.interpreter.error import OperationError, debug_print
from pypy.interpreter import baseobjspace
from pypy.interpreter import eval
from pypy.interpreter.function import Function
@@ -39,7 +39,7 @@
def really_build_fake_type(cpy_type, ignored):
"NOT_RPYTHON (not remotely so!)."
- print 'faking %r'%(cpy_type,)
+ debug_print('faking %r'%(cpy_type,))
kw = {}
for s, v in cpy_type.__dict__.items():
if cpy_type is not unicode or s not in ['__add__', '__contains__']:
More information about the Pypy-commit
mailing list