Skip to content
Merged
Show file tree
Hide file tree
Changes from all 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
18 changes: 18 additions & 0 deletions CHANGES.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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)
==============================

Expand Down
6 changes: 6 additions & 0 deletions setupinfo.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down
2 changes: 1 addition & 1 deletion src/lxml/__init__.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# this is a package

__version__ = "5.0.2+security.1"
__version__ = "5.0.2.post2"


def get_include():
Expand Down
4 changes: 4 additions & 0 deletions src/lxml/etree.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
4 changes: 4 additions & 0 deletions src/lxml/parser.pxi
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down
85 changes: 85 additions & 0 deletions src/lxml/tests/test_deprecated_aliases.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,85 @@
# -*- 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'<r xmlns:n="urn:n"><a>1</a><n:b>2</n:b><a>3</a></r>')

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("<x/>", parser), Custom))
parser.setElementClassLookup()
self.assertFalse(isinstance(etree.fromstring("<x/>", parser), Custom))

def test_xslt_apply(self):
style = etree.XSLT(etree.fromstring(
b'<xsl:stylesheet version="1.0" '
b'xmlns:xsl="http://www.w3.org/1999/XSL/Transform">'
b'<xsl:param name="p" select="0"/>'
b'<xsl:template match="/"><out>'
b'<xsl:value-of select="count(//a) + $p"/></out></xsl:template>'
b'</xsl:stylesheet>'))
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)


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


if __name__ == '__main__':
print('to test use test.py %s' % __file__)
15 changes: 15 additions & 0 deletions src/lxml/xpath.pxi
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
6 changes: 6 additions & 0 deletions src/lxml/xslt.pxi
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down
Loading