Changeset 88

Show
Ignore:
Timestamp:
04/07/02 11:58:14 (6 years ago)
Author:
sholloway
Message:

Bugfixes
New Features
and Generally, stuff! =)

Files:

Legend:

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

    r74 r88  
    3636 
    3737import weakref 
    38 from WeakBind import BindCallable 
     38from WeakBind import BindCallable, BoundCallable 
    3939 
    4040#~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 
     
    5151#~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 
    5252 
    53 class _ContextApply(BindCallable): 
     53class _ContextApply(BoundCallable): 
    5454    def __init__(self, callback, *args, **kw): 
    55         BindCallable.__init__(self, callback) 
     55        BoundCallable.__init__(self, callback) 
    5656        self.args = args 
    5757        self.kw = kw 
  • trunk/RBFoundation/RBFoundation/WeakBind.py

    r83 r88  
    4242#~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 
    4343 
    44 class BindCallable(object): 
     44typesRequireBinding = (types.MethodType, types.UnboundMethodType, types.InstanceType) 
     45 
     46class BoundCallable(object): 
    4547    im_self = None 
    4648 
    4749    def __init__(self, callback): 
    48         assert(callable(callback)) 
    4950        if isinstance(callback, (types.MethodType, types.UnboundMethodType)): 
    5051            if callback.im_self is not None:  
     
    6566 
    6667    def __eq__(self, other): 
    67         if isinstance(other, BindCallable): 
     68        if isinstance(other, BoundCallable): 
    6869            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) 
    7171 
    7272    def _DoCall(self, args, kw): 
    73         #print 'self: %r, func: %r' % (self.im_self, self.im_func) 
    7473        if self.im_self: 
    7574            im_self = self.im_self() 
     
    8079            else: raise weakref.ReferenceError, "weakly-referenced object no longer exists" 
    8180        else: return apply(self.im_func, args, kw) 
     81 
     82 
     83def 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 
    8293 
    8394#~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 
  • trunk/RBFoundation/RBFoundation/XMLObjectify.py

    r87 r88  
    8282        return 
    8383         
    84     def __call__(self, joinstr=None): 
     84    def __call__(self, joinstr=''): 
    8585        result = [x[-1] for x in self._elements if not x[0][-1]] 
    8686        if joinstr is not None: 
  • trunk/RBJabber/RBJabber/JID.py

    r87 r88  
    6060    return [x.lower() for x in result[1-start:3-start]] + result[3-start:] 
    6161 
    62 def cmp(strJIDa, strJIDb, resource=1): 
    63     jida = JIDsplitnorm(strJIDa, end=3+resource) 
    64     jidb = JIDsplitnorm(strJIDb, end=3+resource) 
     62def cmp_(strJIDa, strJIDb, resource=1): 
     63    jida = splitnorm(strJIDa, end=3+resource) 
     64    jidb = splitnorm(strJIDb, end=3+resource) 
    6565    return cmp(jida, jidb) 
    6666 
    6767def compare(*args, **kw): 
    68     return 0 == apply(JIDcmp, args, kw) 
     68    return 0 == apply(cmp_, args, kw) 
    6969 
    7070def join(*args): 
     
    7878 
    7979def normalize(strJID): 
    80     return JIDjoin(JIDsplitnorm(strJID)) 
     80    return join(splitnorm(strJID)) 
    8181 
    8282def nominal(strJID): 
    83     return JIDjoin(JIDsplitnorm(strJID, 1, 3)) 
     83    return join(splitnorm(strJID, 1, 3)) 
    8484 
  • trunk/RBJabber/RBJabber/JabberConnection.py

    r87 r88  
    141141 
    142142    def Process(self, timeout=None): 
    143         lstSelected = select.select(self._NeedsRead() and [self] or [], self._NeedsRead() 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) 
    144144 
    145145        if lstSelected[0]: self._ProcessRead() 
  • trunk/RBJabber/RBJabber/SubjectObserver/AssociativeObserver.py

    r80 r88  
    3535#~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 
    3636 
    37 from Foundation.WeakBind import BindCallable as _BindCallable 
     37from Foundation.WeakBind import BindCallable 
    3838 
    3939#~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 
     
    4545        self._associations = {} 
    4646 
    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)) 
    5149        return self 
    5250 
    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  
    3535#~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 
    3636 
    37 from Foundation.WeakBind import BindCallable as _BindCallable 
     37from Foundation.WeakBind import BoundCallable, BindCallable 
    3838 
    3939#~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 
     
    4141#~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 
    4242 
    43 class Observer(_BindCallable): 
     43class Observer(BoundCallable): 
    4444    def __init__(self, callback=None, Bid=None): 
    4545        super(Observer, self).__init__(callback or self.Update) 
     
    4848    def SetBid(self, Bid=None): 
    4949        if callable(Bid):  
    50             self.Bid = _BindCallable(Bid) 
     50            self.Bid = BindCallable(Bid) 
    5151        elif Bid:  
    5252            self.Bid = Bid 
  • trunk/RBJabber/RBJabber/SubjectObserver/StateMachine.py

    r86 r88  
    5353        self.ReduceFn = ReduceFn 
    5454 
    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 
    6661 
    6762    def SetState(self, value =1): 
  • trunk/RBJabber/RBJabber/SubjectObserver/Subject.py

    r66 r88  
    5454    def AddObserver(self, observer, bUpdate=0): 
    5555        result = self._WrapObserver(observer) 
    56         self._observers.append(observer
     56        self._observers.append(result
    5757        if bUpdate: self.UpdateObserver(result, self._cachedUpdates) 
    5858        return self 
     
    7070    
    7171    def _WrapObserver(self, observer): 
    72         if not isinstance(observer, WeakBind.BindCallable): 
    73             observer = WeakBind.BindCallable(observer) 
    74         return observer 
     72        return WeakBind.BindCallable(observer) 
    7573  
    7674    def _ObserverList(self): 
  • trunk/RBJabber/RBJabber/SubscribeApproveResponse.py

    r86 r88  
    5454 
    5555    def Bid(self, subject, presence): 
    56         print "$%$", presence.type 
    5756        bMatch = presence.type in ['subscribe', 'unsubscribe'] 
    5857        return bMatch and self.BidValue or 0 
     
    6160        presence.to = presence.from_ 
    6261        del presence.from_ 
    63         presence.type += 'd' 
     62        presence.type += 'd' # set to subscribed/unsubscribed 
    6463        self.JC().SendXML(presence._toPrettyXML()) 
    6564 
  • trunk/RBJabber/RBJabber/Test.py

    r86 r88  
    4747#~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 
    4848 
    49 def _printMessage(subject, name, value): 
     49def _printMessage(subject, **UpdateDict): 
    5050    print 
    5151    print "Message from %r" % value.from_ 
    52     print value._toPrettyXML() 
     52    for value in UpdateDict.itervalues(): print value._toPrettyXML() 
    5353    print 
    5454 
     
    6060    print 
    6161 
    62 def _printIQ(subject, name, value): 
     62def _printIQ(subject, **UpdateDict): 
    6363    print 
    6464    print "IQ from %r" % getattr(value, 'from', '') 
    65     print value._toPrettyXML() 
     65    for value in UpdateDict.itervalues(): print value._toPrettyXML() 
    6666    print 
    6767 
    68 def _printPresence(subject, name, value): 
     68def _printPresence(subject, **UpdateDict): 
    6969    print 
    7070    print "Presence from %r" % value.from_ 
    71     print value._toPrettyXML() 
     71    for value in UpdateDict.itervalues(): print value._toPrettyXML() 
    7272    print 
    7373 
     
    8686    print 
    8787 
    88 def _printBrowse(subject, name, value): 
     88def _printBrowse(subject, **UpdateDict): 
    8989    print 
    9090    print "Browse" 
    91     print value._toPrettyXML() 
     91    for value in UpdateDict.itervalues(): print value._toPrettyXML() 
    9292    print 
    9393 
     
    9999    print 
    100100 
    101 def _printVersion(subject, name, value): 
     101def _printVersion(subject, **UpdateDict): 
    102102    print  
    103103    print "Version Received!" 
    104     print value._toPrettyXML() 
     104    for value in UpdateDict.itervalues(): print value._toPrettyXML() 
    105105    print 
    106106 
    107 def _printIt(subject, name, value): 
     107def _printIt(subject, **UpdateDict): 
    108108    print  
    109109    print "PRINT IT!!!" 
    110     print value._toPrettyXML() 
     110    for value in UpdateDict.itervalues(): print value._toPrettyXML() 
    111111    print 
    112112 
  • trunk/RBJabber/RBJabber/iqQuery.py

    r87 r88  
    4949    def __init__(self, JabberClient, BidValue=1): 
    5050        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) 
    5255        self._observer = Observer(self.Update, self.Bid) 
    5356 
    54     def Bid(self, subject, **UpdateDict): 
    55         iq = UpdateDict.get('iq', None) 
     57    def Bid(self, subject, iq): 
    5658        if iq: 
    5759            # if it is an iq with the same id