schema_salad.codegen_base

Base class for the generation of loaders from schema-salad definitions.

Module Contents

Classes

TypeDef

Schema Salad type description.

LazyInitDef

Lazy initialization logic.

CodeGenBase

Abstract base class for schema salad code generators.

class schema_salad.codegen_base.TypeDef(name, init, is_uri=False, scoped_id=False, ref_scope=0, loader_type=None, instance_type=None, abstract=False)

Schema Salad type description.

Parameters:
  • name (str) –

  • init (str) –

  • is_uri (bool) –

  • scoped_id (bool) –

  • ref_scope (Optional[int]) –

  • loader_type (Optional[str]) –

  • instance_type (Optional[str]) –

  • abstract (bool) –

__slots__ = ['name', 'init', 'is_uri', 'scoped_id', 'ref_scope', 'loader_type', 'instance_type', 'abstract']
class schema_salad.codegen_base.LazyInitDef(name, init)

Lazy initialization logic.

Parameters:
  • name (str) –

  • init (str) –

__slots__ = ('name', 'init')
class schema_salad.codegen_base.CodeGenBase

Abstract base class for schema salad code generators.

declare_type(declared_type)

Add this type to our collection, if needed.

Parameters:

declared_type (TypeDef) –

Return type:

TypeDef

add_lazy_init(lazy_init)

Add lazy initialization logic for a given type.

Parameters:

lazy_init (LazyInitDef) –

Return type:

None

add_vocab(name, uri)

Add the given name as an abbreviation for the given URI.

Parameters:
  • name (str) –

  • uri (str) –

Return type:

None

abstract prologue()

Trigger to generate the prolouge code.

Return type:

None

abstract static safe_name(name)

Generate a safe version of the given name.

Parameters:

name (str) –

Return type:

str

abstract begin_class(classname, extends, doc, abstract, field_names, idfield, optional_fields)

Produce the header for the given class.

Parameters:
  • classname (str) –

  • extends (MutableSequence[str]) –

  • doc (str) –

  • abstract (bool) –

  • field_names (MutableSequence[str]) –

  • idfield (str) –

  • optional_fields (Set[str]) –

Return type:

None

abstract end_class(classname, field_names)

Signal that we are done with this class.

Parameters:
  • classname (str) –

  • field_names (List[str]) –

Return type:

None

abstract type_loader(type_declaration, container=None, no_link_check=None)

Parse the given type declaration and declare its components.

Parameters:
  • type_declaration (Union[List[Any], Dict[str, Any]]) –

  • container (Optional[str]) –

  • no_link_check (Optional[bool]) –

Return type:

TypeDef

abstract declare_field(name, fieldtype, doc, optional, subscope)

Output the code to load the given field.

Parameters:
  • name (str) –

  • fieldtype (TypeDef) –

  • doc (Optional[str]) –

  • optional (bool) –

  • subscope (Optional[str]) –

Return type:

None

abstract declare_id_field(name, fieldtype, doc, optional)

Output the code to handle the given ID field.

Parameters:
Return type:

None

abstract uri_loader(inner, scoped_id, vocab_term, ref_scope, no_link_check=None)

Construct the TypeDef for the given URI loader.

Parameters:
  • inner (TypeDef) –

  • scoped_id (bool) –

  • vocab_term (bool) –

  • ref_scope (Optional[int]) –

  • no_link_check (Optional[bool]) –

Return type:

TypeDef

abstract idmap_loader(field, inner, map_subject, map_predicate)

Construct the TypeDef for the given mapped ID loader.

Parameters:
  • field (str) –

  • inner (TypeDef) –

  • map_subject (str) –

  • map_predicate (Optional[str]) –

Return type:

TypeDef

abstract typedsl_loader(inner, ref_scope)

Construct the TypeDef for the given DSL loader.

Parameters:
  • inner (TypeDef) –

  • ref_scope (Optional[int]) –

Return type:

TypeDef

abstract epilogue(root_loader)

Trigger to generate the epilouge code.

Parameters:

root_loader (TypeDef) –

Return type:

None

abstract secondaryfilesdsl_loader(inner)

Construct the TypeDef for secondary files.

Parameters:

inner (TypeDef) –

Return type:

TypeDef