Files
macports-ports/python/py-libxml2/files/python2.patch
2026-03-28 10:50:22 -05:00

62 lines
2.5 KiB
Diff

Restore Python 2 compatibility in Python bindings.
Fixes:
failed to find and generate stubs for libxml2, aborting ...
(<type 'exceptions.SyntaxError'>, SyntaxError('invalid syntax', ('/opt/local/var/macports/build/py27-libxml2-116ed89d/work/libxml2-2.15.2/python/generator.py', 360, 61, " raise Exception(f'Doxygen XML not found in {dstPref}')\n")))
failed to find and generate stubs for libxml2, aborting ...
(<type 'exceptions.LookupError'>, LookupError('unknown encoding: unicode',))
This patch was created with the awk and sed scripts posted here:
https://trac.macports.org/ticket/73605#comment:11
--- generator.py.orig 2026-03-04 03:38:57.000000000 -0600
+++ generator.py 2026-03-28 10:11:33.000000000 -0500
@@ -357,7 +357,7 @@
if not os.path.isdir(xmlDocDir):
xmlDocDir = dstPref + '/doc/xml'
if not os.path.isdir(xmlDocDir):
- raise Exception(f'Doxygen XML not found in {dstPref}')
+ raise Exception('Doxygen XML not found in %s' % dstPref)
def extractDocs(node):
text = ''
@@ -416,13 +416,13 @@
docs = extractDocs(func.find('detaileddescription'))
rtype = etree.tostring(func.find('type'),
- method='text', encoding='unicode').rstrip()
+ method='text', encoding='utf-8').rstrip()
valid = True
args = []
for arg in func.findall('param'):
atype = etree.tostring(arg.find('type'),
- method='text', encoding='unicode').rstrip()
+ method='text', encoding='utf-8').rstrip()
if atype == 'void':
continue
@@ -440,9 +440,9 @@
cond = None
if module1 != '':
- cond = f'defined(LIBXML_{module1}_ENABLED)'
+ cond = 'defined(LIBXML_%s_ENABLED)' % module1
if module2 != '':
- cond += f' && defined(LIBXML_{module2}_ENABLED)'
+ cond += ' && defined(LIBXML_%s_ENABLED)' % module2
functions[name] = (docs, [rtype], args, module, cond)
elif kind == 'enum':
@@ -461,7 +461,7 @@
else:
evalue = init.text.lstrip()
if evalue[0] != '=':
- raise Exception(f'invalid init value {init}')
+ raise Exception('invalid init value %s' % init)
evalue = eval(evalue[1:].strip())
edict[ename] = evalue