Changeset 88
- Timestamp:
- 04/07/02 11:58:14 (6 years ago)
- Files:
-
- trunk/RBFoundation/RBFoundation/ContextApply.py (modified) (2 diffs)
- trunk/RBFoundation/RBFoundation/WeakBind.py (modified) (3 diffs)
- trunk/RBFoundation/RBFoundation/XMLObjectify.py (modified) (1 diff)
- trunk/RBJabber/RBJabber/JID.py (modified) (2 diffs)
- trunk/RBJabber/RBJabber/JabberConnection.py (modified) (1 diff)
- trunk/RBJabber/RBJabber/SubjectObserver/AssociativeObserver.py (modified) (2 diffs)
- trunk/RBJabber/RBJabber/SubjectObserver/Observer.py (modified) (3 diffs)
- trunk/RBJabber/RBJabber/SubjectObserver/StateMachine.py (modified) (1 diff)
- trunk/RBJabber/RBJabber/SubjectObserver/Subject.py (modified) (2 diffs)
- trunk/RBJabber/RBJabber/SubscribeApproveResponse.py (modified) (2 diffs)
- trunk/RBJabber/RBJabber/Test.py (modified) (4 diffs)
- trunk/RBJabber/RBJabber/iqQuery.py (modified) (1 diff)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
trunk/RBFoundation/RBFoundation/ContextApply.py
r74 r88 36 36 37 37 import weakref 38 from WeakBind import BindCallable 38 from WeakBind import BindCallable, BoundCallable 39 39 40 40 #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ … … 51 51 #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 52 52 53 class _ContextApply(B indCallable):53 class _ContextApply(BoundCallable): 54 54 def __init__(self, callback, *args, **kw): 55 B indCallable.__init__(self, callback)55 BoundCallable.__init__(self, callback) 56 56 self.args = args 57 57 self.kw = kw trunk/RBFoundation/RBFoundation/WeakBind.py
r83 r88 42 42 #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 43 43 44 class BindCallable(object): 44 typesRequireBinding = (types.MethodType, types.UnboundMethodType, types.InstanceType) 45 46 class BoundCallable(object): 45 47 im_self = None 46 48 47 49 def __init__(self, callback): 48 assert(callable(callback))49 50 if isinstance(callback, (types.MethodType, types.UnboundMethodType)): 50 51 if callback.im_self is not None: … … 65 66 66 67 def __eq__(self, other): 67 if isinstance(other, B indCallable):68 if isinstance(other, BoundCallable): 68 69 return (self.im_self == other.im_self) and (self.im_func == other.im_func) 69 else: 70 return self == BindCallable(other) 70 else: return self == BoundCallable(other) 71 71 72 72 def _DoCall(self, args, kw): 73 #print 'self: %r, func: %r' % (self.im_self, self.im_func)74 73 if self.im_self: 75 74 im_self = self.im_self() … … 80 79 else: raise weakref.ReferenceError, "weakly-referenced object no longer exists" 81 80 else: return apply(self.im_func, args, kw) 81 82 83 def BindCallable(callback): 84 if isinstance(callback, BoundCallable): 85 # It's already bound in some form or another 86 return callback 87 elif isinstance(callback, typesRequireBinding): 88 # It's already bound in some form or another 89 return BoundCallable(callback) 90 else: 91 # not quite sure what it is, but it does not require binding 92 return callback 82 93 83 94 #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ trunk/RBFoundation/RBFoundation/XMLObjectify.py
r87 r88 82 82 return 83 83 84 def __call__(self, joinstr= None):84 def __call__(self, joinstr=''): 85 85 result = [x[-1] for x in self._elements if not x[0][-1]] 86 86 if joinstr is not None: trunk/RBJabber/RBJabber/JID.py
r87 r88 60 60 return [x.lower() for x in result[1-start:3-start]] + result[3-start:] 61 61 62 def cmp (strJIDa, strJIDb, resource=1):63 jida = JIDsplitnorm(strJIDa, end=3+resource)64 jidb = JIDsplitnorm(strJIDb, end=3+resource)62 def cmp_(strJIDa, strJIDb, resource=1): 63 jida = splitnorm(strJIDa, end=3+resource) 64 jidb = splitnorm(strJIDb, end=3+resource) 65 65 return cmp(jida, jidb) 66 66 67 67 def compare(*args, **kw): 68 return 0 == apply( JIDcmp, args, kw)68 return 0 == apply(cmp_, args, kw) 69 69 70 70 def join(*args): … … 78 78 79 79 def normalize(strJID): 80 return JIDjoin(JIDsplitnorm(strJID))80 return join(splitnorm(strJID)) 81 81 82 82 def nominal(strJID): 83 return JIDjoin(JIDsplitnorm(strJID, 1, 3))83 return join(splitnorm(strJID, 1, 3)) 84 84 trunk/RBJabber/RBJabber/JabberConnection.py
r87 r88 141 141 142 142 def Process(self, timeout=None): 143 lstSelected = select.select(self._NeedsRead() and [self] or [], self._Needs Read() and [self] or [], self._NeedsRead() and [self] or [], timeout)143 lstSelected = select.select(self._NeedsRead() and [self] or [], self._NeedsWrite() and [self] or [], self._NeedsError() and [self] or [], timeout) 144 144 145 145 if lstSelected[0]: self._ProcessRead() trunk/RBJabber/RBJabber/SubjectObserver/AssociativeObserver.py
r80 r88 35 35 #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 36 36 37 from Foundation.WeakBind import BindCallable as _BindCallable37 from Foundation.WeakBind import BindCallable 38 38 39 39 #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ … … 45 45 self._associations = {} 46 46 47 def AddAssociation(self, Association, Callback): 48 if not isinstance(Callback, _BindCallable): 49 self._associations.setdefault(Association, []).append(_BindCallable(Callback)) 50 else: self._associations.setdefault(Association, []).append(Callback) 47 def AddAssociation(self, association, observer): 48 self._associations.setdefault(association, []).append(BindCallable(observer)) 51 49 return self 52 50 53 def __call__(self, subject, **UpdateDict): 54 for each, value in UpdateDict.iteritems(): 55 for callback in self._associations.get(each, []): 56 if callback: callback(subject, each, valuse) 57 51 def Bid(self, subject, **UpdateDict): 52 for key, value in UpdateDict.iteritems(): 53 for observer in self._associations.get(key, []): 54 subject._GetBid(observer, UpdateDict) 55 56 def Update(self, subject, **UpdateDict): 57 pass trunk/RBJabber/RBJabber/SubjectObserver/Observer.py
r66 r88 35 35 #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 36 36 37 from Foundation.WeakBind import B indCallable as _BindCallable37 from Foundation.WeakBind import BoundCallable, BindCallable 38 38 39 39 #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ … … 41 41 #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 42 42 43 class Observer( _BindCallable):43 class Observer(BoundCallable): 44 44 def __init__(self, callback=None, Bid=None): 45 45 super(Observer, self).__init__(callback or self.Update) … … 48 48 def SetBid(self, Bid=None): 49 49 if callable(Bid): 50 self.Bid = _BindCallable(Bid)50 self.Bid = BindCallable(Bid) 51 51 elif Bid: 52 52 self.Bid = Bid trunk/RBJabber/RBJabber/SubjectObserver/StateMachine.py
r86 r88 53 53 self.ReduceFn = ReduceFn 54 54 55 def __or__(self, other): 56 return int(self) or other 57 58 def __and__(self, other): 59 return int(self) and other 60 61 def __nonzero__(self): 62 return int(self) 63 64 def __int__(self): 65 return self.value 55 def __or__(self, other): return int(self) or other 56 def __ror__(self, other): return int(self) or other 57 def __rand__(self, other): return int(self) and other 58 def __and__(self, other): return int(self) and other 59 def __nonzero__(self): return int(self) 60 def __int__(self): return self.value 66 61 67 62 def SetState(self, value =1): trunk/RBJabber/RBJabber/SubjectObserver/Subject.py
r66 r88 54 54 def AddObserver(self, observer, bUpdate=0): 55 55 result = self._WrapObserver(observer) 56 self._observers.append( observer)56 self._observers.append(result) 57 57 if bUpdate: self.UpdateObserver(result, self._cachedUpdates) 58 58 return self … … 70 70 71 71 def _WrapObserver(self, observer): 72 if not isinstance(observer, WeakBind.BindCallable): 73 observer = WeakBind.BindCallable(observer) 74 return observer 72 return WeakBind.BindCallable(observer) 75 73 76 74 def _ObserverList(self): trunk/RBJabber/RBJabber/SubscribeApproveResponse.py
r86 r88 54 54 55 55 def Bid(self, subject, presence): 56 print "$%$", presence.type57 56 bMatch = presence.type in ['subscribe', 'unsubscribe'] 58 57 return bMatch and self.BidValue or 0 … … 61 60 presence.to = presence.from_ 62 61 del presence.from_ 63 presence.type += 'd' 62 presence.type += 'd' # set to subscribed/unsubscribed 64 63 self.JC().SendXML(presence._toPrettyXML()) 65 64 trunk/RBJabber/RBJabber/Test.py
r86 r88 47 47 #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 48 48 49 def _printMessage(subject, name, value):49 def _printMessage(subject, **UpdateDict): 50 50 print 51 51 print "Message from %r" % value.from_ 52 print value._toPrettyXML()52 for value in UpdateDict.itervalues(): print value._toPrettyXML() 53 53 print 54 54 … … 60 60 print 61 61 62 def _printIQ(subject, name, value):62 def _printIQ(subject, **UpdateDict): 63 63 print 64 64 print "IQ from %r" % getattr(value, 'from', '') 65 print value._toPrettyXML()65 for value in UpdateDict.itervalues(): print value._toPrettyXML() 66 66 print 67 67 68 def _printPresence(subject, name, value):68 def _printPresence(subject, **UpdateDict): 69 69 print 70 70 print "Presence from %r" % value.from_ 71 print value._toPrettyXML()71 for value in UpdateDict.itervalues(): print value._toPrettyXML() 72 72 print 73 73 … … 86 86 print 87 87 88 def _printBrowse(subject, name, value):88 def _printBrowse(subject, **UpdateDict): 89 89 print 90 90 print "Browse" 91 print value._toPrettyXML()91 for value in UpdateDict.itervalues(): print value._toPrettyXML() 92 92 print 93 93 … … 99 99 print 100 100 101 def _printVersion(subject, name, value):101 def _printVersion(subject, **UpdateDict): 102 102 print 103 103 print "Version Received!" 104 print value._toPrettyXML()104 for value in UpdateDict.itervalues(): print value._toPrettyXML() 105 105 print 106 106 107 def _printIt(subject, name, value):107 def _printIt(subject, **UpdateDict): 108 108 print 109 109 print "PRINT IT!!!" 110 print value._toPrettyXML()110 for value in UpdateDict.itervalues(): print value._toPrettyXML() 111 111 print 112 112 trunk/RBJabber/RBJabber/iqQuery.py
r87 r88 49 49 def __init__(self, JabberClient, BidValue=1): 50 50 self.BidValue = BidValue 51 self.JC = weakref.ref(JabberClient) 51 if isinstance(JabberClient, weakref.ReferenceType): 52 self.JC = JabberClient 53 else: 54 self.JC = weakref.ref(JabberClient) 52 55 self._observer = Observer(self.Update, self.Bid) 53 56 54 def Bid(self, subject, **UpdateDict): 55 iq = UpdateDict.get('iq', None) 57 def Bid(self, subject, iq): 56 58 if iq: 57 59 # if it is an iq with the same id
