Team Ai
Datasetpublic

codekingpro/portable-devtools

sourceHugging Faceupdated 5mo agoView on Hugging Face
1likes14kdownloads
retrieval.cpython-313.pyc61 linesDownload Raw Back to __pycache__
1�

2��j�3����SrSSKJr SSKJr SSKJr SSKrSSKJ	r	 SSKJr \(aSSK
Jr SS	KJrJrJr \	"S4\S9rS\R*\R,4S
Sjjrg!\5a	 SSKJ	r	 NXf=f)z26Helpers related to (dynamic) resource retrieval.7�)�annotations��	lru_cache)�
TYPE_CHECKINGN)�TypeVar)�Resource)�Callable)�URI�D�Retrieve�_T)�defaultc�8^^^�Tc	[SS9mSUUU4SjjnU$)a�8Create a retriever which caches its return values from a simpler callable.9 10Takes a function which returns things like serialized JSON (strings) and11returns something suitable for passing to `Registry` as a retrieve12function.13 14This decorator both reduces a small bit of boilerplate for a common case15(deserializing JSON from strings and creating `Resource` objects from the16result) as well as makes the probable need for caching a bit easier.17Retrievers which otherwise do expensive operations (like hitting the18network) might otherwise be called repeatedly.19 20Examples21--------22 23.. testcode::24 25    from referencing import Registry26    from referencing.typing import URI27    import referencing.retrieval28 29 30    @referencing.retrieval.to_cached_resource()31    def retrieve(uri: URI):32        print(f"Retrieved {uri}")33 34        # Normally, go get some expensive JSON from the network, a file ...35        return '''36            {37                "$schema": "https://json-schema.org/draft/2020-12/schema",38                "foo": "bar"39            }40        '''41 42    one = Registry(retrieve=retrieve).get_or_retrieve("urn:example:foo")43    print(one.value.contents["foo"])44 45    # Retrieving the same URI again reuses the same value (and thus doesn't46    # print another retrieval message here)47    two = Registry(retrieve=retrieve).get_or_retrieve("urn:example:foo")48    print(two.value.contents["foo"])49 50.. testoutput::51 52    Retrieved urn:example:foo53    bar54    bar55 56N)�maxsizec�(>^�TSUUU4Sjj5nU$)Nc�4>�T"U5nT"U5nT"U5$)N�)�uri�response�contents�
from_contents�loads�retrieves   ����[D:\code\apps\devtools\python\user_packages\Python313\site-packages\referencing/retrieval.py�cached_retrieve�>to_cached_resource.<locals>.decorator.<locals>.cached_retrieveVs �����}�H��X��H� ��*�*�)rr57r)rr�cacherrs` ���r�	decorator�%to_cached_resource.<locals>.decoratorUs"���	�	+�	+�58�	+�59�r)rzCallable[[URI], _T]r)rrrrs``` r�to_cached_resourcer!s'���n
�}��$�'�����r)rz+Callable[[Retrieve[D]], Retrieve[D]] | NonerzCallable[[_T], D]rzCallable[[D], Resource[D]]�returnz,Callable[[Callable[[URI], _T]], Retrieve[D]])�__doc__�60__future__r�	functoolsr�typingr�json�typing_extensionsr�ImportError�referencingr�collections.abcr	�referencing.typingr61rr�strr
rrr!rrr�<module>r.s����#�� ���)�!��(�3�3�
�T�3���:>�#�z�z�08�0F�0F�C�6�C��C�.�C�2�	C������s�A*�*A9�8A9
codekingpro/portable-devtools · Team Ai