blob: a61446417e68e8e397346b14e8525cc9062f1c59 (
about) (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
|
"""
Type-annotation related support for the referencing library.
"""
from __future__ import annotations
from collections.abc import Mapping as Mapping
from typing import TYPE_CHECKING, Any, Protocol
try:
from typing_extensions import TypeVar
except ImportError: # pragma: no cover
from typing import TypeVar
if TYPE_CHECKING:
from referencing._core import Resolved, Resolver, Resource
#: A URI which identifies a `Resource`.
URI = str
#: The type of documents within a registry.
D = TypeVar("D", default=Any)
class Retrieve(Protocol[D]):
"""
A retrieval callable, usable within a `Registry` for resource retrieval.
Does not make assumptions about where the resource might be coming from.
"""
def __call__(self, uri: URI) -> Resource[D]:
"""
Retrieve the resource with the given URI.
Raise `referencing.exceptions.NoSuchResource` if you wish to indicate
the retriever cannot lookup the given URI.
"""
...
class Anchor(Protocol[D]):
"""
An anchor within a `Resource`.
Beyond "simple" anchors, some specifications like JSON Schema's 2020
version have dynamic anchors.
"""
@property
def name(self) -> str:
"""
Return the name of this anchor.
"""
...
def resolve(self, resolver: Resolver[D]) -> Resolved[D]:
"""
Return the resource for this anchor.
"""
...
|