MOON
Server: Apache
System: Linux s5.yayogua.com.py 6.12.0-124.55.3.el10_1.x86_64 #1 SMP PREEMPT_DYNAMIC Thu May 7 16:54:02 EDT 2026 x86_64
User: w3com (1005)
PHP: 8.2.33
Disabled: NONE
Upload Files
File: //lib/python3.12/site-packages/referencing/__pycache__/retrieval.cpython-312.pyc
�

�% g
���dZddlmZddlmZddlmZmZmZddl	Z	ddl
mZer
ddlm
Z
mZmZed�Zde	j"ej$f							d
d	�Zy)z2
Helpers related to (dynamic) resource retrieval.
�)�annotations��	lru_cache)�
TYPE_CHECKING�Callable�TypeVarN)�Resource)�URI�D�Retrieve�_Tc�8������td���d���fd�}|S)aG
    Create a retriever which caches its return values from a simpler callable.

    Takes a function which returns things like serialized JSON (strings) and
    returns something suitable for passing to `Registry` as a retrieve
    function.

    This decorator both reduces a small bit of boilerplate for a common case
    (deserializing JSON from strings and creating `Resource` objects from the
    result) as well as makes the probable need for caching a bit easier.
    Retrievers which otherwise do expensive operations (like hitting the
    network) might otherwise be called repeatedly.

    Examples
    --------

    .. testcode::

        from referencing import Registry
        from referencing.typing import URI
        import referencing.retrieval


        @referencing.retrieval.to_cached_resource()
        def retrieve(uri: URI):
            print(f"Retrieved {uri}")

            # Normally, go get some expensive JSON from the network, a file ...
            return '''
                {
                    "$schema": "https://json-schema.org/draft/2020-12/schema",
                    "foo": "bar"
                }
            '''

        one = Registry(retrieve=retrieve).get_or_retrieve("urn:example:foo")
        print(one.value.contents["foo"])

        # Retrieving the same URI again reuses the same value (and thus doesn't
        # print another retrieval message here)
        two = Registry(retrieve=retrieve).get_or_retrieve("urn:example:foo")
        print(two.value.contents["foo"])

    .. testoutput::

        Retrieved urn:example:foo
        bar
        bar

    N)�maxsizec�$����d���fd��}|S)Nc�4���|�}�|�}�|�S)N�)�uri�response�contents�
from_contents�loads�retrieves   ����:/usr/lib/python3.12/site-packages/referencing/retrieval.py�cached_retrievez>to_cached_resource.<locals>.decorator.<locals>.cached_retrieveNs �����}�H��X��H� ��*�*�)rr
r)rr�cacherrs` ���r�	decoratorz%to_cached_resource.<locals>.decoratorMs���	�	+�
�	+�
�r)rzCallable[[URI], _T]r)rrrrs``` r�to_cached_resourcers"���n
�}��$�'����r)rz+Callable[[Retrieve[D]], Retrieve[D]] | NonerzCallable[[_T], D]rzCallable[[D], Resource[D]]�returnz,Callable[[Callable[[URI], _T]], Retrieve[D]])�__doc__�
__future__r�	functoolsr�typingrrr�json�referencingr	�referencing.typingr
rrr
rrrrrr�<module>r'su���#��3�3�� ��3�3�
�T�]��:>�#�z�z�08�0F�0F�C�6�C��C�.�C�2�	Cr