Ejemplo n.º 1
0
    def notify(self, attr=None, old=None, val=None, doNone=True):
        'Subclasses call notify to inform observers of changes to the object.'
        obs = self.observers
        notify = self.notify
        livecbs = self._live_callbacks

        if self._observable_frozen or attr == 'observers': return

        checkList = obs.keys() if attr is None else (
            [None, attr] if doNone else [attr])

        # Notify regular object observers (both attribute specific and not)
        for a in checkList:
            for cb, wref in livecbs(a):
                try:
                    cb(self, attr, old, val)
                except PyDeadObjectError, _deade:
                    try:
                        obs[a].remove(wref)
                    except ValueError:
                        log.info('weak reference already collected')
                except Exception, e:
                    print >> sys.stderr, "Error notifying %s" % funcinfo(cb)
                    traceback.print_exc()

                    try:
                        obs[a].remove(wref)  # remove the listener
                    except ValueError:
                        # the listener was already removed somehow.
                        log.info('weak reference already collected')
Ejemplo n.º 2
0
    def notify(self, attr = None, old = None, val = None, doNone = True):
        'Subclasses call notify to inform observers of changes to the object.'
        obs     = self.observers
        notify  = self.notify
        livecbs = self._live_callbacks

        if self._observable_frozen or attr == 'observers': return

        checkList = obs.keys() if attr is None else ( [None, attr] if doNone else [attr] )

        # Notify regular object observers (both attribute specific and not)
        for a in checkList:
            for cb, wref in livecbs(a):
                try:
                    cb(self, attr, old, val)
                except PyDeadObjectError, _deade:
                    try:
                        obs[a].remove(wref)
                    except ValueError:
                        log.info('weak reference already collected')
                except Exception, e:
                    print >> sys.stderr, "Error notifying %s" % funcinfo(cb)
                    traceback.print_exc()

                    try:
                        obs[a].remove(wref) # remove the listener
                    except ValueError:
                        # the listener was already removed somehow.
                        log.info('weak reference already collected')
Ejemplo n.º 3
0
    def __init__(self, method, cb = None):
        from util.introspect import funcinfo
        assert hasattr(method, 'im_self'), 'no im_self: %s' % funcinfo(method)

        self.object = weakref_ref(method.im_self, cb)
        self.func   = weakref_ref(method.im_func)
        self.cls    = weakref_ref(method.im_class)
Ejemplo n.º 4
0
        def my_super_callback_error(stanza):
            stanza.handler_frees = True
            if not isinstance(callback.error, list):
                try:
                    log.info("what is this?, callback was %r", funcinfo(callback.error))
                except Exception:
                    log.error('bad callback.error %r', callback.error)
                    return free_stanza(stanza)
            if len(callback.error) == 0:
                return free_stanza(stanza)

            try:
                f = callback.error[0].cb
                _call_free = CallLater(lambda:free_stanza(stanza))
                def my_hyper_callback_error(st):
                    try: f(st)
                    except Exception:
                        log.error('error processing %r', f)
                        print_exc()
                    finally: _call_free()
                callback.error[0].cb = my_hyper_callback_error
                callany(callback.error, stanza)
            except Exception:
                print_exc()
                log.error('failed to set up error stanza.free for %r, %r', callback, stanza)
Ejemplo n.º 5
0
 def __repr__(self):
     try:
         from util import funcinfo
         f_info = funcinfo(self.func())
     except Exception, e:
         f_info = '(unknown)'