Repository URL to install this package:
|
Version:
2.5 ▾
|
ó
ëEYc @ s6 d d l m Z d d l Z d e f d YZ d S( i ( t threadingiÿÿÿÿNt NameRegistryc B sA e Z d Z e j Z e j Z d Z d Z
d Z RS( sá Generates and return an object, keeping it as a
singleton for a certain identifier for as long as its
strongly referenced.
e.g.::
class MyFoo(object):
"some important object."
def __init__(self, identifier):
self.identifier = identifier
registry = NameRegistry(MyFoo)
# thread 1:
my_foo = registry.get("foo1")
# thread 2
my_foo = registry.get("foo1")
Above, ``my_foo`` in both thread #1 and #2 will
be *the same object*. The constructor for
``MyFoo`` will be called once, passing the
identifier ``foo1`` as the argument.
When thread 1 and thread 2 both complete or
otherwise delete references to ``my_foo``, the
object is *removed* from the :class:`.NameRegistry` as
a result of Python garbage collection.
:param creator: A function that will create a new
value, given the identifier passed to the :meth:`.NameRegistry.get`
method.
c C s+ t j | _ t j | _ | | _ d S( s/ Create a new :class:`.NameRegistry`.
N( t weakreft WeakValueDictionaryt _valuesR t RLockt _mutext creator( t selfR ( ( sN /home/tvault/.virtenv/lib/python2.7/site-packages/dogpile/util/nameregistry.pyt __init__+ s c O sY y1 | | j k r | j | S| j | | | SWn! t k
rT | j | | | SXd S( s] Get and possibly create the value.
:param identifier: Hash key for the value.
If the creation function is called, this identifier
will also be passed to the creation function.
:param \*args, \**kw: Additional arguments which will
also be passed to the creation function if it is
called.
N( R t _sync_gett KeyError( R t
identifiert argst kw( ( sN /home/tvault/.virtenv/lib/python2.7/site-packages/dogpile/util/nameregistry.pyt get4 s
c O s | j j z{ yB | | j k r- | j | S| j | | | | j | <} | SWn2 t k
r | j | | | | j | <} | SXWd | j j Xd S( N( R t acquireR R R t release( R R R
R t value( ( sN /home/tvault/.virtenv/lib/python2.7/site-packages/dogpile/util/nameregistry.pyR
G s
( t __name__t
__module__t __doc__R R t _locksR R R R R R
( ( ( sN /home/tvault/.virtenv/lib/python2.7/site-packages/dogpile/util/nameregistry.pyR s " ( t compatR R t objectR ( ( ( sN /home/tvault/.virtenv/lib/python2.7/site-packages/dogpile/util/nameregistry.pyt <module> s