Файловый менеджер - Редактировать - /opt/imh-python/lib/python3.9/site-packages/dogpile/util/__pycache__/nameregistry.cpython-39.pyc
Ðазад
a t�h� � @ sH d dl Z d dlmZ d dlmZ d dlmZ d dlZG dd� de�ZdS )� N)�Any)�Callable)�MutableMappingc @ sV e Zd ZdZe�� Zedef d�dd�Z e eeed�dd�Ze eeed�d d �ZdS )�NameRegistrya� 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. .)�creatorc C s t �� | _t�� | _|| _dS )z$Create a new :class:`.NameRegistry`.N)�weakref�WeakValueDictionary�_values� threading�RLock�_mutexr )�selfr � r ��/root/rpmbuild/BUILDROOT/imh-python39-modules-3.9.7-92.el8.x86_64/opt/imh-python/lib/python3.9/site-packages/dogpile/util/nameregistry.py�__init__. s zNameRegistry.__init__)� identifier�args�kw�returnc O sd z4|| j v r| j | W S | j|g|�R i |��W S W n* ty^ | j|g|�R i |�� Y S 0 dS )a] 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 � _sync_get�KeyError)r r r r r r r �get4 s zNameRegistry.getc O s� | j �� z�zZ|| jv r0| j| W W | j �� S | j|g|�R i |�� | j|<