schema_salad.ref_resolver

Attributes

AttachmentsType

CacheType

ContextType

FetcherCallableType

IdxResultType

IdxType

ResolvedRefType

ResolveType

Exceptions

SchemaSaladException

Base class for all schema-salad exceptions.

ValidationException

Indicates error with document against the provided schema.

Classes

DefaultFetcher

The default Fetcher implementation.

SourceLine

NormDict

A Dict where all keys are normalized using the provided function.

Loader

Functions

add_lc_filename(r, source)

relname(source)

aslist(thing)

Wrap single items and lists.

onWindows()

Check if Python is running on Windows OS.

yaml_no_ts()

Get a YAML loader that won't parse timestamps into datetime objects.

file_uri(path[, split_frag])

uri_file_path(url)

to_validation_exception(e)

Convert ruamel.yaml exception to our type.

SubLoader(loader)

Module Contents

exception schema_salad.ref_resolver.SchemaSaladException(msg, sl=None, children=None, bullet_for_children='')

Bases: Exception

digraph inheritanced63fa9fcc7 { bgcolor=transparent; rankdir=LR; size="8.0, 12.0"; "SchemaSaladException" [URL="../exceptions/index.html#schema_salad.exceptions.SchemaSaladException",fillcolor=white,fontname="Vera Sans, DejaVu Sans, Liberation Sans, Arial, Helvetica, sans",fontsize=10,height=0.25,shape=box,style="setlinewidth(0.5),filled",target="_top",tooltip="Base class for all schema-salad exceptions."]; }

Base class for all schema-salad exceptions.

Parameters:
propagate_sourceline()
Return type:

None

as_warning()
Return type:

SchemaSaladException

with_sourceline(sl)
Parameters:

sl (Optional[schema_salad.sourceline.SourceLine])

Return type:

SchemaSaladException

leaves()
Return type:

List[SchemaSaladException]

prefix()
Return type:

str

summary(level=0, with_bullet=False)
Parameters:
Return type:

str

__str__()

Convert to a string using pretty_str().

Return type:

str

pretty_str(level=0)
Parameters:

level (int)

Return type:

str

exception schema_salad.ref_resolver.ValidationException(msg, sl=None, children=None, bullet_for_children='')

Bases: SchemaSaladException

digraph inheritancee951558fe2 { bgcolor=transparent; rankdir=LR; size="8.0, 12.0"; "SchemaSaladException" [URL="../exceptions/index.html#schema_salad.exceptions.SchemaSaladException",fillcolor=white,fontname="Vera Sans, DejaVu Sans, Liberation Sans, Arial, Helvetica, sans",fontsize=10,height=0.25,shape=box,style="setlinewidth(0.5),filled",target="_top",tooltip="Base class for all schema-salad exceptions."]; "ValidationException" [URL="../exceptions/index.html#schema_salad.exceptions.ValidationException",fillcolor=white,fontname="Vera Sans, DejaVu Sans, Liberation Sans, Arial, Helvetica, sans",fontsize=10,height=0.25,shape=box,style="setlinewidth(0.5),filled",target="_top",tooltip="Indicates error with document against the provided schema."]; "SchemaSaladException" -> "ValidationException" [arrowsize=0.5,style="setlinewidth(0.5)"]; }

Indicates error with document against the provided schema.

Parameters:
class schema_salad.ref_resolver.DefaultFetcher(cache, session)

Bases: MemoryCachingFetcher

