def _bind(self, feature, jid): ## Bindings are made with weak references to keep the ## book-keeping overhead in the core and plugins to a minimum. wr = weakref.KeyedRef(feature, self._remove, jid) if self._bound.setdefault(jid, wr)() is not feature: raise i.IQError('cancel', 'conflict') self._routes[jid.bare].add(jid) return jid
def add_property(self, cls, prop, attr_name): """Register property of C{cls} so that it may be found by C{get()}. """ suffix = cls.__module__.split(".") suffix.append(cls.__name__) suffix.reverse() suffix = ".%s." % ".".join(suffix) prop_ref = weakref.KeyedRef(prop, self._remove, None) pair = (attr_name + suffix, prop_ref) prop_ref.key = pair insort_left(self._properties, pair)
def push(cls, key, maxsize=None, timeout=None): maxsize = maxsize or cls.maxsize timeout = timeout or cls.timeout with cls.lock: limiter = cls._get_limiter(key) if limiter is None: limiter = cls._limiterFactory() cls._limiters[key] = weakref.KeyedRef(limiter, cls._clear, key) try: limiter.push(timeout=timeout, maxsize=maxsize) except LimiterFull: raise LimiterFull(-1, (cls, key)) return limiter
def add_class(self, cls): """Register properties of C{cls} so that they may be found by C{get()}. """ suffix = cls.__module__.split(".") suffix.append(cls.__name__) suffix.reverse() suffix = ".%s." % ".".join(suffix) cls_info = get_cls_info(cls) for attr in cls_info.attributes: prop = cls_info.attributes[attr] prop_ref = weakref.KeyedRef(prop, self._remove, None) pair = (attr + suffix, prop_ref) prop_ref.key = pair insort_left(self._properties, pair)