Changeset 132

Show
Ignore:
Timestamp:
04/29/02 18:49:37 (6 years ago)
Author:
sholloway
Message:

Bugfixes
Interface changes

Files:

Legend:

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

    r104 r132  
    5454    def __init__(self, callback, *args, **kw): 
    5555        BoundCallable.__init__(self, callback) 
    56         self._SaveParameters(args, kw) 
     56        self.SaveParameters(args, kw) 
    5757 
    58     def _SaveParameters(self, args, kw): 
     58    def SaveParameters(self, args, kw): 
    5959        self.args = args 
    6060        self.kw = kw 
     
    6969 
    7070class ContextApply_p(_ContextApply): 
    71     def _SaveParameters(self, args, kw): pass 
     71    def SaveParameters(self, args, kw): pass 
    7272    def __call__(self, *args, **kw): 
    7373        return self._DoCall(args, kw) 
     
    7878 
    7979class ContextApply_0(_ContextApply): 
    80     def _SaveParameters(self, args, kw): pass 
     80    def SaveParameters(self, args, kw): pass 
    8181    def __call__(self, *args, **kw): 
    8282        return self._DoCall(tuple(), {}) 
     
    8686#~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 
    8787 
    88 class MultipleApply: 
    89     def __init__(self, MethodList=[], ReturnNth=None): 
    90         self.MethodList = MethodList 
    91         self.ReturnNth = ReturnNth  
     88class MultipleApply(list): 
     89    def __init__(self, ReturnIdx=-1): 
     90        self.idx = ReturnIdx  
    9291 
    9392    def __call__(self, *args, **kw): 
    94         if self.ReturnNth is None: 
    95             return [apply(method, args, kw) for method in self.MethodList
     93        if self.idx is None: 
     94            return [apply(method, args, kw) for method in self
    9695        else: 
    97             for method in self.MethodList[:self.ReturnNth]: 
     96            for method in self[:self.idx]: 
    9897                apply(method, args, kw) 
    9998 
    100             result = apply(self.MethodList[self.ReturnNth], args, kw) 
     99            result = apply(self[self.idx], args, kw) 
    101100 
    102101            # Normally you would think to just add one to ReturnNth, 
    103102            # But by splitting it twice, self.ReturnNth can be -1 as well 
    104             for method in self.MethodList[self.ReturnNth:][1:]: 
     103            for method in self[self.idx:][1:]: 
    105104                apply(method, args, kw) 
    106105 
  • trunk/RBFoundation/RBFoundation/SmartSelect.py

    r113 r132  
    139139#~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 
    140140 
     141class SmartSelectDictList(SmartSelectBase, dict): 
     142    """A dictionary collection of lists of Smart Sockets to aid in pseudo "non-blocking" socket programming.   
     143    Note, this is very simalr to asyncore.dispatcher.""" 
     144 
     145    def __call__(self, *args, **kw): 
     146        return apply(self.Process, args, kw) 
     147         
     148    def _getReadList(self): return [x for y in self.itervalues() for x in y if x._NeedsRead()] 
     149    ReadList = property(_getReadList) 
     150 
     151    def _getWriteList(self): return [x for y in self.itervalues() for x in y if x._NeedsWrite()] 
     152    WriteList = property(_getWriteList) 
     153 
     154    def _getErrorList(self): return [x for y in self.itervalues() for x in y if x._NeedsError()] 
     155    ErrorList = property(_getErrorList) 
     156 
     157#~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 
     158 
    141159SmartSelect = SmartSelectList 
  • trunk/RBJabber/RBJabber/SubjectObserver/StateMachine.py

    r123 r132  
    4242#~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 
    4343 
     44class OrStateList(list): 
     45    def __int__(self): 
     46        for each in self: 
     47            if int(each): return 1 
     48        return 0 
     49 
     50    def SetHandled(self): 
     51        for each in self: 
     52            if int(each): each.SetHandled() 
     53     
     54#~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 
     55 
     56class AndStateList(list): 
     57    def __int__(self): 
     58        for each in self: 
     59            if not int(each):  
     60                return 0 
     61        if self: return 1 
     62        else: return 0 
     63 
     64    def SetHandled(self): 
     65        for each in self: 
     66            if int(each): each.SetHandled() 
     67     
     68#~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 
     69 
    4470class State(Subject): 
     71    #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 
     72    #~ Constants / Variables / Etc.  
     73    #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 
     74 
    4575    value = 0 
    4676    _handled = 0 
    4777 
    48     def __init__(self, ReduceFn=and_, **kw): 
     78    #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 
     79    #~ Special  
     80    #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 
     81 
     82 
     83    def __init__(self, InfluxsClass=AndStateList, **kw): 
    4984        self.__dict__.update(kw) 
    5085        Subject.__init__(self) 
    51         self._Influxs = [] 
     86        self._Influxs = InfluxsClass() 
    5287        self.StateSubject = Subject() 
    53         self.ReduceFn = ReduceFn 
    5488 
    55     #def __or__(self, other): return int(self) or other 
    56     #def __ror__(self, other): return int(self) or other 
    57     #def __rand__(self, other): return int(self) and other 
    58     #def __and__(self, other): return int(self) and other 
    59     #def __nonzero__(self): return int(self) 
    60     def __int__(self): return self.value 
     89    def __int__(self):  
     90        return self.value 
     91 
     92    #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 
     93    #~ Public Methods  
     94    #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 
    6195 
    6296    def SetState(self, value =1): 
     
    73107        self._handled += handled  
    74108 
    75     def CheckInfluxs(self, subject, **kw): 
    76         if kw.get('state', 0) and not self.value: 
    77             precondition = reduce(self.ReduceFn, [int(x) for x in self._Influxs]
     109    def CheckInfluxs(self, subject, state): 
     110        if state and not self.value: 
     111            precondition = int(self._Influxs
    78112            if precondition: 
    79113                lock = self.StateSubject.Lock() 
    80114                self.UpdateObservers(precondition=precondition) 
    81                 for each in self._Influxs: 
    82                     each.SetHandled() 
     115                self._Influxs.SetHandled() 
    83116                lock.SetLock(None) 
    84117