ó
    sñg‰
  ã                  óð   • S r SSKJr  SSKJr  SSKJrJr  SSKr SSK	J
r
  SSKJr  \(       a
  SSKJrJrJr  \
" S	\S
9rS\R(                  \R*                  4       SS jjrg! \ a	    SSKJ
r
   NRf = f)z2
Helpers related to (dynamic) resource retrieval.
é    )Úannotations©Ú	lru_cache)ÚTYPE_CHECKINGÚCallableN)ÚTypeVar)ÚResource)ÚURIÚDÚRetrieveÚ_T)Údefaultc                ó8   ^ ^^• T c	  [        SS9m SU UU4S jjnU$ )a·  
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                ó(   >^ • TSUUU 4S jj5       nU$ )Nc                ó4   >• T" U 5      nT" U5      nT" U5      $ )N© )ÚuriÚresponseÚcontentsÚfrom_contentsÚloadsÚretrieves      €€€Ú7/usr/lib/python3/dist-packages/referencing/retrieval.pyÚcached_retrieveÚ>to_cached_resource.<locals>.decorator.<locals>.cached_retrieveT   s    ø€ á “}ˆHÙ˜X“ˆHÙ  Ó*Ð*ó    )r   r
   r   )r   r   Úcacher   r   s   ` €€€r   Ú	decoratorÚ%to_cached_resource.<locals>.decoratorS   s"   ù€ Ø	÷	+ð 	+ó 
ð	+ð
 Ðr   )r   zCallable[[URI], _T]r   )r   r   r   r   s   ``` r   Úto_cached_resourcer!      s'   ú€ ðn �}Ü $Ñ'ˆ÷ñ ð Ðr   )r   z+Callable[[Retrieve[D]], Retrieve[D]] | Noner   zCallable[[_T], D]r   zCallable[[D], Resource[D]]Úreturnz,Callable[[Callable[[URI], _T]], Retrieve[D]])Ú__doc__Ú
__future__r   Ú	functoolsr   Útypingr   r   ÚjsonÚtyping_extensionsr   ÚImportErrorÚreferencingr	   Úreferencing.typingr
   r   r   Ústrr   r   r   r!   r   r   r   Ú<module>r-      s“   ðñõ #å ß *Û ðÝ)õ !æß3Ñ3ñ ˆT˜3Ñ€ð :>Ø#Ÿz™zØ08×0FÑ0FðCØ6ðCàðCð .ðCð 2ö	Cøð ó ßðús   œA& Á&A5Á4A5