From 2021c6d501dab6c48556fa057f3d077433dbe12c Mon Sep 17 00:00:00 2001 From: Teal Dulcet Date: Sun, 12 Jan 2025 07:27:27 -0800 Subject: [PATCH] Fixed RUF039 (unraw-re-pattern) --- management/ssl_certificates.py | 2 +- management/status_checks.py | 4 ++-- management/web_update.py | 2 +- tests/tls.py | 8 ++++---- tools/readable_bash.py | 8 ++++---- 5 files changed, 12 insertions(+), 12 deletions(-) diff --git a/management/ssl_certificates.py b/management/ssl_certificates.py index 49fe06c7..27ecdc79 100755 --- a/management/ssl_certificates.py +++ b/management/ssl_certificates.py @@ -635,7 +635,7 @@ def load_pem(pem): from cryptography.x509 import load_pem_x509_certificate from cryptography.hazmat.primitives import serialization from cryptography.hazmat.backends import default_backend - pem_type = re.match(b"-+BEGIN (.*?)-+[\r\n]", pem) + pem_type = re.match(br"-+BEGIN (.*?)-+[\r\n]", pem) if pem_type is None: msg = "File is not a valid PEM-formatted file." raise ValueError(msg) diff --git a/management/status_checks.py b/management/status_checks.py index 53c75fc2..e0cc7b07 100755 --- a/management/status_checks.py +++ b/management/status_checks.py @@ -947,7 +947,7 @@ def get_latest_miab_version(): from urllib.request import urlopen, HTTPError, URLError try: - return re.search(b'TAG=(.*)', urlopen("https://mailinabox.email/setup.sh?ping=1", timeout=5).read()).group(1).decode("utf8") + return re.search(br'TAG=(.*)', urlopen("https://mailinabox.email/setup.sh?ping=1", timeout=5).read()).group(1).decode("utf8") except (TimeoutError, HTTPError, URLError): return None @@ -1074,7 +1074,7 @@ class FileOutput: def print_block(self, message, first_line=" "): print(first_line, end='', file=self.buf) - message = re.sub("\n\\s*", " ", message) + message = re.sub(r"\n\s*", " ", message) words = re.split(r"(\s+)", message) linelen = 0 for w in words: diff --git a/management/web_update.py b/management/web_update.py index 98fbe3e0..776bc1dd 100644 --- a/management/web_update.py +++ b/management/web_update.py @@ -223,7 +223,7 @@ def make_domain_config(domain, templates, ssl_certificates, env): # of the previous template. nginx_conf = "# ADDITIONAL DIRECTIVES HERE\n" for t in [*templates, nginx_conf_extra]: - nginx_conf = re.sub("[ \t]*# ADDITIONAL DIRECTIVES HERE *\n", t, nginx_conf) + nginx_conf = re.sub(r"[ \t]*# ADDITIONAL DIRECTIVES HERE *\n", t, nginx_conf) # Replace substitution strings in the template & return. nginx_conf = nginx_conf.replace("$STORAGE_ROOT", env['STORAGE_ROOT']) diff --git a/tests/tls.py b/tests/tls.py index 89e1dae5..317ea611 100644 --- a/tests/tls.py +++ b/tests/tls.py @@ -94,8 +94,8 @@ def sslyze(opts, port, ok_ciphers): # Trim output to make better for storing in git. if "SCAN RESULTS FOR" not in out: # Failed. Just output the error. - out = re.sub("[\\w\\W]*CHECKING HOST\\(S\\) AVAILABILITY\n\\s*-+\n", "", out) # chop off header that shows the host we queried - out = re.sub("[\\w\\W]*SCAN RESULTS FOR.*\n\\s*-+\n", "", out) # chop off header that shows the host we queried + out = re.sub(r"[\w\W]*CHECKING HOST\(S\) AVAILABILITY\n\s*-+\n", "", out) # chop off header that shows the host we queried + out = re.sub(r"[\w\W]*SCAN RESULTS FOR.*\n\s*-+\n", "", out) # chop off header that shows the host we queried out = re.sub(r"SCAN COMPLETED IN .*", "", out) out = out.rstrip(" \n-") + "\n" @@ -105,8 +105,8 @@ def sslyze(opts, port, ok_ciphers): # Pull out the accepted ciphers list for each SSL/TLS protocol # version outputted. accepted_ciphers = set() - for ciphers in re.findall(" Accepted:([\\w\\W]*?)\n *\n", out): - accepted_ciphers |= set(re.findall("\n\\s*(\\S*)", ciphers)) + for ciphers in re.findall(r" Accepted:([\w\W]*?)\n *\n", out): + accepted_ciphers |= set(re.findall(r"\n\s*(\S*)", ciphers)) # Compare to what Mozilla recommends, for a given modernness-level. print(" Should Not Offer: " + (", ".join(sorted(accepted_ciphers-set(ok_ciphers))) or "(none -- good)")) diff --git a/tools/readable_bash.py b/tools/readable_bash.py index fe7a2c8a..e4874138 100644 --- a/tools/readable_bash.py +++ b/tools/readable_bash.py @@ -363,9 +363,9 @@ def quasitokenize(bashscript): newscript += c # "<< EOF" escaping. - if quote_mode is None and re.search("<<\\s*EOF\n$", newscript): + if quote_mode is None and re.search(r"<<\s*EOF\n$", newscript): quote_mode = "EOF" - elif quote_mode == "EOF" and re.search("\nEOF\n$", newscript): + elif quote_mode == "EOF" and re.search(r"\nEOF\n$", newscript): quote_mode = None return newscript @@ -405,8 +405,8 @@ class BashScript(Grammar): string = f.read() # tokenize - string = re.sub(".* #NODOC\n", "", string) - string = re.sub("\n\\s*if .*then.*|\n\\s*fi|\n\\s*else|\n\\s*elif .*", "", string) + string = re.sub(r".* #NODOC\n", "", string) + string = re.sub(r"\n\s*if .*then.*|\n\s*fi|\n\s*else|\n\s*elif .*", "", string) string = quasitokenize(string) string = string.replace("hide_output ", "")