<s> from peak . util . proxies import ObjectWrapper <EOL> class CallableProxy ( ObjectWrapper ) : <EOL> __slots__ = ( '<STR_LIT>' ) <EOL> def __init__ ( self , wrapped , wrapper ) : <EOL> super ( CallableProxy , self ) . __init__ ( wrapped ) <EOL> self . _eop_wrapper_ = wrapper <EOL> def __call__ ( self , * args , ** kwargs ) : <EOL> return self . _eop_wrapper_ ( self . __subject__ , * args , ** kwargs ) <EOL> class BoundMethodProxy ( ObjectWrapper ) : <EOL> __slots__ = ( '<STR_LIT>' , '<STR_LIT>' ) <EOL> def __init__ ( self , wrapped , instance , wrapper ) : <EOL> super ( BoundMethodProxy , self ) . __init__ ( wrapped ) <EOL> self . _eop_instance_ = instance <EOL> self . _eop_wrapper_ = wrapper <EOL> def __call__ ( self , * args , ** kwargs ) : <EOL> return self . _eop_wrapper_ ( self . __subject__ , self . _eop_instance_ , * args , ** kwargs ) <EOL> class UnboundMethodProxy ( CallableProxy ) : <EOL> __slots__ = ( '<STR_LIT>' ) <EOL> def __get__ ( self , instance , owner ) : <EOL> return BoundMethodProxy ( self . __subject__ . __get__ ( instance , owner ) , instance or owner , self . _eop_wrapper_ ) <EOL> def __getattribute__ ( self , attr , oga = object . __getattribute__ ) : <EOL> """<STR_LIT>""" <EOL> if attr == '<STR_LIT>' : <EOL> return oga ( self , attr ) <EOL> return super ( UnboundMethodProxy , self ) . __getattribute__ ( attr ) <EOL> def monkeypatch_method ( cls , method_name = None ) : <EOL> def decorator ( func ) : <EOL> method_to_patch = method_name or func . __name__ <EOL> original = cls . __dict__ [ method_to_patch ] <EOL> replacement = UnboundMethodProxy ( original , func ) <EOL> type . __setattr__ ( cls , method_to_patch , replacement ) <EOL> return func <EOL> return decorator </s>
