Source code for cadrumo.domain.calculations.registry.source_byte_availability
"""Which catalogued official sources carry their bytes inside a published authority.A published authority embeds the bytes of a source reference only when a runtimeworkflow interprets those bytes: the XML dictionary that maps casillas to elementpaths, and the XSD that fixes the declared schema version. Every other sourcekind - record designs, form specifications, instructions, manuals, suppressionnotices - is a citation. Its identifier, kind, digest and byte count travel inthe catalogue and into every observation, review row and explanation that citesit, but its bytes are not part of the generation, because the fixed-width layoutalready carries the compiled offsets, widths and order the design fixes.The publisher selects the embedded set from this module, the artifact closurecheck requires exactly that set, and runtime readers request bytes only for thereferences this module declares embedded. A reader therefore never asks for apayload the generation cannot hold, and a genuinely required dictionary or XSDpayload that is missing still refuses at the fetch."""from__future__importannotationsfromcollections.abcimportIterable,MappingfromtypingimportFinalfrom....core.export_layout_formatimportExportLayoutFormatfrom.errorsimportRegistryValidationErrorfrom.schema_baseimportRegistrySourceKindfrom.schema_exportsimportExportLayoutDefinitionfrom.schema_referencesimportSourceReference__all__=["EMBEDDED_SOURCE_KINDS","embedded_source_ids","layout_embedded_source_ids","source_bytes_are_embedded",]EMBEDDED_SOURCE_KINDS:Final[frozenset[RegistrySourceKind]]=frozenset({RegistrySourceKind.DICTIONARY,RegistrySourceKind.XSD},)"""Source kinds whose bytes a published authority generation embeds."""
[docs]defsource_bytes_are_embedded(source:SourceReference)->bool:"""Report whether a published generation embeds the bytes of ``source``."""returnsource.kindinEMBEDDED_SOURCE_KINDS
[docs]defembedded_source_ids(sources:Mapping[str,SourceReference])->frozenset[str]:"""Return the identifiers in ``sources`` whose bytes a generation embeds."""returnfrozenset(str(source_id)forsource_id,sourceinsources.items()ifsource_bytes_are_embedded(source))
[docs]deflayout_embedded_source_ids(layouts:Iterable[ExportLayoutDefinition],*,sources:Mapping[str,SourceReference],)->frozenset[str]:"""Return the embedded source identifiers a set of export layouts may read. Every layout source reference must resolve in ``sources``; an unresolved reference is a registry defect, not a citation to skip. An XML dictionary layout must name a dictionary source whose kind is embedded, because its parser cannot run without those bytes. Raises: RegistryValidationError: A layout cites a source absent from ``sources``, or an XML dictionary layout's dictionary source is missing or is not an embedded kind. """selected:set[str]=set()forlayoutinlayouts:forsource_idinlayout.source_refs:source=sources.get(str(source_id))ifsourceisNone:raiseRegistryValidationError(f"export layout {layout.id!r} cites source {source_id!r} absent from the snapshot catalogue",)ifsource_bytes_are_embedded(source):selected.add(str(source_id))iflayout.formatisExportLayoutFormat.XML_DICTIONARY:_require_embedded_dictionary(layout,sources=sources)returnfrozenset(selected)
def_require_embedded_dictionary(layout:ExportLayoutDefinition,*,sources:Mapping[str,SourceReference],)->None:dictionary_ref=layout.dictionary_source_refdictionary=Noneifdictionary_refisNoneelsesources.get(str(dictionary_ref))ifdictionaryisNone:raiseRegistryValidationError(f"XML export layout {layout.id!r} has unresolved dictionary source {dictionary_ref!r}",)ifnotsource_bytes_are_embedded(dictionary):raiseRegistryValidationError(f"XML export layout {layout.id!r} dictionary source {dictionary.id!r} has kind "f"{dictionary.kind.value!r}, whose bytes a published authority does not embed",)