<s> """<STR_LIT>""" <EOL> import sys <EOL> from py . __ . io . terminalwriter import ansi_print <EOL> from pypy . tool . ansi_mandelbrot import Driver <EOL> class AnsiLog : <EOL> wrote_dot = False <EOL> KW_TO_COLOR = { <EOL> '<STR_LIT>' : ( ( <NUM_LIT> , ) , True ) , <EOL> '<STR_LIT>' : ( ( <NUM_LIT:1> , ) , True ) , <EOL> '<STR_LIT>' : ( ( <NUM_LIT> , ) , False ) , <EOL> '<STR_LIT>' : ( ( <NUM_LIT:1> , ) , True ) , <EOL> '<STR_LIT>' : ( ( <NUM_LIT:1> , <NUM_LIT> ) , False ) , <EOL> '<STR_LIT:info>' : ( ( <NUM_LIT> , ) , False ) , <EOL> '<STR_LIT>' : ( ( <NUM_LIT> , ) , False ) , <EOL> } <EOL> def __init__ ( self , kw_to_color = { } , file = None ) : <EOL> self . kw_to_color = self . KW_TO_COLOR . copy ( ) <EOL> self . kw_to_color . update ( kw_to_color ) <EOL> self . file = file <EOL> self . fancy = True <EOL> self . isatty = getattr ( sys . stderr , '<STR_LIT>' , lambda : False ) <EOL> if self . fancy and self . isatty ( ) : <EOL> self . mandelbrot_driver = Driver ( ) <EOL> else : <EOL> self . mandelbrot_driver = None <EOL> def __call__ ( self , msg ) : <EOL> tty = self . isatty ( ) <EOL> flush = False <EOL> newline = True <EOL> keywords = [ ] <EOL> esc = [ ] <EOL> for kw in msg . keywords : <EOL> color , supress = self . kw_to_color . get ( kw , ( None , False ) ) <EOL> if color : <EOL> esc . extend ( color ) <EOL> if not supress : <EOL> keywords . append ( kw ) <EOL> if '<STR_LIT:start>' in keywords : <EOL> if tty : <EOL> newline = False <EOL> flush = True <EOL> keywords . remove ( '<STR_LIT:start>' ) <EOL> elif '<STR_LIT>' in keywords : <EOL> if tty : <EOL> print >> sys . stderr <EOL> return <EOL> elif '<STR_LIT>' in keywords : <EOL> if tty : <EOL> if self . fancy : <EOL> if not AnsiLog . wrote_dot : <EOL> self . mandelbrot_driver . reset ( ) <EOL> self . mandelbrot_driver . dot ( ) <EOL> else : <EOL> ansi_print ( "<STR_LIT:.>" , tuple ( esc ) , file = self . file , newline = False , flush = flush ) <EOL> AnsiLog . wrote_dot = True <EOL> return <EOL> if AnsiLog . wrote_dot : <EOL> AnsiLog . wrote_dot = False <EOL> sys . stderr . write ( "<STR_LIT:\n>" ) <EOL> esc = tuple ( esc ) <EOL> for line in msg . content ( ) . splitlines ( ) : <EOL> ansi_print ( "<STR_LIT>" % ( "<STR_LIT::>" . join ( keywords ) , line ) , esc , <EOL> file = self . file , newline = newline , flush = flush ) <EOL> ansi_log = AnsiLog ( ) <EOL> def raise_nicer_exception ( * extraargs ) : <EOL> cls , e , tb = sys . exc_info ( ) <EOL> str_e = str ( e ) <EOL> class ExcSubclass ( cls ) : <EOL> def __str__ ( self ) : <EOL> lines = [ str_e ] <EOL> for extra in extraargs : <EOL> lines . append ( '<STR_LIT>' % ( extra , ) ) <EOL> return '<STR_LIT:\n>' . join ( lines ) <EOL> ExcSubclass . __name__ = cls . __name__ + "<STR_LIT:'>" <EOL> ExcSubclass . __module__ = cls . __module__ <EOL> try : <EOL> e . __class__ = ExcSubclass <EOL> except TypeError : <EOL> pass <EOL> raise ExcSubclass , e , tb </s>
