$ show mete0r/pyhwp
The pyhwp repository is a Python library and command-line toolset for parsing, analyzing, and converting Hangul Word Processor (HWP) version 5 files. It provides tools to extract text, metadata, and structural information from HWP files and convert them to HTML, ODT (OpenDocument Text), and plain text formats. The architecture is modular, separating concerns into binary model parsing, storage abstraction, platform-specific backends, and transformation pipelines. Key entry points include command-line tools like hwp5proc (for inspection), hwp5odt/htm/txt (for conversion), and hwp5view (for viewing). The system reads HWP files via storage abstractions, parses them into record streams using a declarative binary modeling system, and optionally transforms the internal representation via XSLT for output formats. While the project shows signs of active maintenance with recent security updates and version bumps, it exhibits technical drift due to continued support for end-of-life Python versions (2.7, 3.5-3.8) and reliance on legacy compatibility code.
The LLM identified 4 files worth highlighting for reuse:
Provides a pluggable backend system for services like XSLT compilation, RelaxNG validation, OLE storage, and AES decryption. Attempts multiple implementations in a defined order with fallbacks, allowing the library to adapt to different environments (e.g., system libs, Java via Jython/UNO, or pure Python). This pattern is isolated, reusable in other projects needing multi-backend support, and demonstrates strategic abstraction to handle environmental variability.
Defines a uniform interface for accessing storage systems (OLE files, filesystem) via Storage base class with __iter__ and __getitem__. Includes concrete implementations (OleStorage, FileSystemStorage) and a decorator-like ExtraItemStorage to add virtual streams (e.g., .xml, .records). This abstraction is self-contained, could be extracted for use in other projects needing storage agnosticism, and shows clean separation of concerns between storage logic and higher-level processing.
Implements a metaclass-driven system for declarative binary structure definition. RecordModel base class uses RecordType metaclass to auto-register models by tag ID. Specific record types (e.g., para_header, table) inherit and define fields via attributes() classmethod using primitive types from dataio.py. This pattern is highly reusable for parsing any binary format, reduces boilerplate, and demonstrates advanced yet practical metaprogramming for structured data extraction.
Extends the binary modeling system to handle control records with a ControlType metaclass for auto-registration by CHID. Includes an extension mechanism via extension_types and get_extension_key for dynamic type registration. This component is reusable for systems needing extensible record types with pluggable extensions, showing how to build flexible, maintainable parsing frameworks for complex binary formats with variant records.