<s> """<STR_LIT>""" <EOL> import types <EOL> from twisted . python import log , reflect <EOL> class NotKnown : <EOL> def __init__ ( self ) : <EOL> self . dependants = [ ] <EOL> self . resolved = <NUM_LIT:0> <EOL> def addDependant ( self , mutableObject , key ) : <EOL> assert not self . resolved <EOL> self . dependants . append ( ( mutableObject , key ) ) <EOL> resolvedObject = None <EOL> def resolveDependants ( self , newObject ) : <EOL> self . resolved = <NUM_LIT:1> <EOL> self . resolvedObject = newObject <EOL> for mut , key in self . dependants : <EOL> mut [ key ] = newObject <EOL> if isinstance ( newObject , NotKnown ) : <EOL> newObject . addDependant ( mut , key ) <EOL> def __hash__ ( self ) : <EOL> assert <NUM_LIT:0> , "<STR_LIT>" <EOL> class _Container ( NotKnown ) : <EOL> """<STR_LIT>""" <EOL> def __init__ ( self , l , containerType ) : <EOL> """<STR_LIT>""" <EOL> NotKnown . __init__ ( self ) <EOL> self . containerType = containerType <EOL> self . l = l <EOL> self . locs = range ( len ( l ) ) <EOL> for idx in xrange ( len ( l ) ) : <EOL> if not isinstance ( l [ idx ] , NotKnown ) : <EOL> self . locs . remove ( idx ) <EOL> else : <EOL> l [ idx ] . addDependant ( self , idx ) <EOL> if not self . locs : <EOL> self . resolveDependants ( self . containerType ( self . l ) ) <EOL> def __setitem__ ( self , n , obj ) : <EOL> """<STR_LIT>""" <EOL> self . l [ n ] = obj <EOL> if not isinstance ( obj , NotKnown ) : <EOL> self . locs . remove ( n ) <EOL> if not self . locs : <EOL> self . resolveDependants ( self . containerType ( self . l ) ) <EOL> class _Tuple ( _Container ) : <EOL> """<STR_LIT>""" <EOL> def __init__ ( self , l ) : <EOL> """<STR_LIT>""" <EOL> _Container . __init__ ( self , l , tuple ) <EOL> class _InstanceMethod ( NotKnown ) : <EOL> def __init__ ( self , im_name , im_self , im_class ) : <EOL> NotKnown . __init__ ( self ) <EOL> self . my_class = im_class <EOL> self . name = im_name <EOL> im_self . addDependant ( self , <NUM_LIT:0> ) <EOL> def __call__ ( self , * args , ** kw ) : <EOL> import traceback <EOL> log . msg ( '<STR_LIT>' % ( reflect . qual ( self . my_class ) , self . name ) ) <EOL> log . msg ( '<STR_LIT>' % ( args , kw ) ) <EOL> traceback . print_stack ( file = log . logfile ) <EOL> assert <NUM_LIT:0> <EOL> def __setitem__ ( self , n , obj ) : <EOL> assert n == <NUM_LIT:0> , "<STR_LIT>" <EOL> if not isinstance ( obj , NotKnown ) : <EOL> method = types . MethodType ( self . my_class . __dict__ [ self . name ] , <EOL> obj , self . my_class ) <EOL> self . resolveDependants ( method ) <EOL> class _DictKeyAndValue : <EOL> def __init__ ( self , dict ) : <EOL> self . dict = dict <EOL> def __setitem__ ( self , n , obj ) : <EOL> if n not in ( <NUM_LIT:1> , <NUM_LIT:0> ) : <EOL> raise RuntimeError ( "<STR_LIT>" ) <EOL> if n : <EOL> self . value = obj <EOL> else : <EOL> self . key = obj <EOL> if hasattr ( self , "<STR_LIT:key>" ) and hasattr ( self , "<STR_LIT:value>" ) : <EOL> self . dict [ self . key ] = self . value <EOL> class _Dereference ( NotKnown ) : <EOL> def __init__ ( self , id ) : <EOL> NotKnown . __init__ ( self ) <EOL> self . id = id <EOL> from twisted . internet . defer import Deferred <EOL> class _Catcher : <EOL> def catch ( self , value ) : <EOL> self . value = value <EOL> class _Defer ( Deferred , NotKnown ) : <EOL> def __init__ ( self ) : <EOL> Deferred . __init__ ( self ) <EOL> NotKnown . __init__ ( self ) <EOL> self . pause ( ) <EOL> wasset = <NUM_LIT:0> <EOL> def __setitem__ ( self , n , obj ) : <EOL> if self . wasset : <EOL> raise RuntimeError ( '<STR_LIT>' % ( n , obj ) ) <EOL> else : <EOL> self . wasset = <NUM_LIT:1> <EOL> self . callback ( obj ) <EOL> def addDependant ( self , dep , key ) : <EOL> NotKnown . addDependant ( self , dep , key ) <EOL> self . unpause ( ) <EOL> resovd = self . result <EOL> self . resolveDependants ( resovd ) </s>
