Changeset 83
- Timestamp:
- 04/03/02 00:22:45 (7 years ago)
- Files:
-
- trunk/RBFoundation/RBFoundation/WeakBind.py (modified) (1 diff)
- trunk/RBJabber/RBJabber/SubjectObserver/StateMachine.py (modified) (3 diffs)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
trunk/RBFoundation/RBFoundation/WeakBind.py
r82 r83 58 58 59 59 def __nonzero__(self): 60 return self.im_func and (not self.im_self or self.im_self()) and 1 or 0 60 result = self.im_func and (not self.im_self or self.im_self() is not None) and 1 or 0 61 return result 61 62 62 63 def __call__(self, *args, **kw): trunk/RBJabber/RBJabber/SubjectObserver/StateMachine.py
r78 r83 48 48 def __init__(self, ReduceFn=and_, **kw): 49 49 self.__dict__.update(kw) 50 super(State, self).__init__()50 Subject.__init__(self) 51 51 self._Influxs = [] 52 52 self._StateSubject = Subject() … … 68 68 self.UpdateObservers(precondition=self.state) 69 69 self._StateSubject.UpdateObservers(state=state) 70 if self._handled :70 if self._handled > 0: 71 71 self._handled = 0 72 72 self.state = 0 73 73 74 def SetHandled(self ):75 self._handled += 174 def SetHandled(self, handled=1): 75 self._handled += handled 76 76 77 77 def CheckInfluxs(self, subject, **kw): 78 if kw.get('state', 0) :78 if kw.get('state', 0) and not self.state: 79 79 precondition = reduce(self.ReduceFn, self._Influxs) 80 80 if precondition: 81 lock = self._StateSubject.Lock() 81 82 self.UpdateObservers(precondition=precondition) 82 83 for each in self._Influxs: … … 95 96 96 97 def _Test_StateMachine(): 97 def PrintDescription(StateSubject, precondition): 98 print StateSubject.__doc__ 99 StateSubject.SetState() 98 from Foundation.ContextApply import ContextApply_s_p,ContextApply_0 99 def PrintDescription(State, precondition): 100 print State.__doc__ 101 #State.SetState() 100 102 101 a = State(__doc__="A").AddObserver(PrintDescription) 102 b = State(__doc__="B").AddObserver(PrintDescription) 103 c = State(__doc__="C").AddObserver(PrintDescription) 104 d = State(__doc__="D").AddObserver(PrintDescription) 103 a = State(__doc__="A") 104 a.AddObserver(ContextApply_0(a.SetState)) 105 a.AddObserver(PrintDescription) 106 b = State(__doc__="B") 107 b.AddObserver(ContextApply_0(b.SetState)) 108 b.AddObserver(PrintDescription) 109 c = State(__doc__="C") 110 c.AddObserver(ContextApply_0(c.SetState)) 111 c.AddObserver(PrintDescription) 112 d = State(__doc__="D") 113 d.AddObserver(ContextApply_0(d.SetState)) 114 d.AddObserver(PrintDescription) 105 115 106 116 b.AddInflux(a)
