-
IdentifierTypes — URL slugs for identifier types.
-
IdentifierParts — Identifier url parser and unparser.
comicbox.identifiers.identifiers¶
source module comicbox.identifiers.identifiers
Identifiers functions.
Classes
Functions
-
normalize_key — Strip urn, source, and type prefixes off an id key.
-
get_identifier_url — Get a url for an identifier if we know the rest.
-
get_url_from_identifier — Get the url a whole identifier names, or none if it names no key.
-
create_identifier — Create identifier dict from parts.
-
get_id_source_from_url — Name the database a url belongs to, or “” for one comicbox doesn’t know.
source class IdentifierTypes()
URL slugs for identifier types.
Attributes
-
map : frozenbidict — Initialize reverse dict.
-
default_slug_type : str — Return the type to assume when a url names one we don’t know.
source property IdentifierTypes.map: frozenbidict
Initialize reverse dict.
source property IdentifierTypes.default_slug_type: str
Return the type to assume when a url names one we don’t know.
source class IdentifierParts()
Identifier url parser and unparser.
Methods
-
get_type_by_code — Get identifier type by url fragment or code.
-
parse_url_path — Parse URL path with regex, or return no match.
-
unparse_url — Create url from identifier parts.
source method IdentifierParts.get_type_by_code(id_type_code: str, default: str = DEFAULT_ID_TYPE) → str
Get identifier type by url fragment or code.
source method IdentifierParts.parse_url_path(url: str) → tuple[str, str]
Parse URL path with regex, or return no match.
source method IdentifierParts.unparse_url(id_type: str, id_key: str) → str
Create url from identifier parts.
source normalize_key(id_source_str: str, id_type: str, id_key: str) → tuple[str, str]
Strip urn, source, and type prefixes off an id key.
Hand-tagged keys often mirror the urn form comicbox writes to notes and GTIN (e.g. “series:178012”); a type prefix overrides the caller’s id_type. Prefixes naming a different source are left alone. Comicvine long codes (“4050-160294”) are normalized last.
source get_identifier_url(id_source_str: str, id_type: str, id_key: str) → str
Get a url for an identifier if we know the rest.
source get_url_from_identifier(id_source_str: str, identifier: Mapping[str, str] | None) → str
Get the url a whole identifier names, or none if it names no key.
An identifier stores only its key, and its type only when that type isn’t the implied one, so reading a url off one always means the same three steps. They live here so every caller takes them the same way.
source create_identifier(id_source_str: str, id_key: str, *, id_type: str = ‘’, positional_id_type: str = DEFAULT_ID_TYPE, default_id_source_str: str = DEFAULT_ID_SOURCE.value) → dict
Create identifier dict from parts.
id_type is the type the identifier string itself named, if any. positional_id_type is the type implied by where the identifier sits: an id under series is a series id. The type is stored only when the two disagree, because that is when it decides which url the key builds.
Only the key is stored. A url for it is derived on demand with get_identifier_url; keeping a synthesized copy inside the identifier let the two disagree and made a guessed url look like source data.
source get_id_source_from_url(url: str) → str
Name the database a url belongs to, or “” for one comicbox doesn’t know.
Matches every domain a source answers on, like comicvine.com or the ten amazon country domains, not just its canonical one.