Changeset 127
- Timestamp:
- 04/24/02 21:36:25 (6 years ago)
- Files:
-
- trunk/RBJabber/RBJabber/Client.py (modified) (2 diffs)
- trunk/RBJabber/RBJabber/JabberObserver.py (modified) (5 diffs)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
trunk/RBJabber/RBJabber/Client.py
r115 r127 165 165 return query 166 166 167 def Message(self, toJID, body , subject='', type='message', id=None, xml=''):167 def Message(self, toJID, body='', subject='', type='message', id=None, xml=''): 168 168 idMessage = id or self._GetNextID() 169 169 strXML = '<message id=%s to=%s type=%s>' % (quoteattr(idMessage), quoteattr(toJID), quoteattr(type)) … … 176 176 return self.SendXML(strXML) 177 177 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 178 184 def Presence(self, toJID='', status='', show='', type='available'): 179 185 idPresence = self._GetNextID() trunk/RBJabber/RBJabber/JabberObserver.py
r108 r127 42 42 #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 43 43 44 class MatchAnd(list): 44 class _MatchBase(object): 45 Negate = 0 45 46 def __call__(self, value): 47 if self.Negate: 48 return not self.MatchValue(value) 49 else: return self.MatchValue(value) 50 51 class MatchAnd(list, _MatchBase): 52 def MatchValue(self, value): 46 53 for each in self: 47 54 if not each(value): return 0 48 55 else: return len(self) and 1 or 0 56 MatchAll = MatchAnd 49 57 50 class MatchOr(list ):51 def __call__(self, value):58 class MatchOr(list, _MatchBase): 59 def MatchValue(self, value): 52 60 for each in self: 53 61 if each(value): return 1 54 62 else: return 0 63 MatchOne = MatchOr 64 65 class MatchNone(list, _MatchBase): 66 def MatchValue(self, value): 67 for each in self: 68 if each(value): return 0 69 else: return 1 55 70 56 class MatchAttributesRE( object):71 class MatchAttributesRE(_MatchBase): 57 72 def __init__(self, **attributes): 58 73 import re … … 61 76 self._MatchInfo[key] = re.compile(value).match 62 77 63 def __call__(self, value):78 def MatchValue(self, value): 64 79 for key, match in self._MatchInfo.iteritems(): 65 80 value = getattr(value, key, None) … … 70 85 else: return 1 71 86 72 class MatchAttributes( object):87 class MatchAttributes(_MatchBase): 73 88 def __init__(self, **attributes): 74 89 self._MatchInfo = attributes 75 90 76 def __call__(self, value):91 def MatchValue(self, value): 77 92 for key, compareto in self._MatchInfo.iteritems(): 78 93 if isinstance(compareto, JID.JID): … … 83 98 else: return 1 84 99 85 class MatchHasAttribute( object):100 class MatchHasAttribute(_MatchBase): 86 101 def __init__(self, name): 87 102 self._MatchInfo = name 88 103 89 def __call__(self, value):104 def MatchValue(self, value): 90 105 return hasattr(value, self._MatchInfo) 91 106 92 class MatchHasNode( object):107 class MatchHasNode(_MatchBase): 93 108 def __init__(self, namespace, node): 94 109 self._MatchInfo = (namespace, node) 95 110 96 def __call__(self, value):111 def MatchValue(self, value): 97 112 for each in value._elements: 98 113 if each[0] == self._MatchInfo: return 1 99 114 else: return 0 100 115 101 class MatchHasChildNode( object):116 class MatchHasChildNode(_MatchBase): 102 117 def __init__(self, node): 103 118 self._MatchInfo = node 104 119 105 def __call__(self, value):120 def MatchValue(self, value): 106 121 for each in value._elements: 107 122 if each[0][-1] == self._MatchInfo: return 1 108 123 else: return 0 109 124 110 class MatchHasChildNamespace( object):125 class MatchHasChildNamespace(_MatchBase): 111 126 def __init__(self, namespace): 112 127 self._MatchInfo = namespace 113 128 114 def __call__(self, value):129 def MatchValue(self, value): 115 130 for each in value._elements: 116 131 if each[0][0] == self._MatchInfo: return 1 … … 126 141 self.Match = Match or MatchAnd() 127 142 128 def AddRule(self, rule): 143 def AddRule(self, rule, Negate=0): 144 rule.Negate = Negate 129 145 self.Match.append(rule) 130 146
