fix(sitemap): guard the unavailable `ExpatParser.flush` on older `CPy… · apify/crawlee-python@7f75295 · GitHub
Skip to content

Commit 7f75295

Browse files
authored
fix(sitemap): guard the unavailable ExpatParser.flush on older CPython patch releases (#2141)
### Description - `_XmlSitemapParser.flush` called `ExpatParser.flush()` unguarded. The method was added in CPython 3.10.14, 3.11.9, and 3.12.3, so on earlier patch releases every sitemap parse logged a spurious WARNING. It's now called only when it exists. - Moved the `yield` loop into a `finally`, so a raising `flush()` no longer discards the items the handler has already collected. ### Issues - Closes: #2119 ### Testing - Added tests for a parser without `flush` and for a failing `flush()`.
1 parent 4a67025 commit 7f75295

2 files changed

Lines changed: 59 additions & 5 deletions

File tree

‎src/crawlee/_utils/sitemap.py‎

Lines changed: 8 additions & 4 deletions

‎tests/unit/_utils/test_sitemap.py‎

Lines changed: 51 additions & 1 deletion

0 commit comments

Comments
 (0)