Changeset 89

Show
Ignore:
Timestamp:
04/08/02 09:27:14 (7 years ago)
Author:
sholloway
Message:

*** empty log message ***

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • trunk/RBJabber/RBJabber/JID.py

    r88 r89  
    8383    return join(splitnorm(strJID, 1, 3)) 
    8484 
     85#~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 
     86#~ Class JID  
     87#~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 
     88 
     89class JID(str): 
     90    """An object-oriented way of dealing with JIDs""" 
     91    split = split 
     92    splitnorm = splitnorm 
     93    normalize = normalize 
     94    nominal = nominal 
     95    compare = compare 
     96 
     97    def join(Class, *args): 
     98        return Class(apply(join, args)) 
     99    join = classmethod(join) 
     100 
     101    __cmp__ = cmp_ 
     102    def __eq__(self, other):  
     103        return cmp_(self, other) == 0 
     104    def __ne__(self, other):  
     105        return cmp_(self, other) != 0 
     106    def __lt__(self, other):  
     107        return cmp_(self, other) < 0 
     108    def __le__(self, other):  
     109        return cmp_(self, other) <= 0 
     110    def __gt__(self, other):  
     111        return cmp_(self, other) > 0 
     112    def __ge__(self, other):  
     113        return cmp_(self, other) >= 0 
     114 
     115    def __hash__(self): 
     116        return hash(self.normalize()) 
     117 
     118#~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 
     119#~ Testing  
     120#~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 
     121 
     122def _Test_JID(): 
     123    j1 = JID('user.name@jabber.org/Resource') 
     124    j2 = JID('User.Name@Jabber.org/Resource') 
     125    j3 = JID('User.Name@Jabber.org/ReSoUrCe') 
     126 
     127    assert(j1 == j2) 
     128    assert(j1 >= j2) 
     129    assert(j1 <= j2) 
     130    assert(j1 != j3) 
     131    assert(j2 != j3) 
     132    assert(j3 < j1) 
     133    assert(j1 > j3) 
     134    assert(j3 < j2) 
     135    assert(j2 > j3) 
     136    assert(j1.splitnorm() == j2.splitnorm() != j3.splitnorm()) 
     137    assert(j1.splitnorm(1,3) == j2.splitnorm(1,3) == j3.splitnorm(1,3)) 
     138    assert(hash(j1) == hash(j2)) 
     139    assert(hash(j1) != hash(j3)) 
     140    assert(hash(j2) != hash(j3)) 
     141 
     142#~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 
     143 
     144if __name__=='__main__': 
     145    print "Testing..." 
     146    _Test_JID()  
     147    print "Test complete." 
     148 
     149 
  • trunk/RBJabber/RBJabber/JabberConnection.py

    r88 r89  
    113113        self._fileOut = fileOut 
    114114 
     115    def Process(self, timeout=None): 
     116        lstSelected = select.select(self._NeedsRead() and [self] or [], self._NeedsWrite() and [self] or [], self._NeedsError() and [self] or [], timeout) 
     117 
     118        if lstSelected[0]: self._ProcessRead() 
     119        if lstSelected[1]: self._ProcessWrite() 
     120        if lstSelected[2]: self._ProcessError() 
     121 
     122        return (lstSelected[0] or lstSelected[1] or lstSelected[2]) and 1 or 0 
     123 
    115124    #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 
    116125    #~ Private Methods  
    117126    #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 
     127 
     128    def _start_element(self, name, attributes): 
     129        if name[:7] == 'jabber:': 
     130            for key in ('to', 'from', 'jid'): 
     131                if key in attributes:  
     132                    attributes[key] = JID.JID(attributes[key]) 
     133        return super(Client, self)._start_element(name, attributes) 
    118134 
    119135    def _GetElementFactory(self, owner, parent, namespace, node, attributes): 
     
    140156            self._sendData = self._sendData[nSent:] 
    141157 
    142     def Process(self, timeout=None): 
    143         lstSelected = select.select(self._NeedsRead() and [self] or [], self._NeedsWrite() and [self] or [], self._NeedsError() and [self] or [], timeout) 
    144  
    145         if lstSelected[0]: self._ProcessRead() 
    146         if lstSelected[1]: self._ProcessWrite() 
    147         if lstSelected[2]: self._ProcessError() 
    148  
    149         return (lstSelected[0] or lstSelected[1] or lstSelected[2]) and 1 or 0 
    150  
  • trunk/RBJabber/RBJabber/Test.py

    r88 r89  
    6868def _printPresence(subject, **UpdateDict): 
    6969    print 
    70     print "Presence from %r" % value.from_ 
    71     for value in UpdateDict.itervalues(): print value._toPrettyXML() 
     70    for value in UpdateDict.itervalues():  
     71        print "Presence from %r" % value.from_.normalize() 
     72        print value._toPrettyXML() 
    7273    print 
    7374 
     
    137138        apply(jc.Authenticate, tuple(), dictLogin) 
    138139         
    139         obs = SubjectObserver.AssociativeObserver.AssociativeObserver() 
    140         jc.stream.AddObserver('message', obs) 
    141         jc.stream.AddObserver('presence', obs) 
    142         obs.AddAssociation('message', _printMessage) 
    143         obs.AddAssociation('presence', _printPresence) 
     140        jc.stream.AddObserver('message', _printMessage) 
     141        jc.stream.AddObserver('presence', _printPresence) 
    144142 
    145143        pm = PresenceMap(jc)