Avoid a warning about regex flags in Python 3.6

Python 3.6 deprecated using regex flag syntax (?x) to set flags in the
middle of a pattern. Now you can only use it at the start of a pattern.
Fortunately that same release added a new scoped-flag syntax, (?x:).

(Wait, you say, it looks like our code *does* set flags at the start of
the pattern? That's true, but the markdown module includes our regex in the
middle of a larger one, so it's not actually at the start.)

Fixes this warning (and a couple similar ones):

DeprecationWarning: Flags not at the start of the expression '^(.?)(?x) \[ ([^]]' (truncated)
    self.compiled_re = re.compile(r"^(.?)%s(.)$" % pattern
This commit is contained in:
Andrew Ekstedt 2021-03-20 00:19:12 -07:00
parent 348742fe2a
commit 2faa3ed6af

View file

@ -11,6 +11,7 @@ which case it is replaced by the name of the thing linked to.
""" """
from __future__ import absolute_import from __future__ import absolute_import
import sys
import re import re
import markdown import markdown
@ -159,7 +160,10 @@ class PokedexLinkPattern(markdown.inlinepatterns.Pattern):
Handles matches using factory Handles matches using factory
""" """
regex = u'(?x) \\[ ([^]]*) \\] \\{ ([-a-z0-9]+) : ([-a-z0-9 ]+) \\}' if sys.version_info >= (3, 6):
regex = u'(?x: \\[ ([^]]*) \\] \\{ ([-a-z0-9]+) : ([-a-z0-9 ]+) \\} )'
else:
regex = u'(?x) \\[ ([^]]*) \\] \\{ ([-a-z0-9]+) : ([-a-z0-9 ]+) \\}'
def __init__(self, factory, session, string_language=None, game_language=None): def __init__(self, factory, session, string_language=None, game_language=None):
markdown.inlinepatterns.Pattern.__init__(self, self.regex) markdown.inlinepatterns.Pattern.__init__(self, self.regex)