Skip to content

Commit

Permalink
fix: Add Support for lxml >= 5.2.0 (#217)
Browse files Browse the repository at this point in the history
Co-authored-by: James Addison <[email protected]>
  • Loading branch information
michael-genson and jayaddison authored Apr 11, 2024
1 parent 6053812 commit 9e0179b
Show file tree
Hide file tree
Showing 5 changed files with 28 additions and 11 deletions.
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.1,
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

0 comments on commit 9e0179b

Please sign in to comment.