Fix multiple confusingly escaped regex strings
Python (prior to 3.8) treats meaningless string escape sequences as if they were a slash followed by the character. That is, '\w' == '\\w'. Python 3.8 rejects this, and it's confusing. This change fixes seven of these regex strings found in depot_tools (through a regex search, natch). Most of the fixes don't actually change the value of the strings, and this was manually verified: >>> '(/c(/.*/\+)?)?/(\d+)(/(\d+)?/?)?$' == r'(/c(/.*/\+)?)?/(\d+)(/(\d+)?/?)?$' True >>> '#\s*OWNERS_STATUS\s+=\s+(.+)$' == r'#\s*OWNERS_STATUS\s+=\s+(.+)$' True >>> 'COM\d' == r'COM\d' True >>> '^\s+Change-Id:\s*(\S+)$' == r'^\s+Change-Id:\s*(\S+)$' True >>> 'ETag:\s+([a-z0-9]{32})' == r'ETag:\s+([a-z0-9]{32})' True Two exceptions were the regex expressions in filter_demo_output.py and scm.py. These were turned into raw strings despite this changing the value of the string passed to re. This works because re supports the \x, \d, \w, \t, and other escape sequences needed to make this work. TL;DR - use raw strings for regex to avoid melting your brain. If bulk changing regex strings to raw watch out for double-slashes. Bug: 958138 Change-Id: Ic45264cfc63e8bae9cfcffe2cd88a57c2d3dcdae Reviewed-on: https://chromium-review.googlesource.com/c/chromium/tools/depot_tools/+/1590534 Commit-Queue: Bruce Dawson <brucedawson@chromium.org> Reviewed-by: Dirk Pranke <dpranke@chromium.org>
Showing
Please
register
or
sign in
to comment