Changeset 83

Show
Ignore:
Timestamp:
04/03/02 00:22:45 (7 years ago)
Author:
sholloway
Message:

*** empty log message ***

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • trunk/RBFoundation/RBFoundation/WeakBind.py

    r82 r83  
    5858  
    5959    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 
    6162 
    6263    def __call__(self, *args, **kw): 
  • trunk/RBJabber/RBJabber/SubjectObserver/StateMachine.py

    r78 r83  
    4848    def __init__(self, ReduceFn=and_, **kw): 
    4949        self.__dict__.update(kw) 
    50         super(State, self).__init__(
     50        Subject.__init__(self
    5151        self._Influxs = [] 
    5252        self._StateSubject = Subject() 
     
    6868                self.UpdateObservers(precondition=self.state) 
    6969            self._StateSubject.UpdateObservers(state=state) 
    70             if self._handled:  
     70            if self._handled > 0:  
    7171                self._handled = 0 
    7272                self.state = 0 
    7373 
    74     def SetHandled(self): 
    75         self._handled += 1 
     74    def SetHandled(self, handled=1): 
     75        self._handled += handled  
    7676 
    7777    def CheckInfluxs(self, subject, **kw): 
    78         if kw.get('state', 0)
     78        if kw.get('state', 0) and not self.state
    7979            precondition = reduce(self.ReduceFn, self._Influxs) 
    8080            if precondition: 
     81                lock = self._StateSubject.Lock() 
    8182                self.UpdateObservers(precondition=precondition) 
    8283                for each in self._Influxs: 
     
    9596 
    9697def _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() 
    100102 
    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) 
    105115 
    106116    b.AddInflux(a)