Taric

Parsers for TARIC envelope entities.

exception importer.taric.EnvelopeError[source]
class importer.taric.EnvelopeParser(workbasket_id: str, workbasket_status=None, partition_scheme: Optional[workbaskets.models.TransactionPartitionScheme] = None, tamato_username=None, record_group: Optional[Sequence[str]] = None, save: bool = True, **kwargs)[source]
start(element: xml.etree.ElementTree.Element, parent: Optional[importer.parsers.ElementParser] = None)[source]

Handle the start of an XML tag. The tag may not yet have all of its children.

We have a few cases where there are tags nested within a tag of the same name.

Example:

<oub:additional.code>
    <oub:additional.code.sid>00000001</oub:additional.code.sid>
    <oub:additional.code.type.id>A</oub:additional.code.type.id>
    <oub:additional.code>AAA</oub:additional.code>
    <oub:validity.start.date>2021-01-01</oub:validity.start.date>
</oub:additional.code>

In this case matching on tags is not enough and so we also need to keep track of whether this parser is already parsing an element. If it is, we don’t want to select any child parsers. If it is not, we know that this is an element that this parser should be parsing.

class importer.taric.MessageParser(tag: Optional[importer.namespaces.Tag] = None, many: bool = False, depth: int = 1)[source]

Parser for TARIC3 message element.

save(data: Mapping[str, Any], transaction_id: int)[source]

Save the contained records to the database.

Parameters
  • data – A dict of parsed element, mapping field names to values

  • transaction_id – The primary key of the transaction to add records to

class importer.taric.RecordParser(tag: Optional[importer.namespaces.Tag] = None, many: bool = False, depth: int = 1)[source]

Parser for TARIC3 record element.

save(data: Mapping[str, Any], transaction_id: int)[source]

Save the Record to the database.

Parameters
  • data – A dict of the parsed element, mapping field names to values

  • transaction_id – The primary key of the transaction to add the record to

class importer.taric.TransactionParser(tag: Optional[importer.namespaces.Tag] = None, many: bool = False, depth: int = 1)[source]

Parser for TARIC3 transaction element.

save(data: Mapping[str, Any], envelope: taric.models.Envelope)[source]

Save the transaction and the contained records to the database.

Parameters
  • data – A dict of the parsed element, containing at least an “id” and list of “message” dicts

  • envelope – Containing Envelope

importer.taric.process_taric_xml_stream(taric_stream, workbasket_id, workbasket_status, partition_scheme, username, record_group: Sequence[str] = None)[source]

Parse a TARIC XML stream through the import handlers.

This will load the data from the stream into the database. This runs inside a single database transaction so that if any of the data is invalid, it will not be committed and the XML can be fixed and imported again without needing to remove the existing data.