jsonschema_extras.registries.retrieval package¶
Helpers related to resource retrieval.
For the default implementation of resource caching,
see referencing.retrieval.to_cached_resource().
It uses lru_cache(maxsize=None) as of version 0.37 .
- type jsonschema_extras.registries.retrieval.CacheFn = Callable[[Retrieve], Retrieve]¶
Function decorator for
Retrieveto cache retrieved resources by their URIs.
- type jsonschema_extras.registries.retrieval.CacheSpecDefault = Literal['default']¶
Specification for default implementation of caching for retrieved resources.
- jsonschema_extras.registries.retrieval.LOADS_FN_JSON_DEFAULT(text, *, loads_kwargs=None)¶
Deserialize a schema from JSON text
Satisfies
LoadTextFn.
- type jsonschema_extras.registries.retrieval.ResourceFromContentsFn = Callable[[D], Resource]¶
Function to make a
Resourcefrom resource contents.Note
The function is intended to take a deserialized data structure.
- Parameters:
D – Resource contents.
- Returns:
Produced
Resourceinstance.- Return type:
Resource[D]
- type jsonschema_extras.registries.retrieval.RetrieveTextFn = Callable[[str], str]¶
Function to retrieve serialized resource data by URI
- Parameters:
str – Resource URI.
- Returns:
Retrieved serialized resource representation.
- Return type:
- jsonschema_extras.registries.retrieval.schema_data_from_json_text(text, *, loads_kwargs=None)[source]¶
Deserialize a schema from JSON text
Satisfies
LoadTextFn.
- jsonschema_extras.registries.retrieval.to_cached_resource(cache=None, loads=<function schema_data_from_json_text>, from_contents=<bound method Resource.from_contents of <class 'referencing._core.Resource'>>)[source]¶
Build a decorator to make a resource retrieval callable out of a
RetrieveTextFnwith caching.RetrieveTextFnretrieves serialized representation by URI. A decorator produced by this function adds deserialization (loads), creating aResourceand caching.- Parameters:
cache (
GenericAlias[TypeVar(D)] |None) – Caching decorator forRetrieve, orNoneto use the default caching implementation (seereferencing.retrieval.to_cached_resource()). Defaults toNone.loads (
GenericAlias[TypeVar(D)]) – Function to deserialize resource contents (for example, JSON data structure from JSON string). Default:LOADS_FN_JSON_DEFAULT(for JSON).from_contents (
GenericAlias[TypeVar(D)]) – Function to produce aResourcefrom deserialized resource contents. Default:from_contents().
- Return type:
Callable[[RetrieveTextFn],Retrieve[TypeVar(D)]]- Returns:
Decorator taking a text retriever
RetrieveTextFnand returning a caching resource retriever.
- jsonschema_extras.registries.retrieval.to_maybe_cached_resource(cache=None, loads=<function schema_data_from_json_text>, from_contents=<bound method Resource.from_contents of <class 'referencing._core.Resource'>>)[source]¶
Build a decorator to make a resource retrieval callable out of a
RetrieveTextFnwith optional caching.RetrieveTextFnretrieves serialized representation by URI. A decorator produced by this function adds deserialization (loads), creating aResourceand optional caching.- Parameters:
cache (
GenericAlias[TypeVar(D)] |CacheSpecDefault|None) – Caching decorator forRetrieve, or'default'to use the default caching implementation (seereferencing.retrieval.to_cached_resource()). Defaults toNone, meaning no caching.loads (
GenericAlias[TypeVar(D)]) – Function to deserialize resource contents (for example, JSON data structure from JSON string). Default:LOADS_FN_JSON_DEFAULT(for JSON).from_contents (
GenericAlias[TypeVar(D)]) – Function to produce aResourcefrom deserialized resource contents. Default:from_contents().
- Return type:
Callable[[RetrieveTextFn],Retrieve[TypeVar(D)]]- Returns:
Decorator taking a text retriever
RetrieveTextFnand returning a resource retriever.
- jsonschema_extras.registries.retrieval.to_resource(loads=<function schema_data_from_json_text>, from_contents=<bound method Resource.from_contents of <class 'referencing._core.Resource'>>)[source]¶
Build a decorator to make a resource retrieval callable out of a
RetrieveTextFn.RetrieveTextFnretrieves serialized representation by URI. A decorator produced by this function adds deserialization (loads), creating aResource(with no caching).- Parameters:
loads (
GenericAlias[TypeVar(D)]) – Function to deserialize resource contents (for example, JSON data structure from JSON string). Default:LOADS_FN_JSON_DEFAULT(for JSON).from_contents (
GenericAlias[TypeVar(D)]) – Function to produce aResourcefrom deserialized resource contents. Default:from_contents().
- Return type:
Callable[[RetrieveTextFn],Retrieve[TypeVar(D)]]- Returns:
Decorator taking a text retriever
RetrieveTextFnand returning a caching resource retriever.