@@ -171,7 +171,8 @@ def _parse_mrz(self, mrz_text, include_checkdigit=True):
171
171
172
172
mrz_code_dict ["issuer_code" ] = mrz_lines [0 ][2 :5 ]
173
173
if not mrz_code_dict ["issuer_code" ].isalpha ():
174
- return {"status" : "FAILURE" , "message" : "Invalid MRZ format" }
174
+ mrz_code_dict ["status" ] = "FAILURE"
175
+ mrz_code_dict ["status_message" ] = "Invalid MRZ format"
175
176
176
177
names = mrz_lines [0 ][5 :].split ("<<" )
177
178
mrz_code_dict ["surname" ] = names [0 ].replace ("<" , " " )
@@ -181,18 +182,21 @@ def _parse_mrz(self, mrz_text, include_checkdigit=True):
181
182
mrz_code_dict ["document_number" ] = mrz_lines [1 ][:9 ].replace ("<" , "" )
182
183
document_number_checkdigit = self ._get_checkdigit (mrz_code_dict ["document_number" ])
183
184
if document_number_checkdigit != mrz_lines [1 ][9 ]:
184
- return {"status" : "FAILURE" , "message" : "Document number checksum is not matching" }
185
+ mrz_code_dict ["status" ] = "FAILURE"
186
+ mrz_code_dict ["status_message" ] = "Document number checksum is not matching"
185
187
if include_checkdigit :
186
188
mrz_code_dict ["document_number_checkdigit" ] = document_number_checkdigit
187
189
188
190
mrz_code_dict ["nationality_code" ] = mrz_lines [1 ][10 :13 ]
189
191
if not mrz_code_dict ["nationality_code" ].isalpha ():
190
- return {"status" : "FAILURE" , "message" : "Invalid MRZ format" }
192
+ mrz_code_dict ["status" ] = "FAILURE"
193
+ mrz_code_dict ["status_message" ] = "Invalid MRZ format"
191
194
192
195
mrz_code_dict ["birth_date" ] = mrz_lines [1 ][13 :19 ]
193
196
birth_date_checkdigit = self ._get_checkdigit (mrz_code_dict ["birth_date" ])
194
197
if birth_date_checkdigit != mrz_lines [1 ][19 ]:
195
- return {"status" : "FAILURE" , "message" : "Date of birth checksum is not matching" }
198
+ mrz_code_dict ["status" ] = "FAILURE"
199
+ mrz_code_dict ["status_message" ] = "Date of birth checksum is not matching"
196
200
if include_checkdigit :
197
201
mrz_code_dict ["birth_date_checkdigit" ] = birth_date_checkdigit
198
202
mrz_code_dict ["birth_date" ] = self ._format_date (mrz_code_dict ["birth_date" ])
@@ -202,7 +206,8 @@ def _parse_mrz(self, mrz_text, include_checkdigit=True):
202
206
mrz_code_dict ["expiry_date" ] = mrz_lines [1 ][21 :27 ]
203
207
expiry_date_checkdigit = self ._get_checkdigit (mrz_code_dict ["expiry_date" ])
204
208
if expiry_date_checkdigit != mrz_lines [1 ][27 ]:
205
- return {"status" : "FAILURE" , "message" : "Date of expiry checksum is not matching" }
209
+ mrz_code_dict ["status" ] = "FAILURE"
210
+ mrz_code_dict ["status_message" ] = "Date of expiry checksum is not matching"
206
211
if include_checkdigit :
207
212
mrz_code_dict ["expiry_date_checkdigit" ] = expiry_date_checkdigit
208
213
mrz_code_dict ["expiry_date" ] = self ._format_date (mrz_code_dict ["expiry_date" ])
@@ -214,7 +219,8 @@ def _parse_mrz(self, mrz_text, include_checkdigit=True):
214
219
mrz_code_dict ["optional_data" ] = mrz_lines [1 ][28 :42 ].strip ("<" )
215
220
optional_data_checkdigit = self ._get_checkdigit (mrz_code_dict ["optional_data" ].strip ("<" ))
216
221
if optional_data_checkdigit != mrz_lines [1 ][42 ]:
217
- return {"status" : "FAILURE" , "message" : "Optional data checksum is not matching" }
222
+ mrz_code_dict ["status" ] = "FAILURE"
223
+ mrz_code_dict ["status_message" ] = "Optional data checksum is not matching"
218
224
if include_checkdigit :
219
225
mrz_code_dict ["optional_data_checkdigit" ] = optional_data_checkdigit
220
226
elif mrz_code_dict ["mrz_type" ] == "MRVA" :
@@ -225,7 +231,8 @@ def _parse_mrz(self, mrz_text, include_checkdigit=True):
225
231
final_checkdigit = self ._get_final_checkdigit (mrz_lines , mrz_code_dict ["mrz_type" ])
226
232
if (mrz_lines [1 ][- 1 ] != final_checkdigit
227
233
and mrz_code_dict ["mrz_type" ] not in ("MRVA" , "MRVB" )):
228
- return {"status" : "FAILURE" , "message" : "Final checksum is not matching" }
234
+ mrz_code_dict ["status" ] = "FAILURE"
235
+ mrz_code_dict ["status_message" ] = "Final checksum is not matching"
229
236
if include_checkdigit :
230
237
mrz_code_dict ["final_checkdigit" ] = final_checkdigit
231
238
else :
@@ -236,12 +243,14 @@ def _parse_mrz(self, mrz_text, include_checkdigit=True):
236
243
237
244
mrz_code_dict ["issuer_code" ] = mrz_lines [0 ][2 :5 ]
238
245
if not mrz_code_dict ["issuer_code" ].isalpha ():
239
- return {"status" : "FAILURE" , "message" : "Invalid MRZ format" }
246
+ mrz_code_dict ["status" ] = "FAILURE"
247
+ mrz_code_dict ["status_message" ] = "Invalid MRZ format"
240
248
241
249
mrz_code_dict ["document_number" ] = mrz_lines [0 ][5 :14 ]
242
250
document_number_checkdigit = self ._get_checkdigit (mrz_code_dict ["document_number" ])
243
251
if document_number_checkdigit != mrz_lines [0 ][14 ]:
244
- return {"status" : "FAILURE" , "message" : "Document number checksum is not matching" }
252
+ mrz_code_dict ["status" ] = "FAILURE"
253
+ mrz_code_dict ["status_message" ] = "Document number checksum is not matching"
245
254
if include_checkdigit :
246
255
mrz_code_dict ["document_number_checkdigit" ] = document_number_checkdigit
247
256
@@ -251,7 +260,8 @@ def _parse_mrz(self, mrz_text, include_checkdigit=True):
251
260
mrz_code_dict ["birth_date" ] = mrz_lines [1 ][:6 ]
252
261
birth_date_checkdigit = self ._get_checkdigit (mrz_code_dict ["birth_date" ])
253
262
if birth_date_checkdigit != mrz_lines [1 ][6 ]:
254
- return {"status" : "FAILURE" , "message" : "Date of birth checksum is not matching" }
263
+ mrz_code_dict ["status" ] = "FAILURE"
264
+ mrz_code_dict ["status_message" ] = "Date of birth checksum is not matching"
255
265
if include_checkdigit :
256
266
mrz_code_dict ["birth_date_checkdigit" ] = birth_date_checkdigit
257
267
mrz_code_dict ["birth_date" ] = self ._format_date (mrz_code_dict ["birth_date" ])
@@ -261,7 +271,8 @@ def _parse_mrz(self, mrz_text, include_checkdigit=True):
261
271
mrz_code_dict ["expiry_date" ] = mrz_lines [1 ][8 :14 ]
262
272
expiry_date_checkdigit = self ._get_checkdigit (mrz_code_dict ["expiry_date" ])
263
273
if expiry_date_checkdigit != mrz_lines [1 ][14 ]:
264
- return {"status" : "FAILURE" , "message" : "Date of expiry checksum is not matching" }
274
+ mrz_code_dict ["status" ] = "FAILURE"
275
+ mrz_code_dict ["status_message" ] = "Date of expiry checksum is not matching"
265
276
if include_checkdigit :
266
277
mrz_code_dict ["expiry_date_checkdigit" ] = expiry_date_checkdigit
267
278
mrz_code_dict ["expiry_date" ] = self ._format_date (mrz_code_dict ["expiry_date" ])
@@ -270,12 +281,14 @@ def _parse_mrz(self, mrz_text, include_checkdigit=True):
270
281
271
282
mrz_code_dict ["nationality_code" ] = mrz_lines [1 ][15 :18 ]
272
283
if not mrz_code_dict ["nationality_code" ].isalpha ():
273
- return {"status" : "FAILURE" , "message" : "Invalid MRZ format" }
284
+ mrz_code_dict ["status" ] = "FAILURE"
285
+ mrz_code_dict ["status_message" ] = "Invalid MRZ format"
274
286
275
287
mrz_code_dict ["optional_data_2" ] = mrz_lines [0 ][18 :29 ].strip ("<" )
276
288
final_checkdigit = self ._get_final_checkdigit (mrz_lines , mrz_code_dict ["mrz_type" ])
277
289
if mrz_lines [1 ][- 1 ] != final_checkdigit :
278
- return {"status" : "FAILURE" , "message" : "Final checksum is not matching" }
290
+ mrz_code_dict ["status" ] = "FAILURE"
291
+ mrz_code_dict ["status_message" ] = "Final checksum is not matching"
279
292
if include_checkdigit :
280
293
mrz_code_dict ["final_checkdigit" ] = final_checkdigit
281
294
@@ -287,7 +300,8 @@ def _parse_mrz(self, mrz_text, include_checkdigit=True):
287
300
mrz_code_dict ["mrz_text" ] = mrz_text
288
301
289
302
# Final status
290
- mrz_code_dict ["status" ] = "SUCCESS"
303
+ if mrz_code_dict .get ("status" ) != "FAILURE" :
304
+ mrz_code_dict ["status" ] = "SUCCESS"
291
305
292
306
return mrz_code_dict
293
307
0 commit comments