]> git.ipfire.org Git - thirdparty/tor.git/commitdiff
Use raw strings for regexs containing escapes
authorAlex Xu (Hello71) <alex_y_xu@yahoo.ca>
Sat, 9 Dec 2023 15:16:08 +0000 (10:16 -0500)
committerAlex Xu (Hello71) <alex_y_xu@yahoo.ca>
Sat, 9 Dec 2023 15:19:54 +0000 (10:19 -0500)
In Python 3.12, these invalid escape sequences emit SyntaxWarnings, and will
emit SyntaxErrors in a future release.

Found using: grep '[^r]["'\''].*\\[^rn\\x0t"]' $(grep -rl '^#!.*python')

scripts/codegen/get_mozilla_ciphers.py
scripts/maint/format_changelog.py
scripts/maint/lintChanges.py

index ff01dd8719f5a50983c19c526fba813711f709b0..65ef1aca2fb6f0f27cf759dffd136b798085f406 100755 (executable)
@@ -144,7 +144,7 @@ sslProto = open(ff('security/nss/lib/ssl/sslproto.h'), 'r')
 sslProtoD = {}
 
 for line in sslProto:
-    m = re.match('#define\s+(\S+)\s+(\S+)', line)
+    m = re.match(r'#define\s+(\S+)\s+(\S+)', line)
     if m:
         key, value = m.groups()
         sslProtoD[key] = value
@@ -165,7 +165,7 @@ for fl in oSSLinclude:
         continue
     fp = open(fname, 'r')
     for line in fp.readlines():
-        m = re.match('# *define\s+(\S+)\s+(\S+)', line)
+        m = re.match(r'# *define\s+(\S+)\s+(\S+)', line)
         if m:
             value,key = m.groups()
             if key.startswith('0x') and "_CK_" in value:
index 32b47ffcbb136146c4c8e98fa4bd9d3a50d85902..cab34ab75111b876dc98bec22b7fa50f8f30d1da 100755 (executable)
@@ -416,7 +416,7 @@ ISSUE_PREFIX_MAP = {
 }
 
 # Let's turn bugs to html.
-BUG_PAT = re.compile('(bug|ticket|issue|feature)\s+([\w/]+#)?(\d{4,6})', re.I)
+BUG_PAT = re.compile(r'(bug|ticket|issue|feature)\s+([\w/]+#)?(\d{4,6})', re.I)
 def bug_html(m):
     kind = m.group(1)
     prefix = m.group(2) or ""
index cf7b09fcc310f523fe47a7a53488e7ce6bb0f017..964feaed0a8df945719969644dcb0c7cd19943d9 100755 (executable)
@@ -51,7 +51,7 @@ def split_tor_version(version):
 
     If the version is malformed, returns None.
     '''
-    version_match = re.match('([0-9]+)\.([0-9]+)\.([0-9]+)(\.([0-9]+))?', version)
+    version_match = re.match(r'([0-9]+)\.([0-9]+)\.([0-9]+)(\.([0-9]+))?', version)
     if version_match is None:
         return None
 
@@ -120,13 +120,13 @@ def lintfile(fname):
     if re.search(r'[bB]ug (\d+)', contents):
         if not re.search(r'[Bb]ugfix on ', contents):
             warn("Bugfix does not say 'bugfix on X.Y.Z'")
-        elif not re.search('[fF]ixes ([a-z ]*)bugs? (\d+)((, \d+)* and \d+)?; bugfix on ',
+        elif not re.search(r'[fF]ixes ([a-z ]*)bugs? (\d+)((, \d+)* and \d+)?; bugfix on ',
                            contents):
             warn("Bugfix does not say 'Fixes bug X; bugfix on Y'")
         elif re.search('tor-([0-9]+)', contents):
             warn("Do not prefix versions with 'tor-'. ('0.1.2', not 'tor-0.1.2'.)")
         else:
-            bugfix_match = re.search('bugfix on ([0-9]+\.[0-9]+\.[0-9]+)', contents)
+            bugfix_match = re.search(r'bugfix on ([0-9]+\.[0-9]+\.[0-9]+)', contents)
             if bugfix_match is None:
                 warn("Versions must have at least 3 digits. ('0.1.2', '0.3.4.8', or '0.3.5.1-alpha'.)")
             elif bugfix_match.group(0) is None: