HEX
Server: Apache
System: Linux 185.122.168.184.host.secureserver.net 5.14.0-570.60.1.el9_6.x86_64 #1 SMP PREEMPT_DYNAMIC Wed Nov 5 05:00:59 EST 2025 x86_64
User: barbeatleanalyti (1024)
PHP: 8.1.33
Disabled: NONE
Upload Files
File: //var/opt/nydus/ops/referencing/__pycache__/retrieval.cpython-39.pyc
a

�,�h�
�@s�dZddlmZddlmZddlmZmZddlZzddl	m
Z
Wneybddlm
Z
Yn0ddlm
Z
er�ddlmZmZmZe
d	ed
�Zdeje
jfddd
dd�dd�ZdS)z2
Helpers related to (dynamic) resource retrieval.
�)�annotations��	lru_cache)�
TYPE_CHECKING�CallableN)�TypeVar)�Resource)�URI�D�Retrieve�_T)�defaultz+Callable[[Retrieve[D]], Retrieve[D]] | NonezCallable[[_T], D]zCallable[[D], Resource[D]]z,Callable[[Callable[[URI], _T]], Retrieve[D]])�cache�loads�
from_contents�returncs,�durtdd��dd����fdd�}|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)�maxsizezCallable[[URI], _T]��retrievecs�dd����fdd��}|S)Nr	)�urics�|�}�|�}�|�S)N�)r�response�contents)rrrr�F/opt/nydus/tmp/pip-target-wkfpz8uv/lib/python/referencing/retrieval.py�cached_retrieveTsz>to_cached_resource.<locals>.decorator.<locals>.cached_retriever)rr�rrrrr�	decoratorSsz%to_cached_resource.<locals>.decoratorr)rrrrrrr�to_cached_resources7
	r)�__doc__�
__future__r�	functoolsr�typingrr�jsonZtyping_extensionsr�ImportErrorZreferencingrZreferencing.typingr	r
r�strrrrrrrrr�<module>s �