schema_salad.python_codegen_support

Template code used by python_codegen.py.

Attributes

CacheType

IdxType

save_type

Exceptions

SchemaSaladException

Base class for all schema-salad exceptions.

ValidationException

Indicates error with document against the provided schema.

Classes

DefaultFetcher

The default Fetcher implementation.

Fetcher

Fetch resources from URIs.

MemoryCachingFetcher

Fetcher that caches resources in memory after retrieval.

SourceLine

LoadingOptions

Saveable

Mark classes than have a save() and fromDoc() function.

Functions

add_lc_filename(r, source)

yaml_no_ts()

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

load_field(val, fieldtype, baseuri, loadingOptions[, lc])

Load field.

extract_type(val_type)

Take a type of value, and extracts the value as a string.

convert_typing(val_type)

Normalize type names to schema-salad types.

parse_errors(error_message)

Parse error messages from several loaders into one error message.

save(val[, top, base_url, relative_uris])

save_with_metadata(val, valLoadingOpts[, top, ...])

Save and set $namespaces, $schemas, $base and any other metadata fields at the top level.

expand_url(url, base_url, loadingOptions[, scoped_id, ...])

file_uri(path[, split_frag])

Transform a file path into a URL with file scheme.

prefix_url(url, namespaces)

Expand short forms into full URLs using the given namespace dictionary.

save_relative_uri(uri, base_url, scoped_id, ref_scope, ...)

Convert any URI to a relative one, obeying the scoping rules.

shortname(inputid)

Compute the shortname of a fully qualified identifier.

Module Contents

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

Bases: Exception

digraph inheritancedce83ace68 { 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.python_codegen_support.ValidationException(msg, sl=None, children=None, bullet_for_children='')

Bases: SchemaSaladException

digraph inheritance82179f0a35 { 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.python_codegen_support.DefaultFetcher(cache, session)

Bases: MemoryCachingFetcher

digraph inheritance83d39a7b74 { 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.python_codegen_support.Fetcher

Bases: abc.ABC

digraph inheritance784f3db706 { 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"]; "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)"]; }

Fetch resources from URIs.

abstract fetch_text(url, content_types=None)

Retrieve the given resource as a string.

Parameters:
  • url (str)

  • content_types (Optional[List[str]])

Return type:

str

abstract check_exists(url)

Check if the given resource exists.

Parameters:

url (str)

Return type:

bool

abstract urljoin(base_url, url)

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

Parameters:
Return type:

str

schemes = ['file', 'http', 'https', 'mailto']
supported_schemes()

Return the list of supported URI schemes.

Return type:

List[str]

class schema_salad.python_codegen_support.MemoryCachingFetcher(cache)

Bases: Fetcher

digraph inheritance6bbc9e3acc { 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"]; "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)"]; }

Fetcher that caches resources in memory after retrieval.

Parameters:

cache (schema_salad.utils.CacheType)

class schema_salad.python_codegen_support.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.python_codegen_support.add_lc_filename(r, source)
Parameters:
  • r (ruamel.yaml.comments.CommentedBase)

  • source (str)

Return type:

None

schema_salad.python_codegen_support.CacheType
schema_salad.python_codegen_support.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.python_codegen_support.IdxType
class schema_salad.python_codegen_support.LoadingOptions(fetcher=None, namespaces=None, schemas=None, fileuri=None, copyfrom=None, original_doc=None, addl_metadata=None, baseuri=None, idx=None, imports=None, includes=None, no_link_check=None, container=None)
Parameters:
  • fetcher (Optional[schema_salad.fetcher.Fetcher])

  • namespaces (Optional[Dict[str, str]])

  • schemas (Optional[List[str]])

  • fileuri (Optional[str])

  • copyfrom (Optional[LoadingOptions])

  • original_doc (Optional[Any])

  • addl_metadata (Optional[Dict[str, str]])

  • baseuri (Optional[str])

  • idx (Optional[IdxType])

  • imports (Optional[List[str]])

  • includes (Optional[List[str]])

  • no_link_check (Optional[bool])

  • container (Optional[str])

idx: IdxType
fileuri: str | None
baseuri: str
namespaces: MutableMapping[str, str]
schemas: MutableSequence[str]
original_doc: Any | None
addl_metadata: MutableMapping[str, Any]
fetcher: schema_salad.fetcher.Fetcher
vocab: Dict[str, str]
rvocab: Dict[str, str]
cache: schema_salad.utils.CacheType
imports: List[str]
includes: List[str]
container: str | None
property graph: rdflib.Graph

Generate a merged rdflib.Graph from all entries in self.schemas.

Return type:

rdflib.Graph

class schema_salad.python_codegen_support.Saveable

Bases: abc.ABC

digraph inheritance09618532e3 { 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"]; "Saveable" [URL="#schema_salad.python_codegen_support.Saveable",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="Mark classes than have a save() and fromDoc() function."]; "ABC" -> "Saveable" [arrowsize=0.5,style="setlinewidth(0.5)"]; }

Mark classes than have a save() and fromDoc() function.

classmethod fromDoc(_doc, baseuri, loadingOptions, docRoot=None)
Abstractmethod:

Parameters:
Return type:

Saveable

Construct this object from the result of yaml.load().

abstract save(top=False, base_url='', relative_uris=True)

Convert this object to a JSON/YAML friendly dictionary.

Parameters:
Return type:

Dict[str, Any]

schema_salad.python_codegen_support.load_field(val, fieldtype, baseuri, loadingOptions, lc=None)

Load field.

Parameters:
Return type:

Any

schema_salad.python_codegen_support.save_type
schema_salad.python_codegen_support.extract_type(val_type)

Take a type of value, and extracts the value as a string.

Parameters:

val_type (Type[Any])

Return type:

str

schema_salad.python_codegen_support.convert_typing(val_type)

Normalize type names to schema-salad types.

Parameters:

val_type (str)

Return type:

str

schema_salad.python_codegen_support.parse_errors(error_message)

Parse error messages from several loaders into one error message.

Parameters:

error_message (str)

Return type:

Tuple[str, str, str]

schema_salad.python_codegen_support.save(val, top=True, base_url='', relative_uris=True)
Parameters:
  • val (Any)

  • top (bool)

  • base_url (str)

  • relative_uris (bool)

Return type:

save_type

schema_salad.python_codegen_support.save_with_metadata(val, valLoadingOpts, top=True, base_url='', relative_uris=True)

Save and set $namespaces, $schemas, $base and any other metadata fields at the top level.

Parameters:
Return type:

save_type

schema_salad.python_codegen_support.expand_url(url, base_url, loadingOptions, scoped_id=False, vocab_term=False, scoped_ref=None)
Parameters:
Return type:

str

schema_salad.python_codegen_support.file_uri(path, split_frag=False)

Transform a file path into a URL with file scheme.

Parameters:
Return type:

str

schema_salad.python_codegen_support.prefix_url(url, namespaces)

Expand short forms into full URLs using the given namespace dictionary.

Parameters:
Return type:

str

schema_salad.python_codegen_support.save_relative_uri(uri, base_url, scoped_id, ref_scope, relative_uris)

Convert any URI to a relative one, obeying the scoping rules.

Parameters:
  • uri (Any)

  • base_url (str)

  • scoped_id (bool)

  • ref_scope (Optional[int])

  • relative_uris (bool)

Return type:

Any

schema_salad.python_codegen_support.shortname(inputid)

Compute the shortname of a fully qualified identifier.

See https://w3id.org/cwl/v1.2/SchemaSalad.html#Short_names.

Parameters:

inputid (str)

Return type:

str