HEX
Server: Apache
System: Linux infong-uk86 4.4.400-icpu-106 #2 SMP Mon Sep 15 08:23:40 UTC 2025 x86_64
User: u44115835 (4976590)
PHP: 8.4.17
Disabled: NONE
Upload Files
File: //kunden/lib/python3/dist-packages/breezy/__pycache__/registry.cpython-39.pyc
a

�*�^20�@sldZddlmZddlmZddlmZGdd�de�ZGdd	�d	e�Z	Gd
d�de�Z
Gdd
�d
e
�ZdS)z8Classes to provide name-to-object registry-like support.�)�absolute_import�)�get_named_object)�	viewitemsc@s.eZdZdZdgZdd�Zdd�Zdd�Zd	S)
�
_ObjectGetteraMaintain a reference to an object, and return the object on request.

    This is used by Registry to make plain objects function similarly
    to lazily imported objects.

    Objects can be any sort of python object (class, function, module,
    instance, etc)
    �_objcCs
||_dS�N�r)�self�obj�r�1/usr/lib/python3/dist-packages/breezy/registry.py�__init__&sz_ObjectGetter.__init__cCs|jjS)z*Get the module the object was loaded from.)r�
__module__�r
rrr
�
get_module)sz_ObjectGetter.get_modulecCs|jS)z.Get the object that was saved at creation timer	rrrr
�get_obj-sz_ObjectGetter.get_objN)�__name__r�__qualname__�__doc__�	__slots__rrrrrrr
rs
	rcsDeZdZdZgd�Z�fdd�Zdd�Z�fdd�Zd	d
�Z�Z	S)�_LazyObjectGetterzQKeep a record of a possible object.

    When requested, load and return it.
    )�_module_name�_member_name�	_importedcs&||_||_d|_tt|��d�dS)NF)rrr�superrr)r
�module_name�member_name��	__class__rr
r:sz_LazyObjectGetter.__init__cCs|jS)zBGet the module the referenced object will be loaded from.
        )rrrrr
r@sz_LazyObjectGetter.get_modulecs*|jst|j|j�|_d|_tt|���S)z�Get the referenced object.

        Upon first request, the object will be imported. Future requests will
        return the imported object.
        T)rrrrrrrrrrrr
rEsz_LazyObjectGetter.get_objcCs&d|jj|jjt|�|j|j|jfS)Nz8<%s.%s object at %x, module=%r attribute=%r imported=%r>)rrr�idrrrrrrr
�__repr__Ps�z_LazyObjectGetter.__repr__)
rrrrrrrrr!�
__classcell__rrrr
r2src@s�eZdZdZdd�Zdd�Zdd�Zd.d
d�Zd/dd
�Zd0dd�Z	d1dd�Z
d2dd�Zdd�Zdd�Z
d3dd�Zd4dd�Zd5dd�Zdd�Zd d!�Zd"d#�Zd$d%�Zd&d'�Zd(d)�Zd*d+�Zeeed,d-�ZdS)6�Registrya	A class that registers objects to a name.

    There are many places that want to collect related objects and access them
    by a key. This class is designed to allow registering the mapping from key
    to object. It goes one step further, and allows registering a name to a
    hypothetical object which has not been imported yet. It also supports
    adding additional information at registration time so that decisions can be
    made without having to import the object (which may be expensive).

    The functions 'get', 'get_info', and 'get_help' also support a
    'default_key' (settable through my_registry.default_key = XXX, XXX must
    already be registered.) Calling my_registry.get() or my_registry.get(None),
    will return the entry for the default key.
    cCs"d|_i|_i|_i|_i|_dS)zCreate a new Registry.N)�_default_key�_dict�_aliases�
_help_dict�
_info_dictrrrr
rfs
zRegistry.__init__cCstt|j��S)z3Return a set of the format names which are aliases.)�dictrr&rrrr
�aliasesoszRegistry.aliasescCs.i}t|j�D]\}}|�|g��|�q|Sr)rr&�
setdefault�append)r
Zret�alias�targetrrr
�	alias_mapsszRegistry.alias_mapNFcCs<|s||jvrtd|��t|�|j|<|j|||d�dS)acRegister a new object to a name.

        :param key: This is the key to use to request the object later.
        :param obj: The object to register.
        :param help: Help text for this entry. This may be a string or
                a callable. If it is a callable, it should take two
                parameters (registry, key): this registry and the key that
                the help was registered under.
        :param info: More information for this entry. Registry.get_info()
                can be used to get this information. Registry treats this as an
                opaque storage location (it is defined by the caller).
        :param override_existing: Raise KeyErorr if False and something has
                already been registered for that key. If True, ignore if there
                is an existing key (always register the new value).
        �Key %r already registered��help�infoN)r%�KeyErrorr�_add_help_and_info�r
�keyrr2r3�override_existingrrr
�registerys

