blitzid 0.3.3__tar.gz → 0.3.4__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- {blitzid-0.3.3 → blitzid-0.3.4}/CHANGELOG.md +31 -0
- {blitzid-0.3.3 → blitzid-0.3.4}/PKG-INFO +1 -1
- {blitzid-0.3.3 → blitzid-0.3.4}/docs/coding-standard.md +1 -1
- {blitzid-0.3.3 → blitzid-0.3.4}/pyproject.toml +1 -1
- {blitzid-0.3.3 → blitzid-0.3.4}/src/blitzid/api/_analyze.py +1 -1
- {blitzid-0.3.3 → blitzid-0.3.4}/src/blitzid/reading/barcode.py +56 -15
- {blitzid-0.3.3 → blitzid-0.3.4}/tests/test_barcode.py +88 -6
- {blitzid-0.3.3 → blitzid-0.3.4}/uv.lock +1 -1
- {blitzid-0.3.3 → blitzid-0.3.4}/.dockerignore +0 -0
- {blitzid-0.3.3 → blitzid-0.3.4}/.env.example +0 -0
- {blitzid-0.3.3 → blitzid-0.3.4}/.github/workflows/ci.yml +0 -0
- {blitzid-0.3.3 → blitzid-0.3.4}/.github/workflows/docker.yml +0 -0
- {blitzid-0.3.3 → blitzid-0.3.4}/.github/workflows/publish.yml +0 -0
- {blitzid-0.3.3 → blitzid-0.3.4}/.gitignore +0 -0
- {blitzid-0.3.3 → blitzid-0.3.4}/.pre-commit-config.yaml +0 -0
- {blitzid-0.3.3 → blitzid-0.3.4}/CONTRIBUTING.md +0 -0
- {blitzid-0.3.3 → blitzid-0.3.4}/Dockerfile +0 -0
- {blitzid-0.3.3 → blitzid-0.3.4}/LICENSE +0 -0
- {blitzid-0.3.3 → blitzid-0.3.4}/README.md +0 -0
- {blitzid-0.3.3 → blitzid-0.3.4}/docker-compose.dev.yml +0 -0
- {blitzid-0.3.3 → blitzid-0.3.4}/docker-compose.gpu.yml +0 -0
- {blitzid-0.3.3 → blitzid-0.3.4}/docker-compose.yml +0 -0
- {blitzid-0.3.3 → blitzid-0.3.4}/docs/integration.md +0 -0
- {blitzid-0.3.3 → blitzid-0.3.4}/images/README.md +0 -0
- {blitzid-0.3.3 → blitzid-0.3.4}/images/bub_der_personalausweis_kopie.jpg +0 -0
- {blitzid-0.3.3 → blitzid-0.3.4}/images/nl_td1_id_specimen.jpg +0 -0
- {blitzid-0.3.3 → blitzid-0.3.4}/images/ny_license_plate_wrap.jpg +0 -0
- {blitzid-0.3.3 → blitzid-0.3.4}/images/nys_driver_license_sample.webp +0 -0
- {blitzid-0.3.3 → blitzid-0.3.4}/images/solvay_conference_1927.jpg +0 -0
- {blitzid-0.3.3 → blitzid-0.3.4}/images/td3_passport_specimen.jpg +0 -0
- {blitzid-0.3.3 → blitzid-0.3.4}/images/tlc_driver_license_sample.png +0 -0
- {blitzid-0.3.3 → blitzid-0.3.4}/models/.gitkeep +0 -0
- {blitzid-0.3.3 → blitzid-0.3.4}/models/README.md +0 -0
- {blitzid-0.3.3 → blitzid-0.3.4}/scripts/README.md +0 -0
- {blitzid-0.3.3 → blitzid-0.3.4}/scripts/api_smoke.py +0 -0
- {blitzid-0.3.3 → blitzid-0.3.4}/scripts/benchmark.py +0 -0
- {blitzid-0.3.3 → blitzid-0.3.4}/scripts/demo_cli.py +0 -0
- {blitzid-0.3.3 → blitzid-0.3.4}/scripts/download_models.py +0 -0
- {blitzid-0.3.3 → blitzid-0.3.4}/scripts/face_detector_demo.py +0 -0
- {blitzid-0.3.3 → blitzid-0.3.4}/scripts/midv500.py +0 -0
- {blitzid-0.3.3 → blitzid-0.3.4}/scripts/ocr_demo.py +0 -0
- {blitzid-0.3.3 → blitzid-0.3.4}/scripts/structurize_smoke.py +0 -0
- {blitzid-0.3.3 → blitzid-0.3.4}/scripts/verify_smoke.py +0 -0
- {blitzid-0.3.3 → blitzid-0.3.4}/src/blitzid/__init__.py +0 -0
- {blitzid-0.3.3 → blitzid-0.3.4}/src/blitzid/_dates.py +0 -0
- {blitzid-0.3.3 → blitzid-0.3.4}/src/blitzid/_image.py +0 -0
- {blitzid-0.3.3 → blitzid-0.3.4}/src/blitzid/_models.py +0 -0
- {blitzid-0.3.3 → blitzid-0.3.4}/src/blitzid/api/__init__.py +0 -0
- {blitzid-0.3.3 → blitzid-0.3.4}/src/blitzid/api/_app.py +0 -0
- {blitzid-0.3.3 → blitzid-0.3.4}/src/blitzid/api/_jobs.py +0 -0
- {blitzid-0.3.3 → blitzid-0.3.4}/src/blitzid/api/_liveness.py +0 -0
- {blitzid-0.3.3 → blitzid-0.3.4}/src/blitzid/api/_schemas.py +0 -0
- {blitzid-0.3.3 → blitzid-0.3.4}/src/blitzid/api/_upload.py +0 -0
- {blitzid-0.3.3 → blitzid-0.3.4}/src/blitzid/exceptions.py +0 -0
- {blitzid-0.3.3 → blitzid-0.3.4}/src/blitzid/face/__init__.py +0 -0
- {blitzid-0.3.3 → blitzid-0.3.4}/src/blitzid/face/_antispoof.py +0 -0
- {blitzid-0.3.3 → blitzid-0.3.4}/src/blitzid/face/_arcface.py +0 -0
- {blitzid-0.3.3 → blitzid-0.3.4}/src/blitzid/face/_attributes.py +0 -0
- {blitzid-0.3.3 → blitzid-0.3.4}/src/blitzid/face/_face.py +0 -0
- {blitzid-0.3.3 → blitzid-0.3.4}/src/blitzid/face/_motion.py +0 -0
- {blitzid-0.3.3 → blitzid-0.3.4}/src/blitzid/face/_scrfd.py +0 -0
- {blitzid-0.3.3 → blitzid-0.3.4}/src/blitzid/face/detector.py +0 -0
- {blitzid-0.3.3 → blitzid-0.3.4}/src/blitzid/face/verifier.py +0 -0
- {blitzid-0.3.3 → blitzid-0.3.4}/src/blitzid/py.typed +0 -0
- {blitzid-0.3.3 → blitzid-0.3.4}/src/blitzid/reading/__init__.py +0 -0
- {blitzid-0.3.3 → blitzid-0.3.4}/src/blitzid/reading/_observability.py +0 -0
- {blitzid-0.3.3 → blitzid-0.3.4}/src/blitzid/reading/consistency.py +0 -0
- {blitzid-0.3.3 → blitzid-0.3.4}/src/blitzid/reading/document.py +0 -0
- {blitzid-0.3.3 → blitzid-0.3.4}/src/blitzid/reading/mrz.py +0 -0
- {blitzid-0.3.3 → blitzid-0.3.4}/src/blitzid/reading/ocr.py +0 -0
- {blitzid-0.3.3 → blitzid-0.3.4}/src/blitzid/reading/structurize.py +0 -0
- {blitzid-0.3.3 → blitzid-0.3.4}/tests/conftest.py +0 -0
- {blitzid-0.3.3 → blitzid-0.3.4}/tests/test_antispoof.py +0 -0
- {blitzid-0.3.3 → blitzid-0.3.4}/tests/test_api.py +0 -0
- {blitzid-0.3.3 → blitzid-0.3.4}/tests/test_attributes.py +0 -0
- {blitzid-0.3.3 → blitzid-0.3.4}/tests/test_consistency.py +0 -0
- {blitzid-0.3.3 → blitzid-0.3.4}/tests/test_detector.py +0 -0
- {blitzid-0.3.3 → blitzid-0.3.4}/tests/test_detector_helpers.py +0 -0
- {blitzid-0.3.3 → blitzid-0.3.4}/tests/test_document.py +0 -0
- {blitzid-0.3.3 → blitzid-0.3.4}/tests/test_exceptions.py +0 -0
- {blitzid-0.3.3 → blitzid-0.3.4}/tests/test_image.py +0 -0
- {blitzid-0.3.3 → blitzid-0.3.4}/tests/test_models.py +0 -0
- {blitzid-0.3.3 → blitzid-0.3.4}/tests/test_motion.py +0 -0
- {blitzid-0.3.3 → blitzid-0.3.4}/tests/test_mrz.py +0 -0
- {blitzid-0.3.3 → blitzid-0.3.4}/tests/test_ocr.py +0 -0
- {blitzid-0.3.3 → blitzid-0.3.4}/tests/test_refactored.py +0 -0
- {blitzid-0.3.3 → blitzid-0.3.4}/tests/test_structurize.py +0 -0
- {blitzid-0.3.3 → blitzid-0.3.4}/tests/test_verifier.py +0 -0
|
@@ -4,6 +4,37 @@ All notable changes to this project will be documented in this file.
|
|
|
4
4
|
|
|
5
5
|
## [Unreleased]
|
|
6
6
|
|
|
7
|
+
## [0.3.4] - 2026-10-06
|
|
8
|
+
|
|
9
|
+
### Fixed
|
|
10
|
+
|
|
11
|
+
- `BarcodeReader.read` failed the whole read on the first
|
|
12
|
+
AAMVA-looking barcode in the image: a corrupt or truncated
|
|
13
|
+
candidate next to a valid PDF417 raised `BarcodeError` instead of
|
|
14
|
+
falling through. Every decoded barcode is now tried and the first
|
|
15
|
+
payload that parses wins; a candidate's validation error is only
|
|
16
|
+
raised when nothing else parses.
|
|
17
|
+
- A non-standard `DBC` sex code (anything outside 1/2/9) aborted the
|
|
18
|
+
whole record. It now maps to `X` (unspecified) with the raw code
|
|
19
|
+
preserved in `extra_tags`; a missing `DBC` is still a hard error.
|
|
20
|
+
- Subfile directory entries with a zero-length region passed
|
|
21
|
+
validation through an off-by-one on the segment-terminator check,
|
|
22
|
+
and non-letter designators were accepted. Lengths below the
|
|
23
|
+
designator + terminator minimum and non-letter designators are now
|
|
24
|
+
rejected.
|
|
25
|
+
|
|
26
|
+
## [0.3.3] - 2026-10-06
|
|
27
|
+
|
|
28
|
+
### Fixed
|
|
29
|
+
|
|
30
|
+
- The `structured` engine failed to build in the v0.3.2 image (and
|
|
31
|
+
any fresh install of the `ocr` extra): `opentelemetry-api` 1.44+
|
|
32
|
+
removed the private `._events` module that `pydantic-ai` 0.8.1 still
|
|
33
|
+
imports, so `import pydantic_ai` raised `ModuleNotFoundError` and
|
|
34
|
+
`/health` reported `structured: false` even with `BLITZID_LLM_*`
|
|
35
|
+
configured. `opentelemetry-api` is now pinned `<1.44` in the `ocr`
|
|
36
|
+
extra until pydantic-ai catches up.
|
|
37
|
+
|
|
7
38
|
## [0.3.2] - 2026-10-06
|
|
8
39
|
|
|
9
40
|
### Added
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.5
|
|
2
2
|
Name: blitzid
|
|
3
|
-
Version: 0.3.
|
|
3
|
+
Version: 0.3.4
|
|
4
4
|
Summary: Modular DNN-based ID document reading framework (face detection, OCR, MRZ) optimized for CPU deployment
|
|
5
5
|
Project-URL: Homepage, https://github.com/malvavisc0/blitzid
|
|
6
6
|
Project-URL: Repository, https://github.com/malvavisc0/blitzid
|
|
@@ -4,7 +4,7 @@
|
|
|
4
4
|
You are talking to seniors. Be terse — no preamble, no recap, no
|
|
5
5
|
hand-holding, no "here's what I did" summaries. State results, not
|
|
6
6
|
intentions. Skip explanations unless explicitly asked. Never narrate
|
|
7
|
-
tool use. Answer the question; move on.
|
|
7
|
+
tool use. Answer the question; move on. Talk as a human-being.
|
|
8
8
|
|
|
9
9
|
## Project
|
|
10
10
|
blitzid — modular DNN-based ID document reading framework, optimized
|
|
@@ -52,7 +52,7 @@ class Engines:
|
|
|
52
52
|
structured sections), and ``structured_lock`` the LLM reader. The
|
|
53
53
|
FairFace, MiniFASNet, and ArcFace passes are plain onnxruntime
|
|
54
54
|
sessions, which are thread-safe, so they run outside any lock, and
|
|
55
|
-
the zxing-cpp barcode decode
|
|
55
|
+
the zxing-cpp barcode decode is a stateless per-call function.
|
|
56
56
|
Fields are None when an engine is unavailable (missing ``ocr`` or
|
|
57
57
|
``barcode`` extra, missing weights, missing LLM configuration).
|
|
58
58
|
"""
|
|
@@ -18,7 +18,8 @@ Payload layout (AAMVA versions 02-14)::
|
|
|
18
18
|
Subfile offsets are absolute from the first byte (the ``@``). Each
|
|
19
19
|
subfile holds 3-character element IDs followed by their values, one
|
|
20
20
|
per LF-separated line; the DL/ID/EN subfile carries the standard
|
|
21
|
-
elements
|
|
21
|
+
elements (EN is the pre-2025 enhanced-license subfile) and
|
|
22
|
+
jurisdiction ``Z..`` subfiles carry state-specific extras.
|
|
22
23
|
|
|
23
24
|
Element semantics differ across editions, so each edition's tag map is
|
|
24
25
|
pinned separately: versions 02-03 encode the given name in DCT (first
|
|
@@ -29,7 +30,8 @@ throughout. DAA is the full-name element only in the version-01
|
|
|
29
30
|
keeps the value raw in ``extra_tags``. Date elements
|
|
30
31
|
(DBB, DBD, DBA) are MMDDYYYY (U.S.) or CCYYMMDD (Canada) and normalize
|
|
31
32
|
via :func:`blitzid._dates.parse_date`; DBC sex encodes 1=male,
|
|
32
|
-
2=female, 9=unspecified
|
|
33
|
+
2=female, 9=unspecified, and any other code maps to unspecified with
|
|
34
|
+
the raw code kept in ``extra_tags``.
|
|
33
35
|
"""
|
|
34
36
|
|
|
35
37
|
from __future__ import annotations
|
|
@@ -74,13 +76,15 @@ class BarcodeRecord:
|
|
|
74
76
|
birth_date: Date of birth (DBB).
|
|
75
77
|
issue_date: Document issue date (DBD).
|
|
76
78
|
expiry_date: Document expiration date (DBA).
|
|
77
|
-
sex: ``"M"``, ``"F"``, or ``"X"`` (DBC 1/2/9)
|
|
79
|
+
sex: ``"M"``, ``"F"``, or ``"X"`` (DBC 1/2/9); any other DBC
|
|
80
|
+
code maps to ``"X"`` with the raw code kept in
|
|
81
|
+
``extra_tags``.
|
|
78
82
|
license_number: Customer ID number (DAQ).
|
|
79
83
|
height: Height with its unit, e.g. ``"069 in"`` (DAU), or None
|
|
80
84
|
when absent.
|
|
81
85
|
extra_tags: Raw values of every un-mapped element —
|
|
82
|
-
jurisdiction ``Z..`` extras
|
|
83
|
-
|
|
86
|
+
jurisdiction ``Z..`` extras, standard-but-unmapped fields,
|
|
87
|
+
and a non-standard DBC code alike.
|
|
84
88
|
symbology: The decoded barcode symbology, stamped by the reader
|
|
85
89
|
(``"PDF417"`` for the AAMVA payload), None for records
|
|
86
90
|
built directly by the parser.
|
|
@@ -132,12 +136,18 @@ def _date_field(elements: Mapping[str, str], tag: str, label: str) -> date:
|
|
|
132
136
|
return parsed
|
|
133
137
|
|
|
134
138
|
|
|
135
|
-
def _sex(elements: Mapping[str, str]) -> str:
|
|
136
|
-
"""Map the DBC sex code to M/F/X.
|
|
139
|
+
def _sex(elements: Mapping[str, str]) -> tuple[str, str | None]:
|
|
140
|
+
"""Map the DBC sex code to M/F/X.
|
|
141
|
+
|
|
142
|
+
Returns ``(sex, raw)``: the mapped value and, for a non-standard
|
|
143
|
+
DBC code, that raw code to keep in ``extra_tags``. A non-standard
|
|
144
|
+
code maps to ``"X"`` (unspecified) instead of failing the record.
|
|
145
|
+
"""
|
|
137
146
|
raw = _field(elements, "DBC", "sex")
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
147
|
+
mapped = _SEX.get(raw)
|
|
148
|
+
if mapped is None:
|
|
149
|
+
return "X", raw
|
|
150
|
+
return mapped, None
|
|
141
151
|
|
|
142
152
|
|
|
143
153
|
def _optional(elements: Mapping[str, str], tag: str) -> str | None:
|
|
@@ -177,14 +187,21 @@ def _parse_subfile(text: str, offset: int, length: int) -> Mapping[str, str]:
|
|
|
177
187
|
return MappingProxyType(elements)
|
|
178
188
|
|
|
179
189
|
|
|
190
|
+
def _is_designator(value: str) -> bool:
|
|
191
|
+
"""Whether *value* is a two-letter ASCII subfile designator."""
|
|
192
|
+
return value.isascii() and value.isalpha() and value.isupper()
|
|
193
|
+
|
|
194
|
+
|
|
180
195
|
def _parse_entry(text: str, index: int, directory_end: int) -> _Subfile:
|
|
181
196
|
"""Validate one subfile directory entry and its data region."""
|
|
182
197
|
start = _HEADER_LEN + index * _ENTRY_LEN
|
|
183
198
|
entry = text[start : start + _ENTRY_LEN]
|
|
184
199
|
kind, offset, length = entry[0:2], entry[2:6], entry[6:10]
|
|
185
|
-
if not (_is_digits(offset) and _is_digits(length)):
|
|
200
|
+
if not (_is_designator(kind) and _is_digits(offset) and _is_digits(length)):
|
|
186
201
|
raise BarcodeError(f"malformed subfile directory entry {index}")
|
|
187
202
|
offset_i, length_i = int(offset), int(length)
|
|
203
|
+
if length_i < 3:
|
|
204
|
+
raise BarcodeError(f"invalid subfile {kind!r} length: {length_i}")
|
|
188
205
|
if offset_i < directory_end:
|
|
189
206
|
raise BarcodeError(f"subfile {kind!r} offset lies inside the header")
|
|
190
207
|
if offset_i + length_i > len(text):
|
|
@@ -267,6 +284,9 @@ def _parse_aamva(text: str) -> BarcodeRecord:
|
|
|
267
284
|
jurisdiction, version, jurisdiction_version, subfiles = _parse_header(text)
|
|
268
285
|
primary, extra = _merge(subfiles, version)
|
|
269
286
|
family_name, given_name, middle_name = _names(version, primary)
|
|
287
|
+
sex, raw_sex = _sex(primary)
|
|
288
|
+
if raw_sex is not None:
|
|
289
|
+
extra = MappingProxyType({**extra, "DBC": raw_sex})
|
|
270
290
|
return BarcodeRecord(
|
|
271
291
|
jurisdiction=jurisdiction,
|
|
272
292
|
aamva_version=version,
|
|
@@ -277,7 +297,7 @@ def _parse_aamva(text: str) -> BarcodeRecord:
|
|
|
277
297
|
birth_date=_date_field(primary, "DBB", "birth date"),
|
|
278
298
|
issue_date=_date_field(primary, "DBD", "issue date"),
|
|
279
299
|
expiry_date=_date_field(primary, "DBA", "expiry date"),
|
|
280
|
-
sex=
|
|
300
|
+
sex=sex,
|
|
281
301
|
license_number=_field(primary, "DAQ", "license number"),
|
|
282
302
|
height=_optional(primary, "DAU"),
|
|
283
303
|
extra_tags=extra,
|
|
@@ -330,6 +350,10 @@ class BarcodeReader:
|
|
|
330
350
|
def read(self, image_input: ImageInput) -> BarcodeRecord:
|
|
331
351
|
"""Decode and parse the PDF417 barcode from an image.
|
|
332
352
|
|
|
353
|
+
Every decoded barcode is tried and the first payload that
|
|
354
|
+
parses as AAMVA wins, so one corrupt candidate beside a valid
|
|
355
|
+
code does not fail the read.
|
|
356
|
+
|
|
333
357
|
Args:
|
|
334
358
|
image_input: Path, NumPy array (BGR), or PIL Image.
|
|
335
359
|
|
|
@@ -339,18 +363,33 @@ class BarcodeReader:
|
|
|
339
363
|
Raises:
|
|
340
364
|
ImageError: If the image cannot be loaded or is invalid.
|
|
341
365
|
BarcodeError: If the image decodes no barcode at all, no
|
|
342
|
-
decoded payload is an AAMVA payload, or
|
|
343
|
-
fails validation.
|
|
366
|
+
decoded payload is an AAMVA payload, or every AAMVA
|
|
367
|
+
payload fails validation.
|
|
344
368
|
"""
|
|
345
369
|
img = load_image(image_input, self.logger)
|
|
346
370
|
barcodes = self._zxing.read_barcodes(img)
|
|
347
371
|
if not barcodes:
|
|
348
372
|
raise BarcodeError("no PDF417 barcode found in the image")
|
|
373
|
+
return self._first_record(barcodes)
|
|
374
|
+
|
|
375
|
+
def _first_record(self, barcodes: Any) -> BarcodeRecord:
|
|
376
|
+
"""The first candidate barcode that parses as an AAMVA payload.
|
|
377
|
+
|
|
378
|
+
A candidate carrying the AAMVA header but failing validation
|
|
379
|
+
does not stop the scan of the remaining barcodes; when none
|
|
380
|
+
parses, the first such validation error is raised, or
|
|
381
|
+
:class:`BarcodeError` when no barcode carried the header.
|
|
382
|
+
"""
|
|
383
|
+
error: BarcodeError | None = None
|
|
349
384
|
for barcode in barcodes:
|
|
350
385
|
text = barcode.bytes.decode("latin-1")
|
|
351
386
|
if not text.startswith(_MAGIC):
|
|
352
387
|
continue
|
|
353
|
-
|
|
388
|
+
try:
|
|
389
|
+
record = _parse_aamva(text)
|
|
390
|
+
except BarcodeError as e:
|
|
391
|
+
error = error or e
|
|
392
|
+
continue
|
|
354
393
|
record = replace(record, symbology=str(barcode.format))
|
|
355
394
|
self.logger.info(
|
|
356
395
|
"barcode read: version %s, jurisdiction %s",
|
|
@@ -358,6 +397,8 @@ class BarcodeReader:
|
|
|
358
397
|
record.jurisdiction,
|
|
359
398
|
)
|
|
360
399
|
return record
|
|
400
|
+
if error is not None:
|
|
401
|
+
raise error
|
|
361
402
|
raise BarcodeError(
|
|
362
403
|
"no AAMVA payload among the decoded barcodes "
|
|
363
404
|
"(missing '@\\n\\x1e\\rANSI ' header)"
|
|
@@ -1,9 +1,10 @@
|
|
|
1
1
|
"""Tests for blitzid.reading.barcode — AAMVA PDF417 parsing and decoding.
|
|
2
2
|
|
|
3
|
-
Parser tests are pure-function over synthetic payloads
|
|
4
|
-
name, number, and date
|
|
5
|
-
|
|
6
|
-
|
|
3
|
+
Parser tests are pure-function over synthetic payloads plus the
|
|
4
|
+
standard's own published sample (no PII: every name, number, and date
|
|
5
|
+
is invented or the AAMVA fictitious specimen). Decode tests round-trip
|
|
6
|
+
synthetic payloads through zxing-cpp's PDF417 encoder/decoder and are
|
|
7
|
+
skipped when the ``barcode`` extra is absent.
|
|
7
8
|
"""
|
|
8
9
|
|
|
9
10
|
from __future__ import annotations
|
|
@@ -20,6 +21,15 @@ from blitzid.reading.barcode import _parse_aamva, _record_dict
|
|
|
20
21
|
|
|
21
22
|
_VERSIONS = tuple(f"{number:02d}" for number in range(2, 15))
|
|
22
23
|
|
|
24
|
+
_AAMVA_2020_SAMPLE = (
|
|
25
|
+
"@\n\x1e\rANSI 636000100102DL00410278ZV03190008DLDAQT64235789\n"
|
|
26
|
+
"DCSSAMPLE\nDDEN\nDACMICHAEL\nDDFN\nDADJOHN\nDDGN\nDCUJR\nDCAD\n"
|
|
27
|
+
"DCBK\nDCDPH\nDBD06062019\nDBB06061986\nDBA12102024\nDBC1\n"
|
|
28
|
+
"DAU068 in\nDAYBRO\nDAG2300 WEST BROAD STREET\nDAIRICHMOND\nDAJVA\n"
|
|
29
|
+
"DAK232690000 \nDCF2424244747474786102204\nDCGUSA\nDCK123456789\n"
|
|
30
|
+
"DDAF\nDDB06062018\nDDC06062020\nDDD1\rZVZVA01\r"
|
|
31
|
+
)
|
|
32
|
+
|
|
23
33
|
|
|
24
34
|
def _assemble(
|
|
25
35
|
version: str,
|
|
@@ -90,6 +100,17 @@ def _entry(text: str, index: int) -> tuple[str, int, int]:
|
|
|
90
100
|
)
|
|
91
101
|
|
|
92
102
|
|
|
103
|
+
def _on_canvas(*symbols: np.ndarray) -> np.ndarray:
|
|
104
|
+
"""The encoded symbols side by side on one white canvas."""
|
|
105
|
+
height = max(symbol.shape[0] for symbol in symbols)
|
|
106
|
+
columns = []
|
|
107
|
+
for symbol in symbols:
|
|
108
|
+
column = np.full((height, symbol.shape[1]), 255, dtype=np.uint8)
|
|
109
|
+
column[: symbol.shape[0], : symbol.shape[1]] = symbol
|
|
110
|
+
columns.append(column)
|
|
111
|
+
return np.concatenate(columns, axis=1)
|
|
112
|
+
|
|
113
|
+
|
|
93
114
|
class TestParseHeader:
|
|
94
115
|
def test_rejects_missing_prefix(self) -> None:
|
|
95
116
|
with pytest.raises(BarcodeError, match="not an AAMVA payload"):
|
|
@@ -153,6 +174,16 @@ class TestParseHeader:
|
|
|
153
174
|
with pytest.raises(BarcodeError, match="lies inside the header"):
|
|
154
175
|
_parse_aamva(payload[:23] + "0000" + payload[27:])
|
|
155
176
|
|
|
177
|
+
def test_rejects_zero_length_subfile(self) -> None:
|
|
178
|
+
payload = _payload("08")
|
|
179
|
+
with pytest.raises(BarcodeError, match=r"invalid subfile 'DL' length: 0"):
|
|
180
|
+
_parse_aamva(payload[:27] + "0000" + payload[31:])
|
|
181
|
+
|
|
182
|
+
def test_rejects_non_letter_designator(self) -> None:
|
|
183
|
+
payload = _payload("08")
|
|
184
|
+
with pytest.raises(BarcodeError, match="malformed subfile directory entry"):
|
|
185
|
+
_parse_aamva(payload[:21] + "1A" + payload[23:])
|
|
186
|
+
|
|
156
187
|
def test_rejects_subfile_past_payload(self) -> None:
|
|
157
188
|
payload = _payload("08")
|
|
158
189
|
with pytest.raises(BarcodeError, match="exceeds the payload"):
|
|
@@ -290,6 +321,31 @@ class TestParseRecord:
|
|
|
290
321
|
assert record.sex == expected
|
|
291
322
|
|
|
292
323
|
|
|
324
|
+
class TestPublishedSample:
|
|
325
|
+
def test_parses_the_aamva_2020_sample_payload(self) -> None:
|
|
326
|
+
"""The DL/ID 2020 CDS Annex D sample credential (fictitious).
|
|
327
|
+
|
|
328
|
+
A published byte stream, independent of the payload generator,
|
|
329
|
+
so the tag map is checked against the standard's own example.
|
|
330
|
+
"""
|
|
331
|
+
record = _parse_aamva(_AAMVA_2020_SAMPLE)
|
|
332
|
+
assert record.jurisdiction == "636000"
|
|
333
|
+
assert record.aamva_version == "10"
|
|
334
|
+
assert record.jurisdiction_version == "01"
|
|
335
|
+
assert record.family_name == "SAMPLE"
|
|
336
|
+
assert record.given_name == "MICHAEL"
|
|
337
|
+
assert record.middle_name == "JOHN"
|
|
338
|
+
assert record.birth_date == date(1986, 6, 6)
|
|
339
|
+
assert record.issue_date == date(2019, 6, 6)
|
|
340
|
+
assert record.expiry_date == date(2024, 12, 10)
|
|
341
|
+
assert record.sex == "M"
|
|
342
|
+
assert record.license_number == "T64235789"
|
|
343
|
+
assert record.height == "068 in"
|
|
344
|
+
assert record.extra_tags["DCU"] == "JR"
|
|
345
|
+
assert record.extra_tags["DDF"] == "N"
|
|
346
|
+
assert record.extra_tags["ZVA"] == "01"
|
|
347
|
+
|
|
348
|
+
|
|
293
349
|
class TestSectionBody:
|
|
294
350
|
def test_record_dict_serializes_a_parsed_record(self) -> None:
|
|
295
351
|
body = _record_dict(_parse_aamva(_payload("10")))
|
|
@@ -326,9 +382,15 @@ class TestParseValidation:
|
|
|
326
382
|
with pytest.raises(BarcodeError, match="not a real date"):
|
|
327
383
|
_parse_aamva(_payload("08", elements=elements))
|
|
328
384
|
|
|
329
|
-
def
|
|
385
|
+
def test_nonstandard_sex_maps_to_unspecified(self) -> None:
|
|
330
386
|
elements = _elements("08", sex="3")
|
|
331
|
-
|
|
387
|
+
record = _parse_aamva(_payload("08", elements=elements))
|
|
388
|
+
assert record.sex == "X"
|
|
389
|
+
assert record.extra_tags["DBC"] == "3"
|
|
390
|
+
|
|
391
|
+
def test_missing_sex(self) -> None:
|
|
392
|
+
elements = [tag for tag in _elements("08") if tag[0] != "DBC"]
|
|
393
|
+
with pytest.raises(BarcodeError, match="missing sex"):
|
|
332
394
|
_parse_aamva(_payload("08", elements=elements))
|
|
333
395
|
|
|
334
396
|
def test_missing_license_number(self) -> None:
|
|
@@ -382,6 +444,26 @@ class TestDecodeRoundTrip:
|
|
|
382
444
|
record = reader.read(Image.fromarray(self._encode(_payload("10"))))
|
|
383
445
|
assert record.aamva_version == "10"
|
|
384
446
|
|
|
447
|
+
def test_accepts_a_three_channel_array(self) -> None:
|
|
448
|
+
pytest.importorskip("zxingcpp")
|
|
449
|
+
reader = BarcodeReader(log_level=logging.WARNING)
|
|
450
|
+
gray = self._encode(_payload("08"))
|
|
451
|
+
record = reader.read(np.repeat(gray[:, :, None], 3, axis=2))
|
|
452
|
+
assert record.aamva_version == "08"
|
|
453
|
+
|
|
454
|
+
def test_falls_back_past_a_corrupt_candidate(self) -> None:
|
|
455
|
+
pytest.importorskip("zxingcpp")
|
|
456
|
+
reader = BarcodeReader(log_level=logging.WARNING)
|
|
457
|
+
canvas = _on_canvas(self._encode(_payload("15")), self._encode(_payload("08")))
|
|
458
|
+
record = reader.read(canvas)
|
|
459
|
+
assert record.aamva_version == "08"
|
|
460
|
+
|
|
461
|
+
def test_raises_the_candidate_error_when_nothing_parses(self) -> None:
|
|
462
|
+
pytest.importorskip("zxingcpp")
|
|
463
|
+
reader = BarcodeReader(log_level=logging.WARNING)
|
|
464
|
+
with pytest.raises(BarcodeError, match="unsupported AAMVA version"):
|
|
465
|
+
reader.read(self._encode(_payload("15")))
|
|
466
|
+
|
|
385
467
|
def test_no_barcode_raises(self) -> None:
|
|
386
468
|
pytest.importorskip("zxingcpp")
|
|
387
469
|
reader = BarcodeReader(log_level=logging.WARNING)
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|