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

Code not executed after checker returns False #17

Closed
xxxpsyduck opened this issue Mar 18, 2020 · 4 comments
Closed

Code not executed after checker returns False #17

xxxpsyduck opened this issue Mar 18, 2020 · 4 comments

Comments

@xxxpsyduck
Copy link

xxxpsyduck commented Mar 18, 2020

Hello I have a code block like this:

...
checker1 = TD3CodeChecker(...)

if bool(checker1) == True:
    ...
else:
   ...

The problem is when checker1 does not return True then all the lines below it won't run (the else statement never triggered).

@Arg0s1080
Copy link
Owner

Hi

I don't know if I understood you, but it works fine for me.

An example:

from mrz.checker.td3 import TD3CodeChecker

# This MRZ code should return True 
mrz_td3 = ("P<CANMARTIN<<SARAH<<<<<<<<<<<<<<<<<<<<<<<<<<\n"
           "ZE000509<9CAN8501019F2301147<<<<<<<<<<<<<<08")

check1 = TD3CodeChecker(mrz_td3)

if bool(check1):
    print("check1 it's True")
else:
    print("check1 it's False")


# Now let's introduce some errors:
mrz_td3 = ("BDBADMARTIN<<SARAH<<<<<<<<<BAD<<<<BAD<<<<<<<\n"
           "ZE000509<1CAN8501019F2301147<<<<<<<<<<<<<<11")

check2 = TD3CodeChecker(mrz_td3)

if bool(check2) == True:
    print("check2 it's True")
else:
    print("check2 it's False")

Output:

check1 it's True
check2 it's False

Maybe if you showed the complete code we could see where is the error.

Regards!

@xxxpsyduck
Copy link
Author

xxxpsyduck commented Mar 19, 2020

I have error with the following code:

from mrz.checker.td3 import TD3CodeChecker

mrz_td3 = ("8053333LX2E7EZ90X2908022W6L0LL889SI95326S<2SL<\n"
           "333333333333333333233D13NVL13NX35ONV0317O19SI54")

check2 = TD3CodeChecker(mrz_td3)

if bool(check2) == True:
    print("check2 it's True")
else:
    print("check2 it's False")`

mrz_td3 = ("P<CANMARTIN<<SARAH<<<<<<<<<<<<<<<<<<<<<<<<<<\n"
           "ZE000509<9CAN8501019F2301147<<<<<<<<<<<<<<08")

check1 = TD3CodeChecker(mrz_td3)

if bool(check1):
    print("check1 it's True")
else:
    print("check1 it's False")

Output:

raise LengthError(cause=len(s), document=document_description, length=length) mrz.base.errors.LengthError: ('String was not recognized as a valid TD3. It should have 88 characters', '93')

@xxxpsyduck
Copy link
Author

xxxpsyduck commented Mar 19, 2020

@Arg0s1080 I modified your code to bypass all the exceptions. Btw there are some mistake in base/string_checkers.py, there is no name 's' defined in precheck() function

def precheck(document_description: str, string: str, length: int):
    if check_string(_check_upper(string)) and len(string) != length:
        raise LengthError(cause=len(s), document=document_description, length=length)
    if not is_printable(string, "\n"):
        raise FieldError("%s contains invalid characters" % document_description, s)

@Arg0s1080
Copy link
Owner

Hi again!

In the output you can see what the error is. Your mrz string has 93 chars. MRZ code of all TD3 must be 88 chars long (89 if escape character is counted)

So, as I see it, everything works fine.

Regards

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants