Changeset 132
- Timestamp:
- 04/29/02 18:49:37 (6 years ago)
- Files:
-
- trunk/RBFoundation/RBFoundation/ContextApply.py (modified) (4 diffs)
- trunk/RBFoundation/RBFoundation/SmartSelect.py (modified) (1 diff)
- trunk/RBJabber/RBJabber/SubjectObserver/StateMachine.py (modified) (2 diffs)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
trunk/RBFoundation/RBFoundation/ContextApply.py
r104 r132 54 54 def __init__(self, callback, *args, **kw): 55 55 BoundCallable.__init__(self, callback) 56 self. _SaveParameters(args, kw)56 self.SaveParameters(args, kw) 57 57 58 def _SaveParameters(self, args, kw):58 def SaveParameters(self, args, kw): 59 59 self.args = args 60 60 self.kw = kw … … 69 69 70 70 class ContextApply_p(_ContextApply): 71 def _SaveParameters(self, args, kw): pass71 def SaveParameters(self, args, kw): pass 72 72 def __call__(self, *args, **kw): 73 73 return self._DoCall(args, kw) … … 78 78 79 79 class ContextApply_0(_ContextApply): 80 def _SaveParameters(self, args, kw): pass80 def SaveParameters(self, args, kw): pass 81 81 def __call__(self, *args, **kw): 82 82 return self._DoCall(tuple(), {}) … … 86 86 #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 87 87 88 class MultipleApply: 89 def __init__(self, MethodList=[], ReturnNth=None): 90 self.MethodList = MethodList 91 self.ReturnNth = ReturnNth 88 class MultipleApply(list): 89 def __init__(self, ReturnIdx=-1): 90 self.idx = ReturnIdx 92 91 93 92 def __call__(self, *args, **kw): 94 if self. ReturnNthis 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] 96 95 else: 97 for method in self .MethodList[:self.ReturnNth]:96 for method in self[:self.idx]: 98 97 apply(method, args, kw) 99 98 100 result = apply(self .MethodList[self.ReturnNth], args, kw)99 result = apply(self[self.idx], args, kw) 101 100 102 101 # Normally you would think to just add one to ReturnNth, 103 102 # 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:]: 105 104 apply(method, args, kw) 106 105 trunk/RBFoundation/RBFoundation/SmartSelect.py
r113 r132 139 139 #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 140 140 141 class 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 141 159 SmartSelect = SmartSelectList trunk/RBJabber/RBJabber/SubjectObserver/StateMachine.py
r123 r132 42 42 #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 43 43 44 class 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 56 class 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 44 70 class State(Subject): 71 #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 72 #~ Constants / Variables / Etc. 73 #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 74 45 75 value = 0 46 76 _handled = 0 47 77 48 def __init__(self, ReduceFn=and_, **kw): 78 #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 79 #~ Special 80 #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 81 82 83 def __init__(self, InfluxsClass=AndStateList, **kw): 49 84 self.__dict__.update(kw) 50 85 Subject.__init__(self) 51 self._Influxs = []86 self._Influxs = InfluxsClass() 52 87 self.StateSubject = Subject() 53 self.ReduceFn = ReduceFn54 88 55 #def __or__(self, other): return int(self) or other56 #def __ror__(self, other): return int(self) or other57 #def __rand__(self, other): return int(self) and other 58 # def __and__(self, other): return int(self) and other59 # def __nonzero__(self): return int(self)60 def __int__(self): return self.value89 def __int__(self): 90 return self.value 91 92 #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 93 #~ Public Methods 94 #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 61 95 62 96 def SetState(self, value =1): … … 73 107 self._handled += handled 74 108 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) 78 112 if precondition: 79 113 lock = self.StateSubject.Lock() 80 114 self.UpdateObservers(precondition=precondition) 81 for each in self._Influxs: 82 each.SetHandled() 115 self._Influxs.SetHandled() 83 116 lock.SetLock(None) 84 117
