Make the regex python 3.11 compatible#313
Conversation
|
Thanks for your commits, it worked! |
|
Thanks, it worked! |
|
@attardi As python 3.12 is the latest version, people might want to use 3.11 or 3.12. Gentle ping to merge and release new version. Thanks! |
|
Does the regular expression do what it was supposed to do? I think the proposed change does not change the behavior, so it would be correct, but I am not sure if the regular expression was originally supposed to do something different. If I understand the documentation for Since in this code's regular expression it is listed in a sub group, it looks to me like the original author might have (wrongly) tried to make only this sub group case insensitive. If that's the case I think
If indeed case-insensitivity for the whole regular expression is desired, I'd propose to rather use the compile flag
ExtLinkBracketedRegex = re.compile(
'\[((' + '|'.join(wgUrlProtocols) + ')' + EXT_LINK_URL_CLASS + r'+)\s*([^\]\x00-\x08\x0a-\x1F]*?)\]',
re.S | re.U | re.I)
EXT_IMAGE_REGEX = re.compile(
r"""^(http://|https://)([^][<>"\x00-\x20\x7F\s]+)
/([A-Za-z0-9_.,~%\-+&;#*?!=()@\x80-\xFF]+)\.(gif|png|jpg|jpeg)$""",
re.X | re.S | re.U | re.I)Update: Looking at both regular expression, I'd say the global version seems right. Even if the original code looks like the author intended to only make parts of the expression case-insensitive. Let's assume the original author indeed only wanted to make parts of the expressions case-insensitive. Then in |
|
Thanks for your commits, it worked! |
Python 3.11 throws the error: re.error: global flags not at the start of the expression at position
Ref: https://bugs.python.org/issue47066