Changeset 127

Show
Ignore:
Timestamp:
04/24/02 21:36:25 (6 years ago)
Author:
sholloway
Message:

Bugfixes & such

Files:

Legend:

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

    r115 r127  
    165165        return query 
    166166 
    167     def Message(self, toJID, body, subject='', type='message', id=None, xml=''): 
     167    def Message(self, toJID, body='', subject='', type='message', id=None, xml=''): 
    168168        idMessage = id or self._GetNextID() 
    169169        strXML = '<message id=%s to=%s type=%s>' % (quoteattr(idMessage), quoteattr(toJID), quoteattr(type)) 
     
    176176        return self.SendXML(strXML) 
    177177 
     178    def Subscribe(self, toJID='', type='subscribe'): 
     179        return self.Presence(toJID=toJID, type=type) 
     180 
     181    def Unsubscribe(self, toJID='', type='unsubscribe'): 
     182        return self.Presence(toJID=toJID, type=type) 
     183 
    178184    def Presence(self, toJID='', status='', show='', type='available'): 
    179185        idPresence = self._GetNextID() 
  • trunk/RBJabber/RBJabber/JabberObserver.py

    r108 r127  
    4242#~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 
    4343 
    44 class MatchAnd(list): 
     44class _MatchBase(object): 
     45    Negate = 0 
    4546    def __call__(self, value): 
     47        if self.Negate: 
     48            return not self.MatchValue(value) 
     49        else: return self.MatchValue(value) 
     50 
     51class MatchAnd(list, _MatchBase): 
     52    def MatchValue(self, value): 
    4653        for each in self: 
    4754            if not each(value): return 0 
    4855        else: return len(self) and 1 or 0 
     56MatchAll = MatchAnd 
    4957     
    50 class MatchOr(list): 
    51     def __call__(self, value): 
     58class MatchOr(list, _MatchBase): 
     59    def MatchValue(self, value): 
    5260        for each in self: 
    5361            if each(value): return 1 
    5462        else: return 0 
     63MatchOne = MatchOr 
     64 
     65class MatchNone(list, _MatchBase): 
     66    def MatchValue(self, value): 
     67        for each in self: 
     68            if each(value): return 0 
     69        else: return 1 
    5570     
    56 class MatchAttributesRE(object): 
     71class MatchAttributesRE(_MatchBase): 
    5772    def __init__(self, **attributes): 
    5873        import re 
     
    6176            self._MatchInfo[key] = re.compile(value).match 
    6277 
    63     def __call__(self, value): 
     78    def MatchValue(self, value): 
    6479        for key, match in self._MatchInfo.iteritems(): 
    6580            value = getattr(value, key, None) 
     
    7085        else: return 1 
    7186 
    72 class MatchAttributes(object): 
     87class MatchAttributes(_MatchBase): 
    7388    def __init__(self, **attributes): 
    7489        self._MatchInfo = attributes 
    7590 
    76     def __call__(self, value): 
     91    def MatchValue(self, value): 
    7792        for key, compareto in self._MatchInfo.iteritems(): 
    7893            if isinstance(compareto, JID.JID): 
     
    8398        else: return 1 
    8499 
    85 class MatchHasAttribute(object): 
     100class MatchHasAttribute(_MatchBase): 
    86101    def __init__(self, name): 
    87102        self._MatchInfo = name 
    88103         
    89     def __call__(self, value): 
     104    def MatchValue(self, value): 
    90105        return hasattr(value, self._MatchInfo) 
    91106 
    92 class MatchHasNode(object): 
     107class MatchHasNode(_MatchBase): 
    93108    def __init__(self, namespace, node): 
    94109        self._MatchInfo = (namespace, node) 
    95110         
    96     def __call__(self, value): 
     111    def MatchValue(self, value): 
    97112        for each in value._elements: 
    98113            if each[0] == self._MatchInfo: return 1 
    99114        else: return 0 
    100115 
    101 class MatchHasChildNode(object): 
     116class MatchHasChildNode(_MatchBase): 
    102117    def __init__(self, node): 
    103118        self._MatchInfo = node 
    104119         
    105     def __call__(self, value): 
     120    def MatchValue(self, value): 
    106121        for each in value._elements: 
    107122            if each[0][-1] == self._MatchInfo: return 1 
    108123        else: return 0 
    109124 
    110 class MatchHasChildNamespace(object): 
     125class MatchHasChildNamespace(_MatchBase): 
    111126    def __init__(self, namespace): 
    112127        self._MatchInfo = namespace 
    113128         
    114     def __call__(self, value): 
     129    def MatchValue(self, value): 
    115130        for each in value._elements: 
    116131            if each[0][0] == self._MatchInfo: return 1 
     
    126141        self.Match = Match or MatchAnd() 
    127142 
    128     def AddRule(self, rule): 
     143    def AddRule(self, rule, Negate=0): 
     144        rule.Negate = Negate 
    129145        self.Match.append(rule) 
    130146