Skip to content

comicbox.formats.metron_info.transform.identifier_attribute ยถ

Metron ID attributes to comicbox identifiers transform.

metron_id_attribute_from_cb(metron_obj, comicbox_obj, primary_id_source_str) ยถ

Crete a metron id attribute from comicbox identifier.

Source code in comicbox/formats/metron_info/transform/identifier_attribute.py
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
def metron_id_attribute_from_cb(
    metron_obj: dict, comicbox_obj: Mapping, primary_id_source_str: str
) -> None:
    """Crete a metron id attribute from comicbox identifier."""
    comicbox_identifiers = comicbox_obj.get(IDENTIFIERS_KEY)
    if not comicbox_identifiers:
        return
    for id_source_str, identifier in comicbox_identifiers.items():
        if (
            primary_id_source_str
            and id_source_str == primary_id_source_str
            and (id_key := identifier.get(ID_KEY_KEY))
        ):
            metron_obj[ID_ATTRIBUTE] = id_key
            break

metron_id_attribute_to_cb(id_type, metron_obj, comicbox_obj, id_source_str, *, implied=True) ยถ

Create a metron tag identifier from a metron identifier attribute.

The attribute names no type of its own, so id_type is the type the tag it hangs on means. Usually that tag IS the thing the id names, and the type is left implied. implied=False is for a tag that is a name rather than the thing: an AlternativeName is not a series, so nothing about where its id sits says the id names one, and the type has to be stated the way a top level id states a type that isnโ€™t an issue.

Source code in comicbox/formats/metron_info/transform/identifier_attribute.py
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
def metron_id_attribute_to_cb(
    id_type: str,
    metron_obj: Mapping | str,
    comicbox_obj: dict,
    id_source_str: str,
    *,
    implied: bool = True,
) -> None:
    """
    Create a metron tag identifier from a metron identifier attribute.

    The attribute names no type of its own, so ``id_type`` is the type the
    tag it hangs on means. Usually that tag IS the thing the id names, and
    the type is left implied. ``implied=False`` is for a tag that is a name
    rather than the thing: an AlternativeName is not a series, so nothing
    about where its id sits says the id names one, and the type has to be
    stated the way a top level id states a type that isn't an issue.
    """
    try:
        if not (
            isinstance(metron_obj, Mapping) and (id_key := metron_obj.get(ID_ATTRIBUTE))
        ):
            return
        comicbox_identifier = create_identifier(
            id_source_str,
            # Mapping.get is untyped here; metron @id attributes arrive as
            # str from xmltodict but int from API dicts โ€” coerce.
            str(id_key),
            id_type=id_type,
            positional_id_type=id_type if implied else DEFAULT_ID_TYPE,
            default_id_source_str=DEFAULT_ID_SOURCE_STR,
        )
        comicbox_obj[IDENTIFIERS_KEY] = {id_source_str: comicbox_identifier}
    except Exception as exc:
        logger.warning(f"Parsing metron tag identifier {id_type}:{metron_obj} - {exc}")