§
    jŠtj©
  ã                  óÖ   — d Z ddlmZ ddlmZ ddlmZ ddlZ	 ddlm	Z	 n# e
$ r	 ddlm	Z	 Y nw xY wddlmZ erddlmZ dd	lmZmZmZ  e	d
e¬¦  «        Zdej        ej        fdd„ZdS )z2
Helpers related to (dynamic) resource retrieval.
é    )Úannotations©Ú	lru_cache)ÚTYPE_CHECKINGN)ÚTypeVar)ÚResource)ÚCallable)ÚURIÚDÚRetrieveÚ_T)ÚdefaultÚcacheú+Callable[[Retrieve[D]], Retrieve[D]] | NoneÚloadsúCallable[[_T], D]Úfrom_contentsúCallable[[D], Resource[D]]Úreturnú,Callable[[Callable[[URI], _T]], Retrieve[D]]c                ó@   ‡ ‡‡— ‰ €t          d¬¦  «        Š dˆ ˆˆfd„}|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)ÚmaxsizeÚretrieveúCallable[[URI], _T]c                ó*   •‡ — ‰dˆˆˆ fd„¦   «         }|S )NÚurir
   c                óF   •—  ‰| ¦  «        } ‰|¦  «        } ‰|¦  «        S )N© )r   ÚresponseÚcontentsr   r   r   s      €€€úS/var/www/html/CA-Chatbot/venv/lib/python3.11/site-packages/referencing/retrieval.pyÚcached_retrievez>to_cached_resource.<locals>.decorator.<locals>.cached_retrieveV   s-   ø€ à�x ‘}”}ˆHØ�u˜X‘”ˆHØ �= Ñ*Ô*Ð*ó    )r   r
   r   )r   r"   r   r   r   s   ` €€€r!   Ú	decoratorz%to_cached_resource.<locals>.decoratorU   s>   øø€ Ø	ð	+ð 	+ð 	+ð 	+ð 	+ð 	+ð 	+ñ 
Œð	+ð
 Ðr#   )r   r   r   )r   r   r   r$   s   ``` r!   Úto_cached_resourcer%      sM   øøø€ ðn €}Ý $Ð'Ñ'Ô'ˆðð ð ð ð ð ð ð ð Ðr#   )r   r   r   r   r   r   r   r   )Ú__doc__Ú
__future__r   Ú	functoolsr   Útypingr   ÚjsonÚtyping_extensionsr   ÚImportErrorÚreferencingr   Úcollections.abcr	   Úreferencing.typingr
   r   r   Ústrr   r   r   r%   r   r#   r!   ú<module>r1      s9  ððð ð #Ð "Ð "Ð "Ð "Ð "à Ð Ð Ð Ð Ð Ø  Ð  Ð  Ð  Ð  Ð  Ø €€€ðØ)Ð)Ð)Ð)Ð)Ð)Ð)øØð ð ð ØÐÐÐÐÐÐÐðøøøð !Ð  Ð  Ð  Ð  Ð  àð 4Ø(Ð(Ð(Ð(Ð(Ð(à3Ð3Ð3Ð3Ð3Ð3Ð3Ð3Ð3Ð3ð €WˆT˜3ÐÑÔ€ð :>Ø#œzØ08Ô0FðCð Cð Cð Cð Cð Cð Cs   š! ¡/®/