From 5af8dfda3edd5d255ecb2cd7814923daaaf0d0cc Mon Sep 17 00:00:00 2001 From: Anders Kaseorg Date: Sun, 30 Jun 2024 14:29:07 -0400 Subject: [PATCH] ruff: Fix FURB167 Use of regular expression alias. Signed-off-by: Anders Kaseorg --- scripts/log-search | 4 ++-- zerver/lib/compatibility.py | 6 +++--- zerver/lib/markdown/include.py | 2 +- zerver/lib/user_agent.py | 2 +- .../migrations/0041_create_attachments_for_old_messages.py | 2 +- zerver/openapi/markdown_extension.py | 2 +- zerver/tornado/sharding.py | 3 ++- 7 files changed, 11 insertions(+), 10 deletions(-) diff --git a/scripts/log-search b/scripts/log-search index 2e52a8c4be..0bc488d29c 100755 --- a/scripts/log-search +++ b/scripts/log-search @@ -147,7 +147,7 @@ NGINX_LOG_LINE_RE = re.compile( (?P \S+ ) \s+ (?P \S+ ) """, - re.X, + re.VERBOSE, ) PYTHON_LOG_LINE_RE = re.compile( @@ -178,7 +178,7 @@ PYTHON_LOG_LINE_RE = re.compile( ) \s+ via \s+ (?P .* ) \) """, - re.X, + re.VERBOSE, ) diff --git a/zerver/lib/compatibility.py b/zerver/lib/compatibility.py index 912345454a..1c237cc91e 100644 --- a/zerver/lib/compatibility.py +++ b/zerver/lib/compatibility.py @@ -43,7 +43,7 @@ def is_outdated_server(user_profile: Optional[UserProfile]) -> bool: def pop_numerals(ver: str) -> Tuple[List[int], str]: - match = re.search(r"^( \d+ (?: \. \d+ )* ) (.*)", ver, re.X) + match = re.search(r"^( \d+ (?: \. \d+ )* ) (.*)", ver, re.VERBOSE) if match is None: return [], ver numerals, rest = match.groups() @@ -94,9 +94,9 @@ def version_lt(ver1: str, ver2: str) -> Optional[bool]: def find_mobile_os(user_agent: str) -> Optional[str]: - if re.search(r"\b Android \b", user_agent, re.I | re.X): + if re.search(r"\b Android \b", user_agent, re.IGNORECASE | re.VERBOSE): return "android" - if re.search(r"\b(?: iOS | iPhone\ OS )\b", user_agent, re.I | re.X): + if re.search(r"\b(?: iOS | iPhone\ OS )\b", user_agent, re.IGNORECASE | re.VERBOSE): return "ios" return None diff --git a/zerver/lib/markdown/include.py b/zerver/lib/markdown/include.py index 394181064e..b5bf68b162 100644 --- a/zerver/lib/markdown/include.py +++ b/zerver/lib/markdown/include.py @@ -27,7 +27,7 @@ class IncludeExtension(Extension): class IncludeBlockProcessor(BlockProcessor): - RE = re.compile(r"^ {,3}\{!([^!]+)!\} *$", re.M) + RE = re.compile(r"^ {,3}\{!([^!]+)!\} *$", re.MULTILINE) def __init__(self, parser: BlockParser, base_path: str) -> None: super().__init__(parser) diff --git a/zerver/lib/user_agent.py b/zerver/lib/user_agent.py index b80dc15dfc..28ec2720d4 100644 --- a/zerver/lib/user_agent.py +++ b/zerver/lib/user_agent.py @@ -9,7 +9,7 @@ pattern = re.compile( (/ (?P [^/ ]* ))? ([ /] .*)? $""", - re.X, + re.VERBOSE, ) diff --git a/zerver/migrations/0041_create_attachments_for_old_messages.py b/zerver/migrations/0041_create_attachments_for_old_messages.py index 6b8d593a19..838a21be8f 100644 --- a/zerver/migrations/0041_create_attachments_for_old_messages.py +++ b/zerver/migrations/0041_create_attachments_for_old_messages.py @@ -11,7 +11,7 @@ attachment_url_re = re.compile(r"[/\-]user[\-_]uploads[/\.-].*?(?=[ )]|\Z)") def attachment_url_to_path_id(attachment_url: str) -> str: path_id_raw = re.sub(r"[/\-]user[\-_]uploads[/\.-]", "", attachment_url) # Remove any extra '.' after file extension. These are probably added by the user - return re.sub(r"[.]+$", "", path_id_raw, flags=re.M) + return re.sub(r"[.]+$", "", path_id_raw, flags=re.MULTILINE) def check_and_create_attachments(apps: StateApps, schema_editor: BaseDatabaseSchemaEditor) -> None: diff --git a/zerver/openapi/markdown_extension.py b/zerver/openapi/markdown_extension.py index d5310c8d06..1cac209885 100644 --- a/zerver/openapi/markdown_extension.py +++ b/zerver/openapi/markdown_extension.py @@ -170,7 +170,7 @@ def render_javascript_code_example( ) -> List[str]: pattern = rf'^add_example\(\s*"[^"]*",\s*{re.escape(json.dumps(function))},\s*\d+,\s*async \(client, console\) => \{{\n(.*?)^(?:\}}| *\}},\n)\);$' with open("zerver/openapi/javascript_examples.js") as f: - m = re.search(pattern, f.read(), re.M | re.S) + m = re.search(pattern, f.read(), re.MULTILINE | re.DOTALL) if m is None: return [] function_source_lines = dedent(m.group(1)).splitlines() diff --git a/zerver/tornado/sharding.py b/zerver/tornado/sharding.py index f12b571d92..f876e06d9c 100644 --- a/zerver/tornado/sharding.py +++ b/zerver/tornado/sharding.py @@ -17,7 +17,8 @@ if os.path.exists("/etc/zulip/sharding.json"): data, # backwards compatibility ) shard_regexes = [ - (re.compile(regex, re.I), port) for regex, port in data.get("shard_regexes", []) + (re.compile(regex, re.IGNORECASE), port) + for regex, port in data.get("shard_regexes", []) ]