Support xml.sax pyexpat setup APIs#8238
Conversation
RustPython already exposes an Expat-like XML parser, but xml.sax expects a few setup APIs before parsing. Add compatible parser setup methods and constants without pretending to implement full Expat external entity behavior. Constraint: Lib/test changes only remove expectedFailure markers for tests that now pass; test bodies and assertions are unchanged. Rejected: Implementing full Expat parameter entity parsing | xml-rs does not expose that configuration and the immediate failure is the missing setup API. Confidence: high Scope-risk: narrow Directive: Keep SetParamEntityParsing as a compatibility shim unless the backend grows real Expat-style entity parsing support. Tested: PATH=/tmp/pyshim:$PATH prek run --all-files Tested: cargo run --quiet -- extra_tests/snippets/stdlib_xml.py Tested: cargo run --release -- -m test test_sax Tested: cargo run --release -- -m test test_pyexpat Tested: cargo test --workspace --exclude rustpython-capi --exclude rustpython_wasm --exclude rustpython-compiler-source --exclude rustpython-venvlauncher --features threading --no-default-features --features stdlib,importlib,stdio,encodings,sqlite,ssl-rustls-aws-lc,host_env && (cd crates/capi && cargo test) Tested: PYO3_CONFIG_FILE=$PWD/crates/capi/pyo3-rustpython.config cargo test --workspace --exclude rustpython_wasm --exclude rustpython-venvlauncher Tested: cargo build --release --features sqlite && cd extra_tests && /tmp/rustpython-extra-tests-venv/bin/python -m pytest -v Tested: cargo clippy --workspace --exclude rustpython-capi --exclude rustpython_wasm --exclude rustpython-compiler-source --exclude rustpython-venvlauncher --features threading --no-default-features --features stdlib,importlib,stdio,encodings,sqlite,ssl-rustls-aws-lc,host_env Assisted-by: Codex:gpt-5.5
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: Path: .coderabbit.yml Review profile: CHILL Plan: Pro Run ID: ⛔ Files ignored due to path filters (1)
📒 Files selected for processing (2)
📝 WalkthroughWalkthroughThis PR adds ChangesExpat Parser Compatibility Methods
Estimated code review effort: 2 (Simple) | ~10 minutes Sequence Diagram(s)sequenceDiagram
participant PythonCode
participant PyExpatLikeXmlParser
PythonCode->>PyExpatLikeXmlParser: SetParamEntityParsing(flag)
PyExpatLikeXmlParser-->>PythonCode: returns 1
PythonCode->>PyExpatLikeXmlParser: SetBase(base_str)
PyExpatLikeXmlParser->>PyExpatLikeXmlParser: store base in PyRwLock
PythonCode->>PyExpatLikeXmlParser: GetBase()
PyExpatLikeXmlParser-->>PythonCode: returns stored base or None
🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
✨ Finishing Touches🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
📦 Library DependenciesThe following Lib/ modules were modified. Here are their dependencies: [x] lib: cpython/Lib/asyncio dependencies:
dependent tests: (7 tests)
[x] test: cpython/Lib/test/test_float.py (TODO: 4) dependencies: dependent tests: (no tests depend on float) [x] test: cpython/Lib/test/test_frame.py (TODO: 14) dependencies: dependent tests: (no tests depend on frame) [x] lib: cpython/Lib/xml dependencies:
dependent tests: (34 tests)
[ ] test: cpython/Lib/test/test_generators.py (TODO: 11) dependencies: dependent tests: (no tests depend on generator) [x] lib: cpython/Lib/inspect.py dependencies:
dependent tests: (96 tests)
[x] lib: cpython/Lib/io.py dependencies:
dependent tests: (108 tests)
[x] test: cpython/Lib/test/test_descr.py (TODO: 34) dependencies: dependent tests: (no tests depend on descr) [x] lib: cpython/Lib/ssl.py dependencies:
dependent tests: (53 tests)
[x] lib: cpython/Lib/pdb.py dependencies:
dependent tests: (1 tests)
[x] lib: cpython/Lib/traceback.py dependencies:
dependent tests: (161 tests)
[ ] test: cpython/Lib/test/test_monitoring.py (TODO: 7) dependencies: dependent tests: (no tests depend on monitoring) Legend:
|
Summary
Adds the pyexpat setup APIs that
xml.saxexpects when initializing the Expat reader.Problem
xml.sax.parseString()and related SAX paths create a parser throughxml.parsers.expat, then call setup methods such asSetParamEntityParsing().RustPython's native pyexpat parser did not expose those setup APIs, so normal SAX parsing could fail before it started parsing XML.
Fixes
XML_PARAM_ENTITY_PARSING_*constants.SetParamEntityParsing()as a compatibility shim for SAX setup.SetBase()andGetBase()for parser base URI state used by locator-related SAX paths.extra_tests/snippets/stdlib_xml.py.expectedFailuremarkers from the SAX tests that now pass.This does not implement full Expat-style external entity parsing. The current backend still uses xml-rs, which does not expose that configuration.
Testing
PATH=/tmp/pyshim:$PATH prek run --all-filescargo run --quiet -- extra_tests/snippets/stdlib_xml.pycargo run --release -- -m test test_saxcargo run --release -- -m test test_pyexpatcargo test --workspace --exclude rustpython-capi --exclude rustpython_wasm --exclude rustpython-compiler-source --exclude rustpython-venvlauncher --features threading --no-default-features --features stdlib,importlib,stdio,encodings,sqlite,ssl-rustls-aws-lc,host_env && (cd crates/capi && cargo test)PYO3_CONFIG_FILE=$PWD/crates/capi/pyo3-rustpython.config cargo test --workspace --exclude rustpython_wasm --exclude rustpython-venvlaunchercargo build --release --features sqlite && cd extra_tests && /tmp/rustpython-extra-tests-venv/bin/python -m pytest -vcargo clippy --workspace --exclude rustpython-capi --exclude rustpython_wasm --exclude rustpython-compiler-source --exclude rustpython-venvlauncher --features threading --no-default-features --features stdlib,importlib,stdio,encodings,sqlite,ssl-rustls-aws-lc,host_envAI use
Assisted by Codex:gpt-5.5 for implementation, test drafting, and verification. I reviewed and verified the changes locally.
Summary by CodeRabbit
New Features
Tests