serializers: Serializing bibliographic data

Stock serializers for Relaton bibliographic items.

bibxml: BibXML element tree

Abstracts

relaton.serializers.bibxml.abstracts.create_abstract(abstracts: List[GenericStringValue]) _Element[source]

Formats an <abstract> element.

Anchors

relaton.serializers.bibxml.anchor.get_suitable_anchor(item: BibliographicItem) str[source]

From a BibliographicItem instance get best anchor value and return it as a string.

Tries ANCHOR_FORMATTERS, and if none return a string then takes the first primary docid, (or the first docid with scope equal to “anchor”, or just the first docid).

Ensures the value matches XSID schema.

Parameters

item – a bib_models.bibdata.BibliographicItem instance

Returns str

a string to be used as anchor

Return type

str

Raises

ValueError – unable to obtain an anchor, e.g. item has no docids

relaton.serializers.bibxml.anchor.to_valid_xsid(val: str) str[source]

Transforms a string into a valid xs:id value. Transformation is lossy and irreversible.

relaton.serializers.bibxml.anchor.XSID_REGEX = re.compile('^[a-zA-Z_][-.\\w]*$')

A regular expression matching a full valid xs:id value.

relaton.serializers.bibxml.anchor.XSID_ILLEGAL = re.compile('[^-.\\w]')

A regular expression matching xs:id characters that are invalid anywhere within an xs:id string.

relaton.serializers.bibxml.anchor.ANCHOR_FORMATTERS: Tuple[Callable[[DocID], Optional[str]]] = (<function <lambda>>,)

Custom anchor formatters. Each function must take a relaton.models.bibdata.DocID instance and produce either an anchor string or None.

Authors

relaton.serializers.bibxml.authors.create_author(contributor: Contributor) _Element[source]
relaton.serializers.bibxml.authors.is_author(contrib)

Returns True if given Relaton contributor instance represents an author in xml2rfc domain.

relaton.serializers.bibxml.authors.AUTHOR_ROLES = {'author', 'editor', 'publisher'}

Relaton contributor role types that represent xml2rfc authors.

References

Series

relaton.serializers.bibxml.series.extract_doi_series(docid: DocID) Optional[Tuple[str, str]][source]
relaton.serializers.bibxml.series.extract_rfc_series(docid: DocID) Optional[Tuple[str, str]][source]
relaton.serializers.bibxml.series.extract_id_series(docid: DocID) Optional[Tuple[str, str]][source]
relaton.serializers.bibxml.series.extract_w3c_series(docid: DocID) Optional[Tuple[str, str]][source]
relaton.serializers.bibxml.series.extract_3gpp_tr_series(docid: DocID) Optional[Tuple[str, str]][source]
relaton.serializers.bibxml.series.extract_ieee_series(docid: DocID) Optional[Tuple[str, str]][source]
relaton.serializers.bibxml.series.DOCID_SERIES_EXTRACTORS = [...]

A list of functions capable of extracting series information as 2-tuple (series name, document number) from a DocID. Each function is expected to either return a tuple or None, and not throw.

Targets

relaton.serializers.bibxml.target.get_suitable_target(links: List[Link])[source]

From a list of Link instances, return a string suitable to be used as value of target attribute on root XML element.

It prefers a link with type set to “src”, if not present then first available link.

bibxml_string: BibXML string