Skip to content

Commit 654da15

Browse files
committed
Catch ParseError through defusedxml
`defusedxml.ElementTree` re-exports the stdlib `ParseError`, so the root sniff in `fetchers.py` needs no import of `xml.etree.ElementTree` of its own.
1 parent aa49be5 commit 654da15

1 file changed

Lines changed: 1 addition & 2 deletions

File tree

litfetch/fetchers.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,6 @@
4242
import mimetypes
4343
import re
4444
import urllib.parse
45-
import xml.etree.ElementTree as ET
4645
from collections.abc import Mapping
4746
from typing import Protocol
4847

@@ -396,7 +395,7 @@ def _root_localname(content: bytes) -> str | None:
396395
try:
397396
for _event, element in defusedxml.ElementTree.iterparse(io.BytesIO(content), events=('start',)):
398397
return element.tag.rsplit('}', 1)[-1]
399-
except ET.ParseError:
398+
except defusedxml.ElementTree.ParseError:
400399
return None
401400
return None
402401

0 commit comments

Comments
 (0)