<s> from Log import Log <EOL> import traceback <EOL> class NoPerm ( Exception ) : <EOL> pass <EOL> class WrongArgs ( Exception ) : <EOL> pass <EOL> class NotFound ( Exception ) : <EOL> pass <EOL> class ServerError ( Exception ) : <EOL> pass <EOL> class OutOfRange ( Exception ) : <EOL> pass <EOL> class Unauthorized ( Exception ) : <EOL> pass <EOL> class error_handler : <EOL> def __init__ ( self , svc ) : <EOL> self . svc = svc <EOL> def __enter__ ( self ) : <EOL> pass <EOL> def __exit__ ( self , type , value , tb ) : <EOL> if ( value == None ) : <EOL> return True <EOL> if ( isinstance ( value , NoPerm ) ) : <EOL> self . svc . return_error ( <NUM_LIT> , value . args [ <NUM_LIT:0> ] ) <EOL> elif ( isinstance ( value , WrongArgs ) ) : <EOL> self . svc . return_error ( <NUM_LIT> , value . args [ <NUM_LIT:0> ] ) <EOL> elif ( isinstance ( value , Unauthorized ) ) : <EOL> self . svc . return_error ( <NUM_LIT> , value . args [ <NUM_LIT:0> ] ) <EOL> elif ( isinstance ( value , NotFound ) ) : <EOL> self . svc . return_error ( <NUM_LIT> , value . args [ <NUM_LIT:0> ] ) <EOL> elif ( isinstance ( value , OutOfRange ) ) : <EOL> self . svc . return_error ( <NUM_LIT> , value . args [ <NUM_LIT:0> ] ) <EOL> elif ( isinstance ( value , ServerError ) ) : <EOL> self . svc . return_error ( <NUM_LIT> , value . args [ <NUM_LIT:0> ] ) <EOL> else : <EOL> info = "<STR_LIT>" . join ( traceback . format_exception ( type , value , tb ) ) <EOL> Log . error ( "<STR_LIT>" % info ) <EOL> self . svc . return_error ( <NUM_LIT> , "<STR_LIT>" , info ) ; <EOL> return False <EOL> return True </s>
