Commit e946d18
committed
feat: Add comprehensive codecs module with extension-based codec registries
Implements Pattern 1 (extension-based codec registries) for flexible
configuration file parsing with support for bytes <-> JSON-friendly Python types.
New features:
- Core registry infrastructure with EXTENSION_TO_DECODER/ENCODER mappings
- Registration API: register_codec(), register_decoder(), register_encoder()
- Introspection API: list_registered_extensions(), is_extension_registered(), get_codec_info()
- encode_by_extension() and decode_by_extension() for automatic codec routing
Standard library codecs (always available):
- JSON (.json) - with proper UTF-8 and indentation
- Pickle (.pkl, .pickle) - Python object serialization
- Plain text (.txt)
- Line-separated values (.lsv, .list, .lines)
- CSV (.csv) - with dict support
- TSV (.tsv, .tab) - tab-separated values
- INI/CFG (.ini, .cfg, .conf) - ConfigParser format
- XML (.xml) - basic ElementTree support
Conditional third-party codecs:
- TOML (.toml) - tomllib (3.11+) / tomli + tomli_w
- YAML (.yaml, .yml) - PyYAML with safe_load
- ENV (.env) - python-dotenv with simple fallback
- JSON5 (.json5) - lenient JSON parsing
- Properties (.properties) - Java-style with jproperties fallback
Extras added to pyproject.toml:
- Individual extras: yaml, toml, env, json5, properties
- Convenience groups: all-codecs, all
Key implementation details:
- Graceful fallback for missing third-party dependencies
- Dotfile support (e.g., .env, .gitignore)
- Comprehensive test suite with 100+ test cases
- Full type hints and docstrings1 parent 2b0cea2 commit e946d18
File tree
4 files changed
+1105
-0
lines changed- config2py
- tests
4 files changed
+1105
-0
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
24 | 24 | | |
25 | 25 | | |
26 | 26 | | |
| 27 | + | |
0 commit comments