Repository navigation
Add MetronInfo v1.2 schema support - #265
Merged
Merged
Conversation
Replace the bundled v1.1 schema with the stable v1.2 release and rename SchemaVersion.METRON_INFO_V1_1 to METRON_INFO_V1_2. v1.2 is a strict superset of v1.1, so v1.1 could never be the winning match in the newest-first validation order. Written MetronInfo now declares the v1.2 namespace and schemaLocation. Add end_year, status and summary to Series, read from and written to the new Series EndYear, Status and Summary elements. Status is matched case-insensitively and unknown values are dropped. An EndYear that the schema's assertions would reject (before StartYear, or on an Ongoing series) is omitted, so the write doesn't fail validation. Accept BCP 47 language tags (e.g. pt-BR, zh-Hant) in the Series and AlternativeNames language validators, which now share one implementation. This also fixes an AttributeError for languages without an ISO 639-1 code (e.g. fil, yue), which previously crashed when reading a MetronInfo AlternativeName that used one. Such languages now normalize to their ISO 639-3 code.
…rsion.METRON_INFO_V1_2. Since v1.2 is a superset of v1.1, v1.1 is validated first so documents report the oldest version they conform to. Written MetronInfo now declares the v1.2 namespace and schemaLocation.
Look up the whole value as a language code or name before parsing it as a tag. Hyphenated language names now resolve (Ai-Cham -> aih) instead of being split into a primary subtag and bogus subtags (Na-Dene -> na-Dene). Codes are checked before name lookup, since pycountry's lookup() can match a language name equal to another language's code ("En").
Resolve the primary subtag from its ISO 639-1, ISO 639-3 or ISO 639-2/B code whether or not subtags follow, so ger-DE, fre-CA and chi-Hant are accepted like ger, fre and chi.
Parse subtags with BCP 47 rules: an optional script, an optional region and any variants, in that order. Scripts and alphabetic regions must be known ISO 15924 and ISO 3166-1 codes, and each subtag is normalized to its canonical case (pt-br -> pt-BR, zh-hant-tw -> zh-Hant-TW). Extended language, extension and private use subtags are rejected.
Add MetronInfo._match_mapping and use it for series format, series status and ComicRack age ratings, replacing three copies of the same strip/lower/lookup code. Series status now uses a STATUS_MAPPINGS table like FORMAT_MAPPINGS and RATING_MAPPINGS. ComicRack age ratings are now stripped of surrounding whitespace before matching, like format and status already were.
Give Series.validate_end_year its own docstring and error message instead of aliasing validate_start_year, sharing a _validate_year helper. Year errors now name the field ("End year: 99 length must be 4").
Series now rejects an end year that precedes its start year at construction. The MetronInfo writer keeps its EndYear guard, since fields can be set after construction, a volume may be written as the StartYear, and the Ongoing rule depends on the normalized status.
Run the series language (ComicInfo LanguageISO and MetronInfo Series lang) and MetronInfo AlternativeName languages through validate_language_tag when reading, via a new BaseMetadataHandler._parse_language helper. Series languages were previously stored as read, so pt-br stayed pt-br while alternative names were normalized. An unknown language is now logged and dropped instead of raising. Previously, an AlternativeName with an unknown lang failed the whole MetronInfo read with ValueError.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Updates darkseid for the stable MetronInfo v1.2 schema.
SchemaVersion.METRON_INFO_V1_2. Written files now declare the v1.2 namespace andschemaLocation.Seriesgainsend_year,statusandsummary, mapped to the newEndYear,StatusandSummaryelements.SeriesandAlternativeNameslanguage validators now accept BCP 47 tags such aspt-BR,filandzh-Hant, and normalize them to canonical form.Compatibility
SchemaVersion.METRON_INFO_V1_1is unchanged, and v1.1 files are still reported asMETRON_INFO_V1_1. The enum gains a new member, sovalidate_all()now returns one more entry.Details
Schema detection. The MetronInfo schemas have no target namespace, and v1.2 accepts every v1.1 document.
ValidateMetadatatherefore checks v1.1 before v1.2, so a document reports the oldest version it conforms to. A document reportsMETRON_INFO_V1_2only when it uses v1.2 features (EndYear,Status,Summaryor a BCP 47 language tag).Writing Series status and end year.
Statusis matched case-insensitively, so"hiatus"is written asHiatus. Unknown values are dropped, the same wayFormatis handled. v1.2 adds two schema assertions:EndYearcan't precedeStartYear, and anOngoingseries can't have anEndYear. Every MetronInfo write is validated against the schema, so anEndYearthat would break either rule is left out instead of failing the write. When a volume is written as theStartYear, that value is the one compared againstEndYear.Language tags. The two validators now share one function,
validate_language_tag:"English","ger"and hyphenated names like"Ai-Cham"resolve.ger-DE→de-DE). It's reduced to the 2-letter code where one exists, and the 3-letter code otherwise.pt-br→pt-BR,zh-hant-tw→zh-Hant-TW).zh-min-nan,en-US-x-foo) are rejected.Language values read from existing files go through the same validator, so a file containing
pt-bris written back aspt-BR.Bug fix. Previously, a language with no 2-letter code (such as
filoryue) raisedAttributeError: alpha_2instead of being accepted or rejected cleanly. Because the reader runs this validator forAlternativeNameelements, reading a MetronInfo file with<AlternativeName lang="fil">crashed.Display.
str(Metadata)shows the series year range, for example[1970-1975].ComicInfo has no equivalent for the new Series fields, so they're only stored in MetronInfo.
Tests
EndYearis left out and the file still writesValidateMetadatareports v1.1 for v1.1-compatible documents, reports v1.2 for documents using v1.2 features, and rejects documents that break the new rules