<s> from . import cmd as protocol_cmd <EOL> class Status ( type ) : <EOL> _registered_status = [ ] <EOL> def __new__ ( cls , name , bases , dct ) : <EOL> dct [ '<STR_LIT:code>' ] = len ( cls . _registered_status ) <EOL> c = super ( Status , cls ) . __new__ ( cls , name , bases , dct ) <EOL> cls . _registered_status . append ( c ) <EOL> return c <EOL> @ classmethod <EOL> def get ( cls , code ) : <EOL> return cls . _registered_status [ code ] <EOL> def new_status ( name , exception ) : <EOL> return Status ( name , ( object , ) , { '<STR_LIT>' : exception } ) <EOL> OK = new_status ( '<STR_LIT:OK>' , None ) <EOL> class DatabaseNotFound ( KeyError ) : <EOL> def __init__ ( self , name ) : <EOL> KeyError . __init__ ( self , '<STR_LIT>' . format ( repr ( name ) ) ) <EOL> DB_NOT_FOUND = new_status ( '<STR_LIT>' , DatabaseNotFound ) <EOL> class DatabaseError ( Exception ) : <EOL> def __init__ ( self , name ) : <EOL> Exception . __init__ ( self , '<STR_LIT>' . format ( repr ( name ) ) ) <EOL> DB_ERROR = new_status ( '<STR_LIT>' , DatabaseError ) <EOL> class NoDatabaseSelected ( ValueError ) : <EOL> def __init__ ( self , uid ) : <EOL> ValueError . __init__ ( self , '<STR_LIT>' . <EOL> format ( uid ) ) <EOL> NO_DB = new_status ( '<STR_LIT>' , NoDatabaseSelected ) <EOL> class CommandNotFound ( KeyError ) : <EOL> def __init__ ( self , cmd ) : <EOL> KeyError . __init__ ( self , '<STR_LIT>' . format ( repr ( cmd ) ) ) <EOL> CMD_NOT_FOUND = new_status ( '<STR_LIT>' , CommandNotFound ) <EOL> class InvalidArguments ( TypeError ) : <EOL> def __init__ ( self , cmd ) : <EOL> TypeError . __init__ ( self , '<STR_LIT>' . <EOL> format ( protocol_cmd . get_command ( cmd ) ) ) <EOL> INVALID_ARGS = new_status ( '<STR_LIT>' , InvalidArguments ) <EOL> class KeyNotFound ( KeyError ) : <EOL> def __init__ ( self , key ) : <EOL> KeyError . __init__ ( self , '<STR_LIT>' . format ( repr ( key ) ) ) <EOL> KEY_NOT_FOUND = new_status ( '<STR_LIT>' , KeyNotFound ) <EOL> class EscalatorClosed ( RuntimeError ) : <EOL> def __init__ ( self ) : <EOL> RuntimeError . __init__ ( self , '<STR_LIT>' ) <EOL> ESCALATOR_CLOSED = new_status ( '<STR_LIT>' , EscalatorClosed ) <EOL> class Error ( Exception ) : <EOL> def __init__ ( self ) : <EOL> Exception . __init__ ( self , '<STR_LIT>' ) <EOL> ERROR = new_status ( '<STR_LIT>' , Error ) </s>
