linuxmint/xed

Python3 Regex Syntax Warning

cdillond opened this issue · 0 comments

 * Xed version - Version 3.4.5
 * Distribution - Fedora 39

Issue
Opening xed from the command line results in the following warning:

usr/lib64/xed/plugins/open-uri-context-menu/open-uri-context-menu.py:33: SyntaxWarning: invalid escape sequence '\?'
RE_URI_RFC2396 = re.compile("((([a-zA-Z][0-9a-zA-Z+\\-\\.]*):)?/{0,2}([0-9a-zA-Z;:,/\?@&=\+\$\.\-_!~\*'\(\)%]+))?(#[0-9a-zA-Z;,/\?:@&\=+$\.\\-_!~\*'\(\)%]+)?")

Steps to reproduce
Run xed from the command line.

Expected behaviour

No warning.

Other information
The python re library documentation notes:

Regular expressions use the backslash character ('\') to indicate special forms or to allow special characters to be used without invoking their special meaning. This collides with Python’s usage of the same character for the same purpose in string literals; for example, to match a literal backslash, one might have to write '\\\\' as the pattern string, because the regular expression must be \\, and each backslash must be expressed as \\ inside a regular Python string literal. Also, please note that any invalid escape sequences in Python’s usage of the backslash in string literals now generate a SyntaxWarning and in the future this will become a SyntaxError. This behaviour will happen even if it is a valid escape sequence for a regular expression.

The string literal in this line
RE_URI_RFC2396 = re.compile("((([a-zA-Z][0-9a-zA-Z+\\-\\.]*):)?/{0,2}([0-9a-zA-Z;:,/\?@&=\+\$\.\-_!~\*'\(\)%]+))?(#[0-9a-zA-Z;,/\?:@&\=+$\.\\-_!~\*'\(\)%]+)?")
should instead be a raw string. The \\-\\ part also seems redundant to me, so the line could instead be:
RE_URI_RFC2396 = re.compile(r"((([a-zA-Z][0-9a-zA-Z+\\.]*):)?/{0,2}([0-9a-zA-Z;:,/\?@&=\+\$\.\-_!~\*'\(\)%]+))?(#[0-9a-zA-Z;,/\?:@&\=+$\.\\-_!~\*'\(\)%]+)?")