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