Ejemplo n.º 1
0
 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
Ejemplo n.º 2
0
 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)
Ejemplo n.º 3
0
 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
Ejemplo n.º 4
0
 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)