+
     h
  c                  s    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)Zdefaultc               s(    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]]Zreturnz,Callable[[Callable[[URI], _T]], Retrieve[D]] Zformat   ":/usr/lib/python3.14/site-packages/referencing/retrieval.py__annotate__r      s6     C C6CC .C 2	C    c                sB   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)Zmaxsizec                   V ^8  d   QhRR/# )r   retrievezCallable[[URI], _T]r   r   r   r   r   Z(to_cached_resource.<locals>.__annotate__S   s      / r   c                s*   <a  SR  VVV 3R ll4       pV# )c               r   )r   urir   r   r   r   r   r   Z;to_cached_resource.<locals>.decorator.<locals>.__annotate__U   s     	+ 	+ 	+r   c                s4   < S! V 4      pS! V4      pS! V4      # )Nr   )r   ZresponseZcontentsr   r   r   s   &  r   cached_retrieveZ>to_cached_resource.<locals>.decorator.<locals>.cached_retrieveT   s     }HXH **r   r   )r   r   r   r   r   s   f r   	decoratorZ%to_cached_resource.<locals>.decoratorS   s"    		+ 	+ 
	+
 r   r   )r   r   r   r   s   fff r   to_cached_resourcer      s'    n }$'  r   )Z__doc__Z
__future__r    Z	functoolsr   Ztypingr   r   ZjsonZtyping_extensionsr   ZImportErrorZreferencingr   Zreferencing.typingr   r   r	   Zstrr
   r   r   r   r   r   r   <module>r      sq    #  * ) !33 T3 :>#zz080F0FC C  s   A% %A54A5