digraph inheritance7aca33cd27 { bgcolor=transparent; rankdir=LR; size="8.0, 12.0"; "ABC" [URL="https://docs.python.org/3/library/abc.html#abc.ABC",fillcolor=white,fontname="Vera Sans, DejaVu Sans, Liberation Sans, Arial, Helvetica, sans",fontsize=10,height=0.25,shape=box,style="setlinewidth(0.5),filled",target="_top",tooltip="Helper class that provides a standard way to create an ABC using"]; "DefaultFetcher" [URL="../fetcher/index.html#schema_salad.fetcher.DefaultFetcher",fillcolor=white,fontname="Vera Sans, DejaVu Sans, Liberation Sans, Arial, Helvetica, sans",fontsize=10,height=0.25,shape=box,style="setlinewidth(0.5),filled",target="_top",tooltip="The default Fetcher implementation."]; "MemoryCachingFetcher" -> "DefaultFetcher" [arrowsize=0.5,style="setlinewidth(0.5)"]; "Fetcher" [URL="../fetcher/index.html#schema_salad.fetcher.Fetcher",fillcolor=white,fontname="Vera Sans, DejaVu Sans, Liberation Sans, Arial, Helvetica, sans",fontsize=10,height=0.25,shape=box,style="setlinewidth(0.5),filled",target="_top",tooltip="Fetch resources from URIs."]; "ABC" -> "Fetcher" [arrowsize=0.5,style="setlinewidth(0.5)"]; "MemoryCachingFetcher" [URL="../fetcher/index.html#schema_salad.fetcher.MemoryCachingFetcher",fillcolor=white,fontname="Vera Sans, DejaVu Sans, Liberation Sans, Arial, Helvetica, sans",fontsize=10,height=0.25,shape=box,style="setlinewidth(0.5),filled",target="_top",tooltip="Fetcher that caches resources in memory after retrieval."]; "Fetcher" -> "MemoryCachingFetcher" [arrowsize=0.5,style="setlinewidth(0.5)"]; }

The default Fetcher implementation.

Parameters:
fetch_text(url, content_types=None)

Retrieve the given resource as a string.

Parameters:
  • url (str)

  • content_types (Optional[List[str]])

Return type:

str

check_exists(url)

Check if the given resource exists.

Parameters:

url (str)

Return type:

bool

urljoin(base_url, url)

Construct a full (“absolute”) URL by combining a “base URL” with another URL.

Parameters:
Return type:

str

class schema_salad.ref_resolver.SourceLine(item, key=None, raise_type=str, include_traceback=False)
Parameters:
  • item (Any)

  • key (Optional[Any])

  • raise_type (Callable[[str], Any])

  • include_traceback (bool)

__enter__()
Return type:

SourceLine

__exit__(exc_type, exc_value, tb)
Parameters:
  • exc_type (Any)

  • exc_value (Any)

  • tb (Any)

Return type:

None

file()
Return type:

Optional[str]

start()
Return type:

Optional[Tuple[int, int]]

end()
Return type:

Optional[Tuple[int, int]]

makeLead()
Return type:

str

makeError(msg)
Parameters:

msg (str)

Return type:

Any

schema_salad.ref_resolver.add_lc_filename(r, source)
Parameters:
  • r (ruamel.yaml.comments.CommentedBase)

  • source (str)

Return type:

None

schema_salad.ref_resolver.relname(source)
Parameters:

source (str)

Return type:

str

schema_salad.ref_resolver.AttachmentsType
schema_salad.ref_resolver.CacheType
schema_salad.ref_resolver.ContextType
schema_salad.ref_resolver.FetcherCallableType
schema_salad.ref_resolver.IdxResultType
schema_salad.ref_resolver.IdxType
schema_salad.ref_resolver.ResolvedRefType
schema_salad.ref_resolver.ResolveType
schema_salad.ref_resolver.aslist(thing)

Wrap single items and lists.

Return lists unchanged.

Parameters:

thing (Any)

Return type:

MutableSequence[Any]

schema_salad.ref_resolver.onWindows()

Check if Python is running on Windows OS.

Return type:

bool

schema_salad.ref_resolver.yaml_no_ts()

Get a YAML loader that won’t parse timestamps into datetime objects.

Such datetime objects can’t be easily dumped into JSON.

Return type:

ruamel.yaml.main.YAML

schema_salad.ref_resolver.file_uri(path, split_frag=False)
Parameters:
Return type:

str

schema_salad.ref_resolver.uri_file_path(url)
Parameters:

url (str)

Return type:

str

schema_salad.ref_resolver.to_validation_exception(e)

Convert ruamel.yaml exception to our type.

Parameters:

e (ruamel.yaml.error.MarkedYAMLError)

Return type:

schema_salad.exceptions.ValidationException

class schema_salad.ref_resolver.NormDict(normalize=str)

Bases: Dict[str, Union[ruamel.yaml.comments.CommentedMap, ruamel.yaml.comments.CommentedSeq, str, None]]

