-
Notifications
You must be signed in to change notification settings - Fork 27
Description
Problem
The auto-generated Kaitai Struct parser polyfile/kaitai/parsers/openpgp_message.py contains invalid Python syntax. It uses self.class = ... which causes a SyntaxError because class is a reserved keyword in Python.
Error
File "polyfile/kaitai/parsers/openpgp_message.py", line 370
self.class = self._io.read_u1()
^^^^^
SyntaxError: invalid syntaxImpact
This prevents polyfile from being imported in Python, breaking functionality for parsing OpenPGP messages.
Root Cause
The Kaitai Struct compiler generates Python code without escaping reserved keywords. This affects line 361, 369, 370, and 371 in openpgp_message.py.
Upstream Fix
A fix has been submitted to the Kaitai Struct compiler upstream:
Once that PR is merged and new parsers are generated, this issue will be resolved at the source.
Interim Solution
Until the upstream fix is available, I've prepared a PR that:
- Automatically patches the issue on import - The fix is applied transparently when polyfile is imported
- Includes a manual fix script (
fix_class_keyword.py) for development/debugging - Updates documentation with a Known Issues section
The fix replaces all occurrences of self.class with self.class_ (following PEP 8 conventions for reserved keywords).
Testing
The fix has been tested and successfully:
- Replaces
self.classwithself.class_(line 370) - Updates
SEQ_FIELDSfrom"class"to"class_"(line 361) - Updates debug references from
['class']to['class_'](lines 369, 371) - Allows polyfile to be imported without errors