Changeset 102

Show
Ignore:
Timestamp:
04/15/02 12:19:52 (6 years ago)
Author:
sholloway
Message:

*** empty log message ***

Files:

Legend:

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

    r66 r102  
    4343 
    4444class 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 
    4547    def _NeedsRead(self): return 0 
    4648    #def _ProcessRead(self): pass  ## If there is no definition, then these will raise if not "overridden" 
     
    5254#~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 
    5355 
    54 class SmartSelectBase: 
    55     def __call__(self, *args, **kw): 
    56         return apply(self.Process, args, kw) 
    57          
     56class SmartSelectBase(object): 
     57    """Base class for waiting upon a set of select.select able objects""" 
     58 
    5859    def Process(self, timeout=None): 
     60        """Uses select.select to wait on several file (proxy) handles in an object-oriented way.""" 
    5961        lstSelected = select.select(self.ReadList, self.WriteList, self.ErrorList, timeout) 
    6062 
     
    6567        return (lstSelected[0] or lstSelected[1] or lstSelected[2]) and 1 or 0 
    6668 
     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 
     77class 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     
    6788#~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 
    6889 
    6990class 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         
    7097    def _getReadList(self): return [x for x in self if x._NeedsRead()] 
    7198    ReadList = property(_getReadList) 
     
    81108 
    82109class 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         
    83116    def _getReadList(self): return [x for x in self.itervalues() if x._NeedsRead()] 
    84117    ReadList = property(_getReadList) 
  • trunk/RBJabber/RBJabber/Client.py

    r96 r102  
    155155        return query 
    156156 
     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 
    157169    def Message(self, toJID, body, subject='', type='message', xml=''): 
    158170        idMessage = self._GetNextID() 
  • trunk/RBJabber/RBJabber/JabberConnection.py

    r96 r102  
    5454#~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 
    5555 
    56 class Client(XMLBuilderMixin, SmartSelect.ClientBase): 
     56class Client(XMLBuilderMixin, SmartSelect.SmartSelectClientBase): 
    5757    #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 
    5858    #~ Constants / Variables / Etc.  
     
    116116        self._fileOut = fileOut 
    117117 
    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 0 
    126  
    127118    #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 
    128119    #~ Private Methods