From e1ce191944ee0519d33838259db1cc74a6d65f13 Mon Sep 17 00:00:00 2001 From: icanhasmath Date: Thu, 19 Nov 2026 15:53:27 -0600 Subject: [PATCH 1/4] Restore deprecated methods that lxml 5.0 removed lxml 5.0 removed XPath.evaluate() (XPath, ETXPath, XPathEvaluator), parser.setElementClassLookup() and XSLT.apply(), all deprecated since lxml 2.0. Code written against lxml 4.x that still calls them fails with AttributeError after an upgrade to 5.0. Bring them back verbatim from lxml 4.9.2: each is a thin alias of the supported call. Co-Authored-By: Claude Opus 5.5 --- src/lxml/parser.pxi | 4 ++ src/lxml/tests/test_deprecated_aliases.py | 74 +++++++++++++++++++++++ src/lxml/xpath.pxi | 15 +++++ src/lxml/xslt.pxi | 6 ++ 4 files changed, 99 insertions(+) create mode 100644 src/lxml/tests/test_deprecated_aliases.py diff --git a/src/lxml/parser.pxi b/src/lxml/parser.pxi index f078b27d3..c96df6348 100644 --- a/src/lxml/parser.pxi +++ b/src/lxml/parser.pxi @@ -1013,6 +1013,10 @@ cdef class _BaseParser: """The version of the underlying XML parser.""" return u"libxml2 %d.%d.%d" % LIBXML_VERSION + def setElementClassLookup(self, ElementClassLookup lookup = None): + u":deprecated: use ``parser.set_element_class_lookup(lookup)`` instead." + self.set_element_class_lookup(lookup) + def set_element_class_lookup(self, ElementClassLookup lookup = None): u"""set_element_class_lookup(self, lookup = None) diff --git a/src/lxml/tests/test_deprecated_aliases.py b/src/lxml/tests/test_deprecated_aliases.py new file mode 100644 index 000000000..afdab9c4d --- /dev/null +++ b/src/lxml/tests/test_deprecated_aliases.py @@ -0,0 +1,74 @@ +# -*- coding: utf-8 -*- +""" +Tests for the deprecated methods that lxml 5.0 removed and this fork keeps +for code written against lxml 4.x: XPath.evaluate(), parser.setElementClassLookup() +and XSLT.apply(). Each must behave like the supported call it aliases. +""" +from __future__ import absolute_import + +import unittest + +from lxml import etree + +from .common_imports import HelperTestCase + + +class DeprecatedAliasesTestCase(HelperTestCase): + def setUp(self): + super(DeprecatedAliasesTestCase, self).setUp() + self.root = etree.fromstring( + b'123') + + def test_etxpath_evaluate(self): + path = etree.ETXPath("{urn:n}b") + self.assertEqual([e.text for e in path.evaluate(self.root)], + [e.text for e in path(self.root)]) + self.assertEqual(["2"], [e.text for e in path.evaluate(self.root)]) + + def test_xpath_evaluate_variables(self): + path = etree.XPath("count(a[. = $v])") + self.assertEqual(1.0, path.evaluate(self.root, v="3")) + self.assertEqual(path(self.root, v="3"), path.evaluate(self.root, v="3")) + + def test_xpath_element_evaluator_evaluate(self): + evaluator = etree.XPathEvaluator(self.root) + self.assertEqual(2.0, evaluator.evaluate("count(a)")) + self.assertEqual(evaluator("count(a)"), evaluator.evaluate("count(a)")) + + def test_xpath_document_evaluator_evaluate(self): + evaluator = etree.XPathEvaluator(etree.ElementTree(self.root)) + self.assertEqual(2.0, evaluator.evaluate("count(//a)")) + + def test_parser_set_element_class_lookup(self): + class Custom(etree.ElementBase): + pass + for parser in (etree.XMLParser(), etree.HTMLParser()): + parser.setElementClassLookup( + etree.ElementDefaultClassLookup(element=Custom)) + self.assertTrue(isinstance(etree.fromstring("", parser), Custom)) + parser.setElementClassLookup() + self.assertFalse(isinstance(etree.fromstring("", parser), Custom)) + + def test_xslt_apply(self): + style = etree.XSLT(etree.fromstring( + b'' + b'' + b'' + b'' + b'')) + self.assertEqual(str(style(self.root)), str(style.apply(self.root))) + self.assertEqual("12", style.apply(self.root, p="10").getroot().text) + self.assertTrue(style.apply(self.root, profile_run=True).xslt_profile + is not None) + + +def test_suite(): + suite = unittest.TestSuite() + suite.addTests([unittest.defaultTestLoader.loadTestsFromTestCase( + DeprecatedAliasesTestCase)]) + return suite + + +if __name__ == '__main__': + print('to test use test.py %s' % __file__) diff --git a/src/lxml/xpath.pxi b/src/lxml/xpath.pxi index 9f364f998..ac7177fd9 100644 --- a/src/lxml/xpath.pxi +++ b/src/lxml/xpath.pxi @@ -147,6 +147,21 @@ cdef class _XPathEvaluatorBase: self._xpathCtxt = xpathCtxt self._context.set_context(xpathCtxt) + def evaluate(self, _eval_arg, **_variables): + u"""evaluate(self, _eval_arg, **_variables) + + Evaluate an XPath expression. + + Instead of calling this method, you can also call the evaluator object + itself. + + Variables may be provided as keyword arguments. Note that namespaces + are currently not supported for variables. + + :deprecated: call the object, not its method. + """ + return self(_eval_arg, **_variables) + cdef bint _checkAbsolutePath(self, char* path) noexcept: cdef char c if path is NULL: diff --git a/src/lxml/xslt.pxi b/src/lxml/xslt.pxi index cb629ca92..ebbbf03ac 100644 --- a/src/lxml/xslt.pxi +++ b/src/lxml/xslt.pxi @@ -469,6 +469,12 @@ cdef class XSLT: raise ValueError("cannot set a maximum stylesheet traversal depth < 0") xslt.xsltMaxDepth = max_depth + def apply(self, _input, *, profile_run=False, **kw): + u"""apply(self, _input, profile_run=False, **kw) + + :deprecated: call the object, not this method.""" + return self(_input, profile_run=profile_run, **kw) + def tostring(self, _ElementTree result_tree): u"""tostring(self, result_tree) From 651eecb3573535cd5b3efea76a2def2ec8a94d67 Mon Sep 17 00:00:00 2001 From: icanhasmath Date: Thu, 19 Nov 2026 15:53:30 -0600 Subject: [PATCH 2/4] Link the libraries xml2-config and xslt-config report lxml links a fixed list (xslt exslt xml2 rt z m) and takes only the -L directories from xml2-config/xslt-config --libs. Against static libxml2.a and libxslt.a, which carry no DT_NEEDED entries, that drops libxml2's own dependencies: with GNU libiconv, etree.so and objectify.so are left with undefined libiconv/libiconv_open/libiconv_close and fail on import. Append every -l the config tools report that is not already listed. With shared libraries this is harmless. The ActiveState Platform has carried this as an inventory patch on 5.0.2.1; it now lives in the source. Co-Authored-By: Claude Opus 5.5 --- setupinfo.py | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/setupinfo.py b/setupinfo.py index d9722b3be..56996e3d5 100644 --- a/setupinfo.py +++ b/setupinfo.py @@ -336,6 +336,12 @@ def libraries(): libs = standard_libs else: libs = ['xslt', 'exslt', 'xml2'] + standard_libs + # Static libxml2/libxslt archives carry no DT_NEEDED entries, so also link + # every library their config tools report (e.g. -liconv for GNU libiconv, + # -lpthread, -ldl). With shared libraries this is harmless. + for flag in flags('libs'): + if flag.startswith('-l') and flag[2:] not in libs: + libs.append(flag[2:]) return libs def library_dirs(static_library_dirs): From 2578c885d6ea1d8a3cf3ce758daf7f0338593fed Mon Sep 17 00:00:00 2001 From: icanhasmath Date: Thu, 19 Nov 2026 15:54:03 -0600 Subject: [PATCH 3/4] Parse a .postN suffix in LXML_VERSION __unpackDottedVersion() left an unknown suffix as a string, so a post release would give LXML_VERSION = (5, 0, 2, 'post2'), which raises TypeError when compared with an all-integer tuple on Python 3. Read postN as the number N: 5.0.2.post2 -> (5, 0, 2, 2). Co-Authored-By: Claude Opus 5.5 --- src/lxml/etree.pyx | 4 ++++ src/lxml/tests/test_deprecated_aliases.py | 11 +++++++++++ 2 files changed, 15 insertions(+) diff --git a/src/lxml/etree.pyx b/src/lxml/etree.pyx index 84db353b7..79f1fc409 100644 --- a/src/lxml/etree.pyx +++ b/src/lxml/etree.pyx @@ -253,6 +253,10 @@ cdef __unpackDottedVersion(version): elif item.startswith(u'beta'): count = item[4:] item = -100 + elif item.startswith(u'post'): + # ActiveState post releases: 5.0.2.post2 -> (5, 0, 2, 2) + count = item[4:] + item = 0 else: count = 0 if count: diff --git a/src/lxml/tests/test_deprecated_aliases.py b/src/lxml/tests/test_deprecated_aliases.py index afdab9c4d..be2a83396 100644 --- a/src/lxml/tests/test_deprecated_aliases.py +++ b/src/lxml/tests/test_deprecated_aliases.py @@ -63,10 +63,21 @@ def test_xslt_apply(self): is not None) +class VersionTestCase(HelperTestCase): + def test_lxml_version_is_numeric(self): + # A post release (5.0.2.postN) must still unpack to four integers, + # so that tuple comparisons against LXML_VERSION work on Python 3. + self.assertEqual(4, len(etree.LXML_VERSION)) + for part in etree.LXML_VERSION: + self.assertTrue(isinstance(part, int), etree.LXML_VERSION) + + def test_suite(): suite = unittest.TestSuite() suite.addTests([unittest.defaultTestLoader.loadTestsFromTestCase( DeprecatedAliasesTestCase)]) + suite.addTests([unittest.defaultTestLoader.loadTestsFromTestCase( + VersionTestCase)]) return suite From 20fc6708e9cb74f1a8c2c00ab08ce94b32598092 Mon Sep 17 00:00:00 2001 From: icanhasmath Date: Thu, 19 Nov 2026 15:54:03 -0600 Subject: [PATCH 4/4] Release 5.0.2.post2 Version string: 5.0.2.post2 Git tag: 5.0.2.2 Co-Authored-By: Claude Opus 5.5 --- CHANGES.txt | 18 ++++++++++++++++++ src/lxml/__init__.py | 2 +- 2 files changed, 19 insertions(+), 1 deletion(-) diff --git a/CHANGES.txt b/CHANGES.txt index 3bc6c92fa..df472ad4a 100644 --- a/CHANGES.txt +++ b/CHANGES.txt @@ -2,6 +2,24 @@ lxml changelog ============== +5.0.2.post2 (2026-11-19) +======================== + +Bug fixes +--------- + +* Restored the deprecated methods that lxml 5.0 removed, for code written + against lxml 4.x: ``XPath.evaluate()`` (also on ``ETXPath`` and + ``XPathEvaluator``), ``parser.setElementClassLookup()`` and + ``XSLT.apply()``. Each is an alias of the supported call, as in lxml 4.9. + +* ``setupinfo.py`` links every library ``xml2-config`` and ``xslt-config`` + report, so static ``libxml2.a`` builds pick up ``-liconv`` and similar. + +* ``LXML_VERSION`` parses a ``.postN`` suffix as the fourth number, so + 5.0.2.post2 is ``(5, 0, 2, 2)``. + + 5.0.2+security.1 (2026-05-28) ============================== diff --git a/src/lxml/__init__.py b/src/lxml/__init__.py index 13756ca4c..3341b2b7a 100644 --- a/src/lxml/__init__.py +++ b/src/lxml/__init__.py @@ -1,6 +1,6 @@ # this is a package -__version__ = "5.0.2+security.1" +__version__ = "5.0.2.post2" def get_include():