<s> import sys <EOL> from Cython . Utils import open_new_file <EOL> class PyrexError ( Exception ) : <EOL> pass <EOL> class PyrexWarning ( Exception ) : <EOL> pass <EOL> def context ( position ) : <EOL> source = position [ <NUM_LIT:0> ] <EOL> assert not ( isinstance ( source , unicode ) or isinstance ( source , str ) ) , ( <EOL> "<STR_LIT>" % source ) <EOL> try : <EOL> F = list ( source . get_lines ( ) ) <EOL> except UnicodeDecodeError : <EOL> s = "<STR_LIT>" <EOL> else : <EOL> s = '<STR_LIT>' . join ( F [ max ( <NUM_LIT:0> , position [ <NUM_LIT:1> ] - <NUM_LIT:6> ) : position [ <NUM_LIT:1> ] ] ) <EOL> s = '<STR_LIT>' + s + '<STR_LIT:U+0020>' * ( position [ <NUM_LIT:2> ] - <NUM_LIT:1> ) + '<STR_LIT>' <EOL> s = '<STR_LIT:->' * <NUM_LIT> + '<STR_LIT:\n>' + s + '<STR_LIT:->' * <NUM_LIT> + '<STR_LIT:\n>' <EOL> return s <EOL> class CompileError ( PyrexError ) : <EOL> def __init__ ( self , position = None , message = "<STR_LIT>" ) : <EOL> self . position = position <EOL> self . message_only = message <EOL> self . reported = False <EOL> if position : <EOL> pos_str = "<STR_LIT>" % ( position [ <NUM_LIT:0> ] . get_description ( ) , position [ <NUM_LIT:1> ] , position [ <NUM_LIT:2> ] ) <EOL> cont = context ( position ) <EOL> else : <EOL> pos_str = "<STR_LIT>" <EOL> cont = '<STR_LIT>' <EOL> Exception . __init__ ( self , '<STR_LIT>' + cont + '<STR_LIT:\n>' + pos_str + message ) <EOL> class CompileWarning ( PyrexWarning ) : <EOL> def __init__ ( self , position = None , message = "<STR_LIT>" ) : <EOL> self . position = position <EOL> if position : <EOL> pos_str = "<STR_LIT>" % ( position [ <NUM_LIT:0> ] . get_description ( ) , position [ <NUM_LIT:1> ] , position [ <NUM_LIT:2> ] ) <EOL> else : <EOL> pos_str = "<STR_LIT>" <EOL> Exception . __init__ ( self , pos_str + message ) <EOL> class InternalError ( Exception ) : <EOL> def __init__ ( self , message ) : <EOL> Exception . __init__ ( self , "<STR_LIT>" <EOL> % message ) <EOL> listing_file = None <EOL> num_errors = <NUM_LIT:0> <EOL> echo_file = None <EOL> def open_listing_file ( path , echo_to_stderr = <NUM_LIT:1> ) : <EOL> global listing_file , num_errors , echo_file <EOL> if path is not None : <EOL> listing_file = open_new_file ( path ) <EOL> else : <EOL> listing_file = None <EOL> if echo_to_stderr : <EOL> echo_file = sys . stderr <EOL> else : <EOL> echo_file = None <EOL> num_errors = <NUM_LIT:0> <EOL> def close_listing_file ( ) : <EOL> global listing_file <EOL> if listing_file : <EOL> listing_file . close ( ) <EOL> listing_file = None <EOL> def report_error ( err ) : <EOL> if error_stack : <EOL> error_stack [ - <NUM_LIT:1> ] . append ( err ) <EOL> else : <EOL> global num_errors <EOL> if err . reported : return <EOL> err . reported = True <EOL> line = "<STR_LIT>" % err <EOL> if listing_file : <EOL> listing_file . write ( line ) <EOL> if echo_file : <EOL> echo_file . write ( line ) <EOL> num_errors = num_errors + <NUM_LIT:1> <EOL> def error ( position , message ) : <EOL> err = CompileError ( position , message ) <EOL> report_error ( err ) <EOL> return err <EOL> LEVEL = <NUM_LIT:1> <EOL> def warning ( position , message , level = <NUM_LIT:0> ) : <EOL> if level < LEVEL : <EOL> return <EOL> warn = CompileWarning ( position , message ) <EOL> line = "<STR_LIT>" % warn <EOL> if listing_file : <EOL> listing_file . write ( line ) <EOL> if echo_file : <EOL> echo_file . write ( line ) <EOL> return warn <EOL> error_stack = [ ] <EOL> def hold_errors ( ) : <EOL> error_stack . append ( [ ] ) <EOL> def release_errors ( ignore = False ) : <EOL> held_errors = error_stack . pop ( ) <EOL> if not ignore : <EOL> for err in held_errors : <EOL> report_error ( err ) <EOL> def held_errors ( ) : <EOL> return error_stack [ - <NUM_LIT:1> ] </s>
