Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix invalid escape sequences #639

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

meator
Copy link

@meator meator commented Apr 13, 2024

When trying to run

python -m compileall -q <dir>

on this project (as the XBPS package manager does), a lot of SyntaxWarning: invalid escape sequence warnings are spewed:

./future/backports/email/_header_value_parser.py:662: SyntaxWarning: invalid escape sequence '\('
  '(', '\(').replace(
./future/backports/email/_header_value_parser.py:663: SyntaxWarning: invalid escape sequence '\)'
  ')', '\)')
./future/backports/email/_header_value_parser.py:1349: SyntaxWarning: invalid escape sequence '\]'
  ''.join(ATOM_ENDS).replace('\\','\\\\').replace(']','\]'))).match
./future/backports/email/_header_value_parser.py:1352: SyntaxWarning: invalid escape sequence '\]'
  ''.join(TOKEN_ENDS).replace('\\','\\\\').replace(']','\]'))).match
./future/backports/email/_header_value_parser.py:1354: SyntaxWarning: invalid escape sequence '\]'
  ''.join(ATTRIBUTE_ENDS).replace('\\','\\\\').replace(']','\]'))).match
./future/backports/email/_header_value_parser.py:1357: SyntaxWarning: invalid escape sequence '\]'
  '\\','\\\\').replace(']','\]'))).match
./future/backports/email/_header_value_parser.py:1541: SyntaxWarning: invalid escape sequence '\ '
  """ctext = <printable ascii except \ ( )>
./future/backports/email/_header_value_parser.py:1876: SyntaxWarning: invalid escape sequence '\ '
  """ dtext = <printable ascii except \ [ ]> / obs-dtext
./future/backports/email/feedparser.py:37: SyntaxWarning: invalid escape sequence '\Z'
  NLCRE_eol = re.compile('(\r\n|\r|\n)\Z')
./future/backports/email/utils.py:68: SyntaxWarning: invalid escape sequence '\A'
  '([^\ud800-\udbff]|\A)[\udc00-\udfff]([^\udc00-\udfff]|\Z)').search
./future/backports/html/parser.py:31: SyntaxWarning: invalid escape sequence '\s'
  tagfind = re.compile('([a-zA-Z][-.a-zA-Z0-9:_]*)(?:\s|/(?!>))*')
./future/backports/html/parser.py:79: SyntaxWarning: invalid escape sequence '\s'
  endtagfind = re.compile('</\s*([a-zA-Z][-.a-zA-Z0-9:_]*)\s*>')
./future/backports/http/client.py:1: SyntaxWarning: invalid escape sequence '\_'
  """HTTP/1.1 client library
./future/backports/http/cookiejar.py:212: SyntaxWarning: invalid escape sequence '\d'
  "(\d\d\d\d) (\d\d):(\d\d):(\d\d) GMT$", re.ASCII)
./future/backports/http/cookiejar.py:293: SyntaxWarning: invalid escape sequence '\d'
  """^
./future/backports/http/cookiejar.py:429: SyntaxWarning: invalid escape sequence '\s'
  non_junk, nr_junk_chars = re.subn("^[=\s;]*", "", text)
./future/backports/test/support.py:1945: SyntaxWarning: invalid escape sequence '\d'
  m = re.match("2.6.(\d{1,2})", kernel_version)
./future/backports/urllib/parse.py:957: SyntaxWarning: invalid escape sequence '\?'
  _queryprog = re.compile('^(.*)\?([^?]*)$')

This PR fixes all of them.

Comment on lines 35 to 38
NLCRE = re.compile('\r\n|\r|\n')
NLCRE_bol = re.compile('(\r\n|\r|\n)')
NLCRE_eol = re.compile('(\r\n|\r|\n)\Z')
NLCRE_eol = re.compile(r'(\r\n|\r|\n)\Z')
NLCRE_crack = re.compile('(\r\n|\r|\n)')
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These regexes look pretty broken to be honest. All of these should be raw string literals. There are probably more examples of this in the codebase.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

1 participant