digraph inheritance5b4caf496b { bgcolor=transparent; rankdir=LR; size="8.0, 12.0"; "Dict" [URL="https://docs.python.org/3/library/typing.html#typing.Dict",fillcolor=white,fontname="Vera Sans, DejaVu Sans, Liberation Sans, Arial, Helvetica, sans",fontsize=10,height=0.25,shape=box,style="setlinewidth(0.5),filled",target="_top"]; "NormDict" [URL="#schema_salad.ref_resolver.NormDict",fillcolor=white,fontname="Vera Sans, DejaVu Sans, Liberation Sans, Arial, Helvetica, sans",fontsize=10,height=0.25,shape=box,style="setlinewidth(0.5),filled",target="_top",tooltip="A Dict where all keys are normalized using the provided function."]; "Dict" -> "NormDict" [arrowsize=0.5,style="setlinewidth(0.5)"]; }

A Dict where all keys are normalized using the provided function.

Parameters:

normalize (Callable[[str], str])

__eq__(other)

Return self==value.

Parameters:

other (Any)

Return type:

bool

__getitem__(key)

x.__getitem__(y) <==> x[y]

Parameters:

key (Any)

Return type:

Any

__setitem__(key, value)

Set self[key] to value.

Parameters:
  • key (Any)

  • value (Any)

Return type:

Any

__delitem__(key)

Delete self[key].

Parameters:

key (Any)

Return type:

Any

__contains__(key)

True if the dictionary has the specified key, else False.

Parameters:

key (Any)

Return type:

bool

__del__()
Return type:

None

schema_salad.ref_resolver.SubLoader(loader)
Parameters:

loader (Loader)

Return type:

Loader

class schema_salad.ref_resolver.Loader(ctx, schemagraph=None, foreign_properties=None, idx=None, cache=None, session=None, fetcher_constructor=None, skip_schemas=None, url_fields=None, allow_attachments=None, doc_cache=True, salad_version=None)
Parameters:
  • ctx (schema_salad.utils.ContextType)

  • schemagraph (Optional[rdflib.graph.Graph])

  • foreign_properties (Optional[Set[str]])

  • idx (Optional[schema_salad.utils.IdxType])

  • cache (Optional[schema_salad.utils.CacheType])

  • session (Optional[requests.sessions.Session])

  • fetcher_constructor (Optional[schema_salad.utils.FetcherCallableType])

  • skip_schemas (Optional[bool])

  • url_fields (Optional[Set[str]])

  • allow_attachments (Optional[schema_salad.utils.AttachmentsType])

  • doc_cache (Union[str, bool])

  • salad_version (Optional[str])

expand_url(url, base_url, scoped_id=False, vocab_term=False, scoped_ref=None)
Parameters:
  • url (str)

  • base_url (str)

  • scoped_id (bool)

  • vocab_term (bool)

  • scoped_ref (Optional[int])

Return type:

str

add_namespaces(ns)
Parameters:

ns (Dict[str, str])

Return type:

None

add_schemas(ns, base_url)
Parameters:
Return type:

None

add_context(newcontext)
Parameters:

newcontext (schema_salad.utils.ContextType)

Return type:

None

resolve_ref(ref, base_url=None, checklinks=True, strict_foreign_properties=False, content_types=None)
Parameters:
  • ref (schema_salad.utils.ResolveType)

  • base_url (Optional[str])

  • checklinks (bool)

  • strict_foreign_properties (bool)

  • content_types (Optional[List[str]])

Return type:

schema_salad.utils.ResolvedRefType

resolve_all(document, base_url, file_base=None, checklinks=True, strict_foreign_properties=False)
Parameters:
  • document (schema_salad.utils.ResolveType)

  • base_url (str)

  • file_base (Optional[str])

  • checklinks (bool)

  • strict_foreign_properties (bool)

Return type:

schema_salad.utils.ResolvedRefType

fetch(url, inject_ids=True, content_types=None)
Parameters:
  • url (str)

  • inject_ids (bool)

  • content_types (Optional[List[str]])

Return type:

schema_salad.utils.IdxResultType

validate_scoped(field, link, docid)
Parameters:
Return type:

str

Parameters:
  • field (str)

  • link (Union[str, ruamel.yaml.comments.CommentedSeq, ruamel.yaml.comments.CommentedMap])

  • docid (str)

  • all_doc_ids (Dict[str, str])

Return type:

Union[str, ruamel.yaml.comments.CommentedSeq, ruamel.yaml.comments.CommentedMap]

getid(d)
Parameters:

d (Any)

Return type:

Optional[str]

Parameters:
  • document (schema_salad.utils.ResolveType)

  • base_url (str)

  • all_doc_ids (Dict[str, str])

  • strict_foreign_properties (bool)

Return type:

None