Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: Add Support for lxml >= 5.2.0 #217

Merged
Merged
Show file tree
Hide file tree
Changes from 7 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 14 additions & 7 deletions extruct/xmldom.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,15 +6,22 @@
from xml.dom import Node
from xml.dom.minidom import Attr, NamedNodeMap

from lxml.etree import (
ElementBase,
XPath,
_ElementStringResult,
_ElementUnicodeResult,
tostring,
)
from lxml.etree import ElementBase, XPath, _ElementUnicodeResult, tostring
from lxml.html import HtmlElementClassLookup, HTMLParser

try:
from lxml.etree import _ElementStringResult
except ImportError:

class _ElementStringResult(bytes): # type: ignore[no-redef]
"""
_ElementStringResult is removed in lxml >= 5.1.0,
Gallaecio marked this conversation as resolved.
Show resolved Hide resolved
so we define it here for compatibility.
"""

def getparent(self):
return self._parent # type: ignore[attr-defined]


class DomElementUnicodeResult:
CDATA_SECTION_NODE = Node.CDATA_SECTION_NODE
Expand Down
2 changes: 1 addition & 1 deletion requirements.txt
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# project requirements, install them using following command:
# pip install -r requirements.txt
lxml
lxml[html_clean]
requests
rdflib>=6.0.0; python_version>="3.7"
rdflib<6.0.0; python_version<"3.7"
Expand Down
5 changes: 4 additions & 1 deletion tests/samples/misc/microformat_flat_test.json
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,10 @@
"aJ Styles FastLane 2018 15 x 17 Framed Plaque w/ Ring Canvas"
],
"photo": [
"/on/demandware.static/-/Sites-main/default/dwa3227ee6/images/small/CN1148.jpg"
{
"alt": "aJ Styles FastLane 2018 15 x 17 Framed Plaque w/ Ring Canvas",
"value": "/on/demandware.static/-/Sites-main/default/dwa3227ee6/images/small/CN1148.jpg"
}
]
}
]
Expand Down
6 changes: 5 additions & 1 deletion tests/samples/misc/microformat_test.json
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,11 @@
{
"properties": {
"photo": [
"/on/demandware.static/-/Sites-main/default/dwa3227ee6/images/small/CN1148.jpg"
{
"alt": "aJ Styles FastLane 2018 15 x 17 Framed Plaque w/ Ring Canvas",
"value": "/on/demandware.static/-/Sites-main/default/dwa3227ee6/images/small/CN1148.jpg"

}
],
"name": [
"aJ Styles FastLane 2018 15 x 17 Framed Plaque w/ Ring Canvas"
Expand Down
5 changes: 4 additions & 1 deletion tests/test_uniform.py
Original file line number Diff line number Diff line change
Expand Up @@ -167,7 +167,10 @@ def test_umicroformat(self):
"Canvas"
],
"photo": [
"/on/demandware.static/-/Sites-main/default/dwa3227ee6/images/small/CN1148.jpg"
{
"alt": "aJ Styles FastLane 2018 15 x 17 Framed Plaque w/ Ring Canvas",
"value": "/on/demandware.static/-/Sites-main/default/dwa3227ee6/images/small/CN1148.jpg",
}
],
},
],
Expand Down
Loading