Ë $L i© ãóî—dZddlmZddlmZddlmZddlZ ddlm Z ddl m Z erddl mZdd lmZmZmZe d e¬ «Zdej*e j,f d d „Zy#e $r ddlm Z YŒSwxYw)z2 Helpers related to (dynamic) resource retrieval. é)Ú annotations©Ú lru_cache)Ú TYPE_CHECKINGN)ÚTypeVar)ÚResource)ÚCallable)ÚURIÚDÚRetrieveÚ_T)Údefaultcó8‡‡‡—‰€ td¬«Šdˆˆˆfd„ }|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)Úmaxsizecó$•‡—‰dˆˆˆfd„ «}|S)Ncó4•—‰|«}‰|«}‰|«S)N©)ÚuriÚresponseÚcontentsÚ from_contentsÚloadsÚretrieves €€€ú[/mnt/ssd/data/python-lab/Trading/venv/lib/python3.12/site-packages/referencing/retrieval.pyÚcached_retrievez>to_cached_resource..decorator..cached_retrieveVs ø€á “}ˆHÙ˜X“ˆHÙ  Ó*Ð *ó)rr r)rrÚcacherrs` €€€rÚ decoratorz%to_cached_resource..decoratorUsù€Ø ö +ó ð +ð Ðr)rzCallable[[URI], _T]r)rrrrs``` rÚto_cached_resourcers"ú€ðn €}Ü $Ô'ˆ÷ð Ðr)rz+Callable[[Retrieve[D]], Retrieve[D]] | NonerzCallable[[_T], D]rzCallable[[D], Resource[D]]Úreturnz,Callable[[Callable[[URI], _T]], Retrieve[D]])Ú__doc__Ú __future__rÚ functoolsrÚtypingrÚjsonÚtyping_extensionsrÚ ImportErrorÚ referencingrÚcollections.abcr Úreferencing.typingr r r Ústrr rrrrrrúr,s–ðñõ#åÝ Û ðÝ)õ!áÝ(ç3Ñ3ñ ˆT˜3Ô€ð:>Ø#Ÿz™zØ08×0FÑ0FðCØ 6ðCà ðCð.ðCð2ô CøðòßðúsšA&Á& A4Á3A4