Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Two letter country code #32

Open
GrofGraf opened this issue Dec 16, 2020 · 6 comments
Open

Two letter country code #32

GrofGraf opened this issue Dec 16, 2020 · 6 comments
Assignees
Labels
CHECKER MRZ.CHECKER Issues enhancement New feature or request GENERATOR MRZ.GENERATOR Issues pending Something is pending verification

Comments

@GrofGraf
Copy link

I believe, there is an error in TD1CodeChecker, atlest for some IDs.

Two letter country codes and nationality codes do not pass the check, while three letter country codes do.

There should also be a possibility of two letter country codes added to check, because some IDs have two letter country and nationality code.

@Arg0s1080
Copy link
Owner

Hi!

I don't know if I understand you..

IIf I remember correctly, all countries codes have 3 letters with two exceptions: United Kingdom "GB" and Germany "D" and both work correctly

For example:

from mrz.checker.td1 import TD1CodeChecker

print(TD1CodeChecker("ID<GB0000000000000000000<<<<<<\n"
                     "8001014F2501017<GB<<<<<<<<<<<4\n"
                     "SAMPLE<SAMPLE<<SAMPLE<SAMPLE<<"))

print(TD1CodeChecker("ID<<D0000000000000000000<<<<<<\n"
                     "8001014F2501017<<D<<<<<<<<<<<4\n"
                     "SAMPLE<SAMPLE<<SAMPLE<SAMPLE<<"))

Output

True
True

Can you give an example?

Thanks

@GrofGraf
Copy link
Author

GrofGraf commented Dec 18, 2020

Thank you for a quick response. I get an error with Slovenian ID, that has a two letter country code SI. Slovenian passports work as expected as they have three letter country code SVN.

Slovenian ID

@Arg0s1080
Copy link
Owner

Sorry.. I read your message days ago but i forgot to reply to you.

I was planning to give you the standard answer. "ICAO specifications says": All countries use 3-letter codes, so "this is outside the scope of the project. Therefore it's a special case" and then I would quote specs.

But reviewing the specs i read:

The following are the two- and three-letter codes for entities specified and regularly updated in [ISO 3166-1], with
extensions for certain States and organizations being identified by an asterisk. The current version of the codes may be
obtained from the [ISO 3166] maintenance agency - [ISO 3166/MA], ISO’s focal point for country codes.

Specs are specs, so it's within the scope of this project.

The good news is that I envisioned something for something similar to your request:

def country(string, dictionary=countries.english):
    if check_string(string) and string.upper() in dictionary.values():
        return string.upper().ljust(3, "<")
    elif full_capitalize(string) in dictionary.keys():
        return dictionary[full_capitalize(string)].ljust(3, "<")
    else:
        raise CountryError(cause=string)

(See dictionary kwarg)

Bad news is that I now have very little free time. However, all this it's pending.

As this is something that requires a lot of changes, I promise to provide a temporary special case in a few days (a special case for Slovenian TD1s)

BR

@Arg0s1080 Arg0s1080 self-assigned this Dec 23, 2020
@Arg0s1080 Arg0s1080 added CHECKER MRZ.CHECKER Issues enhancement New feature or request GENERATOR MRZ.GENERATOR Issues pending Something is pending verification labels Dec 23, 2020
@GrofGraf
Copy link
Author

Thank you for the response,
Take your time when you can, I will make a workaround based on your response in the meanwhile.

Thanks again for supporting this project and keep up the good work.

Best regards.

@mjl
Copy link

mjl commented Apr 20, 2021

I just stumbled over the same issue (on the checker side).

The quick and dirty fix is to add

"Slovenia2": "SI",

to base/countries.py.

However, this might be a bit of a moving target, so I'd suggest to ultimatively not flag unrecognised countries as errors at all but to just pass them through. Or perhaps add a verify_country=True to the checker to disable the country check if you don't really need it?

@mjl
Copy link

mjl commented Apr 20, 2021

The even easier quick hack is to add

# Patch up MRZ module for special cases
from mrz.base.countries import english

english["Slovenia2"] = "SI"

to you application, that way one doesn't have to touch the original mrz distribution files.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
CHECKER MRZ.CHECKER Issues enhancement New feature or request GENERATOR MRZ.GENERATOR Issues pending Something is pending verification
Projects
None yet
Development

No branches or pull requests

3 participants