zRegistry.registercCs>|s||jvrtd|��t||�|j|<|j|||d�dS)ajRegister a new object to be loaded on request.

        :param key: This is the key to use to request the object later.
        :param module_name: The python path to the module. Such as 'os.path'.
        :param member_name: The member of the module to return.  If empty or
                None, get() will return the module itself.
        :param help: Help text for this entry. This may be a string or
                a callable.
        :param info: More information for this entry. Registry.get_info()
                can be used to get this information. Registry treats this as an
                opaque storage location (it is defined by the caller).
        :param override_existing: If True, replace the existing object
                with the new one. If False, if there is already something
                registered with the same key, raise a KeyError
        r0r1N)r%r4rr5�r
r7rrr2r3r8rrr
�
register_lazy�s

zRegistry.register_lazycCsf||jvr ||jvr td|��|j||j|<||j|<|durL|j|}|j||j||d�dS)zbRegister an alias.

        :param key: Alias name
        :param target: Target key name
        z*Key %r already registered and not an aliasNr1)r%r&r4r(r5r')r
r7r.r3rrr
�register_alias�s

zRegistry.register_aliascCs||j|<||j|<dS)z+Add the help and information about this keyN)r'r()r
r7r2r3rrr
r5�s
zRegistry._add_help_and_infocCs|j|�|���S)aReturn the object register()'ed to the given key.

        May raise ImportError if the object was registered lazily and
        there are any problems, or AttributeError if the module does not
        have the supplied member.

        :param key: The key to obtain the object for. If no object has been
            registered to that key, the object registered for self.default_key
            will be returned instead, if it exists. Otherwise KeyError will be
            raised.
        :return: The previously registered object.
        :raises ImportError: If the object was registered lazily, and there are
            problems during import.
        :raises AttributeError: If registered lazily, and the module does not
            contain the registered member.
        )r%�_get_key_or_defaultr�r
r7rrr
�get�szRegistry.getcCs|j|��S)z�Return the module the object will be or was loaded from.

        :param key: The key to obtain the module for.
        :return: The name of the module
        )r%rr>rrr
�_get_module�szRegistry._get_modulecCs:|��D],}|�|�r|�|�|t|�d�fSqdS)aReturn an object whose key is a prefix of the supplied value.

        :fullname: The name to find a prefix for
        :return: a tuple of (object, remainder), where the remainder is the
            portion of the name that did not match the key.
        N)�keys�
startswithr?�len)r
�fullnamer7rrr
�
get_prefix�s
zRegistry.get_prefixcCs*|dur|S|jdur td��n|jSdS)z5Return either 'key' or the default key if key is NoneNz&Key is None, and no default key is set)�default_keyr4r>rrr
r=�s


zRegistry._get_key_or_defaultcCs&|j|�|�}t|�r"|||�S|S)z/Get the help text associated with the given key)r'r=�callable)r
r7Zthe_helprrr
�get_help�s
zRegistry.get_helpcCs|j|�|�S)z7Get the extra information associated with the given key)r(r=r>rrr
�get_info�szRegistry.get_infocCs|j|=dS)zlRemove a registered entry.

        This is mostly for the test suite, but it can be used by others
        N�r%r>rrr
�remove�szRegistry.removecCs
||jvSrrJr>rrr
�__contains__�szRegistry.__contains__cCs
t|j�S)z Get a list of registered entries)�sortedr%rrrr
rA�sz
Registry.keysccs$|jD]}||j|��fVqdSr�r%rr>rrr
�	iteritemss
zRegistry.iteritemscs�fdd����D�S)Ncsg|]}|�j|��f�qSrrN)�.0r7rrr
�
<listcomp>
�z"Registry.items.<locals>.<listcomp>)rArrrr
�itemsszRegistry.itemscCs"||jvrtd|��n||_dS)Nz"No object registered under key %s.)r%r4r$r>rrr
�_set_default_keys
zRegistry._set_default_keycCs|jSr)r$rrrr
�_get_default_keyszRegistry._get_default_keyzACurrent value of the default key. Can be set to any existing key.)�doc)NNF)NNF)N)NN)N)N)N)N)rrrrrr*r/r9r;r<r5r?r@rEr=rHrIrKrLrArOrSrTrU�propertyrFrrrr
r#Vs8	�
�




	

�r#c@s>eZdZdZddd�Zddd�Zddd	�Zd
d�Zdd
�ZdS)�FormatRegistryz*Registry specialised for handling formats.NcCst�|�||_dSr)r#r�_other_registry)r
Zother_registryrrr
rs
zFormatRegistry.__init__FcCs:tj||||||d�|jdur6|jj|||||d�dS�N)r2r3r8)r#r9rYr6rrr
r9!s�
�zFormatRegistry.registerc	Cs>tj|||||||d�|jdur:|jj||||||d�dSrZ)r#r;rYr:rrr
r;)s�
�zFormatRegistry.register_lazycCs&t�||�|jdur"|j�|�dSr)r#rKrYr>rrr
rK4s
zFormatRegistry.removecCst�||�}t|�r|�}|Sr)r#r?rG)r
�
format_string�rrrr
r?9szFormatRegistry.get)N)NNF)NNF)	rrrrrr9r;rKr?rrrr
rXs
�
	�
rXN)rZ
__future__rZpyutilsrZsixishr�objectrrr#rXrrrr
�<module>s$E