Skip to content

Commit 59bb3f2

Browse files
committed
Version 3.10.3rc1
1 parent a772bdd commit 59bb3f2

File tree

5 files changed

+19
-13
lines changed

5 files changed

+19
-13
lines changed

.bumpversion.cfg

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
[bumpversion]
2-
current_version = 3.10.3rc0
2+
current_version = 3.10.3rc1
33
message = Release {new_version}
44
parse = ^
55
(?P<major>\d+)

CHANGELOG.rst

+2-2
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ can check out the `wish list <https://github.com/mborsetti/webchanges/blob/main/
3131
Internals, for changes that don't affect users. [triggers a minor patch]
3232
3333
34-
Version 3.10.3rc0
34+
Version 3.10.3rc1
3535
===================
3636
Unreleased
3737

@@ -54,7 +54,7 @@ Changed
5454

5555
Fixed
5656
-----
57-
* Attempt to fix ``Unicode strings with encoding declaration are not supported.`` error in the ``xpath`` filter using
57+
* Fixed ``Unicode strings with encoding declaration are not supported.`` error in the ``xpath`` filter using
5858
``method: xml`` under certain conditions (MacOS only). Reported by `jprokos <https://github.com/jprokos>`__ in `#42
5959
<https://github.com/mborsetti/webchanges/issues/42>`__.
6060

RELEASE.rst

+1-1
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ Changed
1717

1818
Fixed
1919
-----
20-
* Attempt to fix ``Unicode strings with encoding declaration are not supported.`` error in the ``xpath`` filter using
20+
* Fixed ``Unicode strings with encoding declaration are not supported.`` error in the ``xpath`` filter using
2121
``method: xml`` under certain conditions (MacOS only). Reported by `jprokos <https://github.com/jprokos>`__ in `#42
2222
<https://github.com/mborsetti/webchanges/issues/42>`__.
2323

webchanges/__init__.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818
# * MINOR version when you add functionality in a backwards compatible manner, and
1919
# * MICRO or PATCH version when you make backwards compatible bug fixes. We no longer use '0'
2020
# If unsure on increments, use pkg_resources.parse_version to parse
21-
__version__ = '3.10.3rc0'
21+
__version__ = '3.10.3rc1'
2222
__description__ = (
2323
'Check web (or commands) for changes since last run and notify.\n\nAnonymously alerts you of webpage changes.'
2424
)

webchanges/filters.py

+14-8
Original file line numberDiff line numberDiff line change
@@ -1109,10 +1109,8 @@ class LxmlParser:
11091109

11101110
expression: str
11111111
method: str
1112-
exclude: Optional[str]
11131112
namespaces: Optional[Dict[str, str]]
11141113
skip: int
1115-
maxitems: int
11161114

11171115
def __init__(
11181116
self: Union['LxmlParser', 'CSSFilter', 'XPathFilter'],
@@ -1143,8 +1141,7 @@ def __init__(
11431141
f"The '{filter_kind}' filter's namespace prefixes are only supported with 'method: xml'. "
11441142
f'({job.get_indexed_location()})'
11451143
)
1146-
# for the below, see https://lxml.de/FAQ.html#why-can-t-lxml-parse-my-xml-from-unicode-strings
1147-
self.parser = etree.HTMLParser() if self.method == 'html' else etree.XMLParser()
1144+
self.parser = etree.HTMLParser() if self.method == 'html' else etree.XMLParser() # etree._FeedParser
11481145
self.data = ''
11491146

11501147
def feed(self, data: str) -> None:
@@ -1220,11 +1217,20 @@ def _orphaned(self, element: etree.Element) -> bool:
12201217
def _get_filtered_elements(self) -> List[Union[etree.Element, str]]:
12211218
if self.method == 'xml' and isinstance(self.data, str):
12221219
# see https://lxml.de/FAQ.html#why-can-t-lxml-parse-my-xml-from-unicode-strings
1223-
root = etree.fromstring( # nosec B320: use defusedxml TODO
1224-
self.data.encode(errors='xmlcharrefreplace'), self.parser
1225-
)
1220+
data: Union[str, bytes] = self.data.encode(errors='xmlcharrefreplace')
1221+
elif self.method == 'html' and self.data.startswith('<?xml'):
1222+
# handle legacy https://stackoverflow.com/questions/37592045/
1223+
data = self.data.split('>', maxsplit=1)[1]
12261224
else:
1227-
root = etree.fromstring(self.data, self.parser) # nosec B320: use defusedxml TODO
1225+
data = self.data
1226+
try:
1227+
root = etree.fromstring(data, self.parser) # nosec B320: use defusedxml TODO
1228+
except ValueError as e:
1229+
args = (
1230+
f"Filter '{self.filter_kind}' encountered the following error when parsing the data. Check that "
1231+
f"'method: {self.method}' is the correct one.\n {type(e).__name__}: {e.args[0]}"
1232+
)
1233+
raise RuntimeError(args) from None
12281234
if root is None:
12291235
return []
12301236
selected_elems: Optional[List[etree.Element]] = None

0 commit comments

Comments
 (0)