+
    (i
                        R t ^ RIHt ^ RIHt ^ RIHtHt ^ RIt ^ RI	H
t
 ^ RIHt ]'       d   ^ RIHtHtHt ]
! R]R	7      tR]P(                  ]P*                  3R
 R lltR#   ] d
    ^ RIH
t
  LRi ; i)z2
Helpers related to (dynamic) resource retrieval.
)annotations	lru_cache)TYPE_CHECKINGCallableN)TypeVar)Resource)URIDRetrieve_T)defaultc               (    V ^8  d   QhRRRRRRRR/# )	   cachez+Callable[[Retrieve[D]], Retrieve[D]] | NoneloadszCallable[[_T], D]from_contentszCallable[[D], Resource[D]]returnz,Callable[[Callable[[URI], _T]], Retrieve[D]] )formats   "7/usr/lib/python3/dist-packages/referencing/retrieval.py__annotate__r      s6     C C6CC .C 2	C    c                B   a aa S f   \        RR7      o R V VV3R llpV# )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                   V ^8  d   QhRR/# )r   retrievezCallable[[URI], _T]r   )r   s   "r   r   (to_cached_resource.<locals>.__annotate__S   s      / r   c                *   <a  SR  VVV 3R ll4       pV# )c                   V ^8  d   QhRR/# )r   urir	   r   )r   s   "r   r   ;to_cached_resource.<locals>.decorator.<locals>.__annotate__U   s     	+ 	+ 	+r   c                4   < S! V 4      pS! V4      pS! V4      # )Nr   )r    responsecontentsr   r   r   s   &  r   cached_retrieve>to_cached_resource.<locals>.decorator.<locals>.cached_retrieveT   s     }HXH **r   r   )r   r%   r   r   r   s   f r   	decorator%to_cached_resource.<locals>.decoratorS   s"    		+ 	+ 
	+
 r   r   )r   r   r   r'   s   fff r   to_cached_resourcer)      s'    n }$'  r   )__doc__
__future__r   	functoolsr   typingr   r   jsontyping_extensionsr   ImportErrorreferencingr   referencing.typingr	   r
   r   strr   r   r   r)   r   r   r   <module>r4      sq    #  * ) !33 T3 :>#zz080F0FC C  s   A% %A54A5