<s> '''<STR_LIT>''' <EOL> import weakref <EOL> import new <EOL> class WeakMethodReference ( object ) : <EOL> """<STR_LIT>""" <EOL> def __init__ ( self , function = None ) : <EOL> """<STR_LIT>""" <EOL> super ( WeakMethodReference , self ) . __init__ ( ) <EOL> try : <EOL> if function . im_self is not None : <EOL> self . _obj = weakref . ref ( function . im_self ) <EOL> else : <EOL> self . _obj = None <EOL> self . _func = function . im_func <EOL> self . _class = function . im_class <EOL> except AttributeError : <EOL> self . _obj = None <EOL> self . _func = function <EOL> self . _class = None <EOL> def __call__ ( self ) : <EOL> """<STR_LIT>""" <EOL> if self . is_dead ( ) : <EOL> return None <EOL> if self . _obj is not None : <EOL> return new . instancemethod ( <EOL> self . _func , <EOL> self . _obj ( ) , <EOL> self . _class <EOL> ) <EOL> else : <EOL> return self . _func <EOL> def is_dead ( self ) : <EOL> """<STR_LIT>""" <EOL> if self . _obj is None and self . _func is not None : <EOL> return False <EOL> if self . _obj is not None and self . _obj ( ) is None : <EOL> return True <EOL> return False <EOL> def is_alive ( self ) : <EOL> """<STR_LIT>""" <EOL> return not self . is_dead ( ) <EOL> def __eq__ ( self , other ) : <EOL> """<STR_LIT>""" <EOL> return ( <EOL> isinstance ( other , self . __class__ ) and self . __dict__ == other . __dict__ <EOL> ) <EOL> def __ne__ ( self , other ) : <EOL> """<STR_LIT>""" <EOL> return not self . __eq__ ( other ) <EOL> def __hash__ ( self ) : <EOL> """<STR_LIT>""" <EOL> return hash ( ( self . _obj , self . _func , self . _class ) ) </s>
