plone / Products.PortalTransforms

Provides MIME types based transformation chains on Plone Archetypes contents
4 stars 15 forks source link

Regular expression errors on Python 3.11 #48

Closed mauritsvanrees closed 1 year ago

mauritsvanrees commented 1 year ago

See Jenkins.

Error in test testCall (Products.PortalTransforms.tests.test_engine.TestEngine.testCall)
Traceback (most recent call last):
  File "/srv/python3.11/lib/python3.11/unittest/case.py", line 57, in testPartExecutor
    yield
  File "/srv/python3.11/lib/python3.11/unittest/case.py", line 623, in run
    self._callTestMethod(testMethod)
  File "/srv/python3.11/lib/python3.11/unittest/case.py", line 579, in _callTestMethod
    if method() is not None:
  File "/home/jenkins/workspace/plone-6.0-python-3.11/src/Products.PortalTransforms/Products/PortalTransforms/tests/test_engine.py", line 153, in testCall
    data = self.engine('HtmlToText', self.data)
  File "/home/jenkins/workspace/plone-6.0-python-3.11/src/Products.PortalTransforms/Products/PortalTransforms/TransformEngine.py", line 222, in __call__
    data = self.convert(name, orig, data, context, **kwargs)
  File "/home/jenkins/workspace/plone-6.0-python-3.11/src/Products.PortalTransforms/Products/PortalTransforms/TransformEngine.py", line 210, in convert
    data = transform.convert(orig, data, context=context, **kwargs)
  File "/home/jenkins/workspace/plone-6.0-python-3.11/src/Products.PortalTransforms/Products/PortalTransforms/Transform.py", line 202, in convert
    return self._v_transform.convert(*args, **kwargs)
  File "/home/jenkins/workspace/plone-6.0-python-3.11/src/Products.PortalTransforms/Products/PortalTransforms/tests/test_engine.py", line 29, in convert
    orig = self.__call__(orig)
  File "/home/jenkins/workspace/plone-6.0-python-3.11/src/Products.PortalTransforms/Products/PortalTransforms/tests/test_engine.py", line 25, in __call__
    orig = re.sub('<[^>]*>(?i)(?m)', '', orig)
  File "/srv/python3.11/lib/python3.11/re/__init__.py", line 185, in sub
    return _compile(pattern, flags).sub(repl, string, count)
  File "/srv/python3.11/lib/python3.11/re/__init__.py", line 294, in _compile
    p = _compiler.compile(pattern, flags)
  File "/srv/python3.11/lib/python3.11/re/_compiler.py", line 743, in compile
    p = _parser.parse(p, flags)
  File "/srv/python3.11/lib/python3.11/re/_parser.py", line 980, in parse
    p = _parse_sub(source, state, flags & SRE_FLAG_VERBOSE, 0)
  File "/srv/python3.11/lib/python3.11/re/_parser.py", line 455, in _parse_sub
    itemsappend(_parse(source, state, verbose, nested + 1,
  File "/srv/python3.11/lib/python3.11/re/_parser.py", line 841, in _parse
    raise source.error('global flags not at the start '
re.error: global flags not at the start of the expression at position 7

In Python 3.10 you can already see a deprecation warning:

>>> import re
>>> re.sub(r'<[^>]*>(?i)(?m)', '', '')
<stdin>:1: DeprecationWarning: Flags not at the start of the expression '<[^>]*>(?i)(?m)' but at position 7
<stdin>:1: DeprecationWarning: Flags not at the start of the expression '<[^>]*>(?i)(?m)' but at position 11

Solution:

>>> import re
>>> re.sub(r'(?i)(?m)<[^>]*>', '', '')