<s> """<STR_LIT>""" <EOL> __all__ = ( '<STR_LIT>' , '<STR_LIT>' ) <EOL> class Registry ( object ) : <EOL> """<STR_LIT>""" <EOL> def __init__ ( self ) : <EOL> self . _actions = { } <EOL> self . _cache = { } <EOL> def __iter__ ( self ) : <EOL> """<STR_LIT>""" <EOL> for key in self . _actions . keys ( ) : <EOL> yield key , self . get ( key ) <EOL> def clear ( self ) : <EOL> """<STR_LIT>""" <EOL> self . _actions = { } <EOL> self . _cache = { } <EOL> def get ( self , key ) : <EOL> """<STR_LIT>""" <EOL> if not key in self . _actions : <EOL> return None <EOL> if not key in self . _cache : <EOL> self . _cache [ key ] = self . _actions [ key ] ( ) <EOL> return self . _cache [ key ] <EOL> def register ( self , key , value ) : <EOL> """<STR_LIT>""" <EOL> self . _actions [ key ] = value <EOL> if key in self . _cache : <EOL> del self . _cache [ key ] <EOL> def deregister ( self , key ) : <EOL> """<STR_LIT>""" <EOL> if not key in self . _actions : <EOL> return False <EOL> del self . _actions [ key ] <EOL> if key in self . _cache : <EOL> del self . _cache [ key ] <EOL> return True <EOL> class ExtRegistry ( Registry ) : <EOL> """<STR_LIT>""" <EOL> def __init__ ( self , * args , ** kwargs ) : <EOL> super ( ExtRegistry , self ) . __init__ ( * args , ** kwargs ) <EOL> self . _type_info = { } <EOL> def clear ( self ) : <EOL> """<STR_LIT>""" <EOL> super ( ExtRegistry , self ) . clear ( ) <EOL> self . _type_info = { } <EOL> def get ( self , key ) : <EOL> """<STR_LIT>""" <EOL> obj = super ( ExtRegistry , self ) . get ( key ) <EOL> if obj is None : <EOL> return obj <EOL> return ( obj , self . _type_info . get ( key ) ) <EOL> def register ( self , key , value , type_info ) : <EOL> """<STR_LIT>""" <EOL> old_action = self . _actions . get ( key ) <EOL> if old_action == value and key in self . _type_info : <EOL> self . _type_info [ key ] . update ( type_info ) <EOL> else : <EOL> self . _type_info [ key ] = dict ( type_info ) <EOL> super ( ExtRegistry , self ) . register ( key , value ) <EOL> def deregister ( self , key ) : <EOL> """<STR_LIT>""" <EOL> res = super ( ExtRegistry , self ) . deregister ( key ) <EOL> if key in self . _type_info : <EOL> del self . _type_info [ key ] <EOL> return res </s>
