[docs]@frozenclassNoSuchResource(KeyError):""" The given URI is not present in a registry. Unlike most exceptions, this class *is* intended to be publicly instantiable and *is* part of the public API of the package. """ref:URIdef__eq__(self,other:object)->bool:ifself.__class__isnotother.__class__:returnNotImplementedreturnattrs.astuple(self)==attrs.astuple(other)def__hash__(self)->int:returnhash(attrs.astuple(self))
[docs]@frozenclassNoInternalID(Exception):""" A resource has no internal ID, but one is needed. E.g. in modern JSON Schema drafts, this is the :kw:`$id` keyword. One might be needed if a resource was to-be added to a registry but no other URI is available, and the resource doesn't declare its canonical URI. """resource:Resource[Any]def__eq__(self,other:object)->bool:ifself.__class__isnotother.__class__:returnNotImplementedreturnattrs.astuple(self)==attrs.astuple(other)def__hash__(self)->int:returnhash(attrs.astuple(self))
[docs]@frozenclassUnretrievable(KeyError):""" The given URI is not present in a registry, and retrieving it failed. """ref:URIdef__eq__(self,other:object)->bool:ifself.__class__isnotother.__class__:returnNotImplementedreturnattrs.astuple(self)==attrs.astuple(other)def__hash__(self)->int:returnhash(attrs.astuple(self))
[docs]@frozenclassCannotDetermineSpecification(Exception):""" Attempting to detect the appropriate `Specification` failed. This happens if no discernible information is found in the contents of the new resource which would help identify it. """contents:Anydef__eq__(self,other:object)->bool:ifself.__class__isnotother.__class__:returnNotImplementedreturnattrs.astuple(self)==attrs.astuple(other)def__hash__(self)->int:returnhash(attrs.astuple(self))
[docs]@attrs.frozen# Because here we allow subclassing below.classUnresolvable(Exception):""" A reference was unresolvable. """ref:URIdef__eq__(self,other:object)->bool:ifself.__class__isnotother.__class__:returnNotImplementedreturnattrs.astuple(self)==attrs.astuple(other)def__hash__(self)->int:returnhash(attrs.astuple(self))
[docs]@frozenclassPointerToNowhere(Unresolvable):""" A JSON Pointer leads to a part of a document that does not exist. """resource:Resource[Any]def__str__(self)->str:msg=f"{self.ref!r} does not exist within {self.resource.contents!r}"ifself.ref=="/":msg+=(". The pointer '/' is a valid JSON Pointer but it points to ""an empty string property ''. If you intended to point ""to the entire resource, you should use '#'.")returnmsg
[docs]@frozenclassNoSuchAnchor(Unresolvable):""" An anchor does not exist within a particular resource. """resource:Resource[Any]anchor:strdef__str__(self)->str:return(f"{self.anchor!r} does not exist within {self.resource.contents!r}")
[docs]@frozenclassInvalidAnchor(Unresolvable):""" An anchor which could never exist in a resource was dereferenced. It is somehow syntactically invalid. """resource:Resource[Any]anchor:strdef__str__(self)->str:return(f"'#{self.anchor}' is not a valid anchor, neither as a ""plain name anchor nor as a JSON Pointer. You may have intended "f"to use '#/{self.anchor}', as the slash is required *before each ""segment* of a JSON pointer.")