hivesolutions/appier

Invalid escape sequences

Closed this issue · 1 comments

SyntaxWarning: invalid escape sequence

Performing system checks...
System check identified no issues (0 silenced).
March 19, 2024 - 17:10:56
Django version 5.0.2
Starting development server at http://0.0.0.0:8000/
Quit the server with CONTROL-C.
/usr/local/lib/python3.12/site-packages/appier/base.py:197: SyntaxWarning: invalid escape sequence '\('
  REPLACE_REGEX = re.compile("(?<!\(\?P)\<((\w+)(\([\"'].*?[\"']\))?:)?(\w+)\>")
/usr/local/lib/python3.12/site-packages/appier/base.py:203: SyntaxWarning: invalid escape sequence '\<'
  INT_REGEX = re.compile("\<int:(\w+)\>")
/usr/local/lib/python3.12/site-packages/appier/base.py:207: SyntaxWarning: invalid escape sequence '\<'
  REGEX_REGEX = re.compile("\<regex\([\"'](.*?)[\"']\):(\w+)\>")
/usr/local/lib/python3.12/site-packages/appier/base.py:220: SyntaxWarning: invalid escape sequence '\('
  CSS_ABS_REGEX = re.compile(b"url\((?!(http:\/\/|https:\/\/|\/\/|\/))([^\)]+)\)")
/usr/local/lib/python3.12/site-packages/appier/validation.py:40: SyntaxWarning: invalid escape sequence '\:'
  SIMPLE_REGEX_VALUE = "^[\:\.\s\w-]+$"
/usr/local/lib/python3.12/site-packages/appier/validation.py:45: SyntaxWarning: invalid escape sequence '\w'
  EMAIL_REGEX_VALUE = "^[\w\d\._%+-]+@[\w\d\.\-]+$"
/usr/local/lib/python3.12/site-packages/appier/validation.py:50: SyntaxWarning: invalid escape sequence '\w'
  "^\w+\:\/\/([^@]+\:[^@]+@)?[^\:\/\?#]+(\:\d+)?(\/[^\?#]+)*\/?(\?[^#]*)?(#.*)?$"
Watching for file changes with StatReloader
/usr/local/lib/python3.12/site-packages/appier/util.py:1101: SyntaxWarning: invalid escape sequence '\`'
  """
/usr/local/lib/python3.12/site-packages/appier/base.py:197: SyntaxWarning: invalid escape sequence '\('
  REPLACE_REGEX = re.compile("(?<!\(\?P)\<((\w+)(\([\"'].*?[\"']\))?:)?(\w+)\>")
/usr/local/lib/python3.12/site-packages/appier/base.py:203: SyntaxWarning: invalid escape sequence '\<'
  INT_REGEX = re.compile("\<int:(\w+)\>")
/usr/local/lib/python3.12/site-packages/appier/base.py:207: SyntaxWarning: invalid escape sequence '\<'
  REGEX_REGEX = re.compile("\<regex\([\"'](.*?)[\"']\):(\w+)\>")
/usr/local/lib/python3.12/site-packages/appier/base.py:220: SyntaxWarning: invalid escape sequence '\('
  CSS_ABS_REGEX = re.compile(b"url\((?!(http:\/\/|https:\/\/|\/\/|\/))([^\)]+)\)")
/usr/local/lib/python3.12/site-packages/appier/validation.py:40: SyntaxWarning: invalid escape sequence '\:'
  SIMPLE_REGEX_VALUE = "^[\:\.\s\w-]+$"
/usr/local/lib/python3.12/site-packages/appier/validation.py:45: SyntaxWarning: invalid escape sequence '\w'
  EMAIL_REGEX_VALUE = "^[\w\d\._%+-]+@[\w\d\.\-]+$"
/usr/local/lib/python3.12/site-packages/appier/validation.py:50: SyntaxWarning: invalid escape sequence '\w'
  "^\w+\:\/\/([^@]+\:[^@]+@)?[^\:\/\?#]+(\:\d+)?(\/[^\?#]+)*\/?(\?[^#]*)?(#.*)?$"
[19/Mar/2024 17:11:00] "GET /api/rgp/list HTTP/1.1" 200 820
/usr/local/lib/python3.12/site-packages/appier/util.py:1101: SyntaxWarning: invalid escape sequence '\`'
  """
/usr/local/lib/python3.12/site-packages/appier/base.py:197: SyntaxWarning: invalid escape sequence '\('
  REPLACE_REGEX = re.compile("(?<!\(\?P)\<((\w+)(\([\"'].*?[\"']\))?:)?(\w+)\>")
/usr/local/lib/python3.12/site-packages/appier/base.py:203: SyntaxWarning: invalid escape sequence '\<'
  INT_REGEX = re.compile("\<int:(\w+)\>")
/usr/local/lib/python3.12/site-packages/appier/base.py:207: SyntaxWarning: invalid escape sequence '\<'
  REGEX_REGEX = re.compile("\<regex\([\"'](.*?)[\"']\):(\w+)\>")
/usr/local/lib/python3.12/site-packages/appier/base.py:220: SyntaxWarning: invalid escape sequence '\('
  CSS_ABS_REGEX = re.compile(b"url\((?!(http:\/\/|https:\/\/|\/\/|\/))([^\)]+)\)")
/usr/local/lib/python3.12/site-packages/appier/validation.py:40: SyntaxWarning: invalid escape sequence '\:'
  SIMPLE_REGEX_VALUE = "^[\:\.\s\w-]+$"
/usr/local/lib/python3.12/site-packages/appier/validation.py:45: SyntaxWarning: invalid escape sequence '\w'
  EMAIL_REGEX_VALUE = "^[\w\d\._%+-]+@[\w\d\.\-]+$"
/usr/local/lib/python3.12/site-packages/appier/validation.py:50: SyntaxWarning: invalid escape sequence '\w'
  "^\w+\:\/\/([^@]+\:[^@]+@)?[^\:\/\?#]+(\:\d+)?(\/[^\?#]+)*\/?(\?[^#]*)?(#.*)?$"

The regex errors come from the use of "invalid escape sequences" in regex patterns defined within the appier library. In Python 3.6 and later, sequences like (, <, and : in regular expressions should be either double escaped (e.g., \() or, preferably, raw string literals should be used by prefixing the string with r, to avoid these warnings. This is because such sequences are not valid Python string escape sequences, and starting from Python 3.6, a SyntaxWarning is raised for these.

Here's an example to illustrate the adjustment:

Original code in appier that might be causing warnings:

REPLACE_REGEX = re.compile("(?<!\(\?P)\<((\w+)(\([\"'].*?[\"']\))?:)?(\w+)\>")

Adjusted code using a raw string literal:

REPLACE_REGEX = re.compile(r"(?<!\(\?P)\<((\w+)(\([\"'].*?[\"']\))?:)?(\w+)\>")

@daz-williams should be fixed by #64