Skip to content

Commit

Permalink
Provide compile time version of libiconv as "etree.ICONV_COMPILED_VER…
Browse files Browse the repository at this point in the history
…SION".
  • Loading branch information
scoder committed May 11, 2024
1 parent 1ab00bd commit ddaa6ed
Show file tree
Hide file tree
Showing 3 changed files with 40 additions and 17 deletions.
2 changes: 2 additions & 0 deletions CHANGES.txt
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@ Bugs fixed
* LP#2059910: The minimum CPU architecture for the Linux x86 binary wheels was set back to
"core2", without SSE 4.2.

* If libxml2 uses iconv, the compile time version is available as `etree.ICONV_COMPILED_VERSION`.


5.2.1 (2024-04-02)
==================
Expand Down
30 changes: 25 additions & 5 deletions src/lxml/etree.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -232,7 +232,7 @@ cdef class C14NError(LxmlError):
"""

# version information
cdef __unpackDottedVersion(version):
cdef tuple __unpackDottedVersion(version):
version_list = []
l = (version.decode("ascii").replace('-', '.').split('.') + [0]*4)[:4]
for item in l:
Expand All @@ -255,11 +255,11 @@ cdef __unpackDottedVersion(version):
version_list.append(item)
return tuple(version_list)

cdef __unpackIntVersion(int c_version):
cdef tuple __unpackIntVersion(int c_version, int base=100):
return (
((c_version // (100*100)) % 100),
((c_version // 100) % 100),
(c_version % 100)
((c_version // (base*base)) % base),
((c_version // base) % base),
(c_version % base)
)

cdef int _LIBXML_VERSION_INT
Expand All @@ -276,6 +276,26 @@ LXML_VERSION = __unpackDottedVersion(tree.LXML_VERSION_STRING)

__version__ = tree.LXML_VERSION_STRING.decode("ascii")

cdef extern from *:
"""
#ifdef ZLIB_VERNUM
#define __lxml_zlib_version (ZLIB_VERNUM >> 4)
#else
#define __lxml_zlib_version 0
#endif
#ifdef _LIBICONV_VERSION
#define __lxml_iconv_version (_LIBICONV_VERSION << 8)
#else
#define __lxml_iconv_version 0
#endif
"""
# zlib isn't included automatically by libxml2's headers
#long ZLIB_HEX_VERSION "__lxml_zlib_version"
long LIBICONV_HEX_VERSION "__lxml_iconv_version"

#ZLIB_COMPILED_VERSION = __unpackIntVersion(ZLIB_HEX_VERSION, base=0x10)
ICONV_COMPILED_VERSION = __unpackIntVersion(LIBICONV_HEX_VERSION, base=0x100)[:2]


# class for temporary storage of Python references,
# used e.g. for XPath results
Expand Down
25 changes: 13 additions & 12 deletions src/lxml/tests/test_etree.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,18 +28,19 @@
from .common_imports import canonicalize, _str, _bytes
from .common_imports import SimpleFSPath

print("""
TESTED VERSION: %s""" % etree.__version__ + """
Python: %r""" % (sys.version_info,) + """
lxml.etree: %r""" % (etree.LXML_VERSION,) + """
libxml used: %r""" % (etree.LIBXML_VERSION,) + """
libxml compiled: %r""" % (etree.LIBXML_COMPILED_VERSION,) + """
libxslt used: %r""" % (etree.LIBXSLT_VERSION,) + """
libxslt compiled: %r""" % (etree.LIBXSLT_COMPILED_VERSION,) + """
FS encoding: %s""" % (sys.getfilesystemencoding(),) + """
Default encoding: %s""" % (sys.getdefaultencoding(),) + """
Max Unicode: %s""" % (sys.maxunicode,) + """
PyUCS4 encoding: %s""" % (getattr(etree, '_pyucs4_encoding_name', ''),) + """
print(f"""
TESTED VERSION: {etree.__version__}
Python: {tuple(sys.version_info)!r}
lxml.etree: {etree.LXML_VERSION!r}
libxml used: {etree.LIBXML_VERSION!r}
libxml compiled: {etree.LIBXML_COMPILED_VERSION!r}
libxslt used: {etree.LIBXSLT_VERSION!r}
libxslt compiled: {etree.LIBXSLT_COMPILED_VERSION!r}
iconv compiled: {etree.ICONV_COMPILED_VERSION!r}
FS encoding: {sys.getfilesystemencoding()}
Default encoding: {sys.getdefaultencoding()}
Max Unicode: {sys.maxunicode}
PyUCS4 encoding: {getattr(etree, '_pyucs4_encoding_name', '')}
""")


Expand Down

0 comments on commit ddaa6ed

Please sign in to comment.