DefinitionsConst

class dsviper.DefinitionsConst

Bases: object

Retrieves registered types and attachments by runtime id.

Note: Not directly instantiable.

attachment_runtime_ids() → set[ValueUUId]

Return the set of runtime ID for all attachments.

attachments() → list[Attachment]

Return the list of attachments.

check_attachment(attachment_runtime_id: ValueUUId) → Attachment

Return the attachment registered under attachment_runtime_id, or raise if none is.

check_club(runtime_id: ValueUUId) → TypeClub

Return the club registered under runtime_id, or raise if none is.

check_concept(runtime_id: ValueUUId) → TypeConcept

Return the concept registered under runtime_id, or raise if none is.

check_enumeration(runtime_id: ValueUUId) → TypeEnumeration

Return the enum registered under runtime_id, or raise if none is.

check_structure(runtime_id: ValueUUId) → TypeStructure

Return the struct registered under runtime_id, or raise if none is.

check_type(runtime_id: ValueUUId) → Type

Return the type registered under runtime_id, or raise if none is.

club_runtime_ids() → set[ValueUUId]

Return the set of runtime ID for all clubs.

clubs() → list[TypeClub]

Return the list of clubs.

collector() → DefinitionsCollector

Return an empty DefinitionsCollector bound to these definitions, to feed extract() with.

concept_members(type_concept: TypeConcept) → list[TypeConcept]

Return type_concept and every concept whose parent chain reaches it.

They are the concepts a key of type_concept accepts; clubs play no part.

concept_runtime_ids() → set[ValueUUId]

Return the set of runtime ID for all concepts.

concepts() → list[TypeConcept]

Return the list of concepts.

contains(definitions: DefinitionsConst) → bool

Return True if every type and attachment of definitions is already registered here.

copy() → Definitions

Return a mutable Definitions holding the same types - the way out of the const view.

discard(namespace: dict | None = None) → None

Remove injected constants from a namespace. If namespace is None, the __main__ module is used.

encode(*, stream_codec_instancing: StreamCodecInstancing | None = None) → ValueBlob

Return the blob that encodes the definitions with Codec.STREAM_TOKEN_BINARY if not specified.

enumeration_runtime_ids() → set[ValueUUId]

Return the set of runtime ID for all enums.

enumerations() → list[TypeEnumeration]

Return the list of enums.

extract(definitions_collector: DefinitionsCollector) → Definitions

Return a new Definitions holding only the types definitions_collector gathered, and the types those depend on.

hexdigest() → str

Return the SHA1 of the definitions, as a hex string.

Two Definitions holding the same types and attachments share it, which is what makes it usable as an identity.

inject(namespace: dict | None = None) → None

Fill a Python namespace - a module, or the dict globals() answers - with constants for all definitions. None means the __main__ module. In an embedded editor, pass globals().

Every part is upper snake case, so a Viper NameSpace OtherNs and a structure UserProfile meet as OTHER_NS_S_USER_PROFILE:

  • <namespace>_T_<name> for a concept or a club.

  • <namespace>_K_<name> for a key of a concept or a club.

  • <namespace>_S_<name> for a structure.

  • <namespace>_E_<name> for an enumeration.

  • <namespace>_P_<name>_… for the path to a property of a structure.

  • <namespace>_A_<key>_<name> for an attachment.

<key> is the key concept’s own name, unless another attachment of the same namespace carries the same name over a concept of the same short name - what DefinitionsInspector.is_ambiguous answers. It is then qualified by its namespace, so two User concepts give APP_A_APP_USER_PROFILE beside APP_A_OTHER_NS_USER_PROFILE.

is_equal(definitions: DefinitionsConst) → bool

Return True if definitions holds the same types and attachments.

By content, so two registries built apart from the same model answer True. Comparing hexdigest() answers the same question on a string, which is what travels between processes.

query_attachment(attachment_runtime_id: ValueUUId) → Attachment | None

Return the attachment registered under attachment_runtime_id, or None if none is.

query_club(runtime_id: ValueUUId) → TypeClub | None

Return the club registered under runtime_id, or None if none is.

query_concept(runtime_id: ValueUUId) → TypeConcept | None

Return the concept registered under runtime_id, or None if none is.

query_enumeration(runtime_id: ValueUUId) → TypeEnumeration | None

Return the enum registered under runtime_id, or None if none is.

query_structure(runtime_id: ValueUUId) → TypeStructure | None

Return the struct registered under runtime_id, or None if none is.

query_type(runtime_id: ValueUUId) → Type | None

Return the type registered under runtime_id, or None if none is.

query_types(name: str) → list[Type]

Return every type whose name is name, across all namespaces.

runtime_ids() → set[ValueUUId]

Return the set of runtime ID for all registered types.

structure_runtime_ids() → set[ValueUUId]

Return the set of runtime ID for all structs.

structures() → list[TypeStructure]

Return the list of structs.

to_dsm_definitions() → DSMDefinitions

Convert and return a DSMDefinitions.

types() → list[Type]

Return the topologically sorted list of types.

write(stream_writing: StreamWriting) → None

Write to a stream.