Changeset 102
- Timestamp:
- 04/15/02 12:19:52 (6 years ago)
- Files:
-
- trunk/RBFoundation/RBFoundation/SmartSelect.py (modified) (4 diffs)
- trunk/RBJabber/RBJabber/Client.py (modified) (1 diff)
- trunk/RBJabber/RBJabber/JabberConnection.py (modified) (2 diffs)
- trunk/RBSkinning/support/scripts/.cvsignore (added)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
trunk/RBFoundation/RBFoundation/SmartSelect.py
r66 r102 43 43 44 44 class ClientBase(object): 45 """An abstract base class for creating "Smart Sockets" or other select.select able objects""" 46 #def fileno(self): return 0 ## override this, returning something that works with select.select, like socket.fileno 45 47 def _NeedsRead(self): return 0 46 48 #def _ProcessRead(self): pass ## If there is no definition, then these will raise if not "overridden" … … 52 54 #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 53 55 54 class SmartSelectBase: 55 def __call__(self, *args, **kw): 56 return apply(self.Process, args, kw) 57 56 class SmartSelectBase(object): 57 """Base class for waiting upon a set of select.select able objects""" 58 58 59 def Process(self, timeout=None): 60 """Uses select.select to wait on several file (proxy) handles in an object-oriented way.""" 59 61 lstSelected = select.select(self.ReadList, self.WriteList, self.ErrorList, timeout) 60 62 … … 65 67 return (lstSelected[0] or lstSelected[1] or lstSelected[2]) and 1 or 0 66 68 69 def ProcessPending(self, timeout=0.0): 70 """Calls Process until a timeout occurs.""" 71 while self.Process(timeout): 72 pass 73 return 0 74 75 #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 76 77 class SmartSelectClientBase(ClientBase, SmartSelectBase): 78 """Allows base classes of a smart select to be able to run "by themselves" as if they were their own SmartSelectors""" 79 def _getReadList(self): return self._NeedsRead() and [self] or [] 80 ReadList = property(_getReadList) 81 82 def _getWriteList(self): return self._NeedsWrite() and [self] or [] 83 WriteList = property(_getWriteList) 84 85 def _getErrorList(self): return self._NeedsError() and [self] or [] 86 ErrorList = property(_getErrorList) 87 67 88 #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 68 89 69 90 class SmartSelectList(SmartSelectBase, list): 91 """A list collection of Smart Sockets to aid in pseudo "non-blocking" socket programming. 92 Note, this is very simalr to asyncore.dispatcher.""" 93 94 def __call__(self, *args, **kw): 95 return apply(self.Process, args, kw) 96 70 97 def _getReadList(self): return [x for x in self if x._NeedsRead()] 71 98 ReadList = property(_getReadList) … … 81 108 82 109 class SmartSelectDict(SmartSelectBase, dict): 110 """A dictionary collection of Smart Sockets to aid in pseudo "non-blocking" socket programming. 111 Note, this is very simalr to asyncore.dispatcher.""" 112 113 def __call__(self, *args, **kw): 114 return apply(self.Process, args, kw) 115 83 116 def _getReadList(self): return [x for x in self.itervalues() if x._NeedsRead()] 84 117 ReadList = property(_getReadList) trunk/RBJabber/RBJabber/Client.py
r96 r102 155 155 return query 156 156 157 def SetData(self, namespace, xml): 158 self.SenddXML('''<iq id='%s' type='set'><query xmlns='%s'>%s</query></iq> ''' % (self._GetNextID(), namespace, xmlData)) 159 160 def GetData(self, namespace, callback=None, xml=''): 161 return self.Query(namespace, '', callback, xml) 162 163 def Query(self, namespace, toJID='', callback=None, xml=''): 164 import iqQuery 165 query = iqQuery.iqQuery(self, callback) 166 query.SendQuery(namespace, toJID) 167 return query 168 157 169 def Message(self, toJID, body, subject='', type='message', xml=''): 158 170 idMessage = self._GetNextID() trunk/RBJabber/RBJabber/JabberConnection.py
r96 r102 54 54 #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 55 55 56 class Client(XMLBuilderMixin, SmartSelect. ClientBase):56 class Client(XMLBuilderMixin, SmartSelect.SmartSelectClientBase): 57 57 #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 58 58 #~ Constants / Variables / Etc. … … 116 116 self._fileOut = fileOut 117 117 118 def Process(self, timeout=None):119 lstSelected = select.select(self._NeedsRead() and [self] or [], self._NeedsWrite() and [self] or [], self._NeedsError() and [self] or [], timeout)120 121 if lstSelected[0]: self._ProcessRead()122 if lstSelected[1]: self._ProcessWrite()123 if lstSelected[2]: self._ProcessError()124 125 return (lstSelected[0] or lstSelected[1] or lstSelected[2]) and 1 or 0126 127 118 #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 128 119 #~ Private Methods
