/usr/share/pyshared/pypy/sandbox/rpython/tool/ansi_print.py is in python-pypy.sandbox 2.2.1+dfsg-1.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 | """
A color print.
"""
import sys
from py.io import ansi_print
from rpython.tool.ansi_mandelbrot import Driver
class AnsiLog:
wrote_dot = False # XXX sharing state with all instances
KW_TO_COLOR = {
# color supress
'red': ((31,), True),
'bold': ((1,), True),
'WARNING': ((31,), False),
'event': ((1,), True),
'ERROR': ((1, 31), False),
'Error': ((1, 31), False),
'info': ((35,), False),
'stub': ((34,), False),
}
def __init__(self, kw_to_color={}, file=None):
self.kw_to_color = self.KW_TO_COLOR.copy()
self.kw_to_color.update(kw_to_color)
self.file = file
self.fancy = True
self.isatty = lambda: True
if self.fancy and self.isatty():
self.mandelbrot_driver = Driver()
else:
self.mandelbrot_driver = None
def __call__(self, msg):
tty = self.isatty()
flush = False
newline = True
keywords = []
esc = []
for kw in msg.keywords:
color, supress = self.kw_to_color.get(kw, (None, False))
if color:
esc.extend(color)
if not supress:
keywords.append(kw)
if 'start' in keywords:
if tty:
newline = False
flush = True
keywords.remove('start')
elif 'done' in keywords:
if tty:
print >> sys.stderr
return
elif 'dot' in keywords:
if tty:
if self.fancy:
if not AnsiLog.wrote_dot:
self.mandelbrot_driver.reset()
self.mandelbrot_driver.dot()
else:
ansi_print(".", tuple(esc), file=self.file, newline=False, flush=flush)
AnsiLog.wrote_dot = True
return
if AnsiLog.wrote_dot:
AnsiLog.wrote_dot = False
sys.stderr.write("\n")
esc = tuple(esc)
for line in msg.content().splitlines():
ansi_print("[%s] %s" %(":".join(keywords), line), esc,
file=self.file, newline=newline, flush=flush)
ansi_log = AnsiLog()
|