1
1
mirror of https://github.com/dbcli/pgcli.git synced 2024-10-06 10:17:15 +03:00

Fix #595: use a double escape in the replacement argument to re.sub()

Starting with version 3.6 Python is getting stricter in which escape
sequences it accepts in string literals, so unknown codes must use a
double backslash.

This also use the sub() method on the compiled pattern, instead of
passing it to the "generic" re.sub() function.
This commit is contained in:
Lele Gaifax 2016-10-15 13:19:16 +02:00
parent 47d39660b6
commit 44ceb97522

View File

@ -11,7 +11,7 @@ white_space_regex = re.compile('\\s+', re.MULTILINE)
def _compile_regex(keyword):
# Surround the keyword with word boundaries and replace interior whitespace
# with whitespace wildcards
pattern = '\\b' + re.sub(white_space_regex, '\\s+', keyword) + '\\b'
pattern = '\\b' + white_space_regex.sub(r'\\s+', keyword) + '\\b'
return re.compile(pattern, re.MULTILINE | re.IGNORECASE)
keywords = get_literals('keywords')