ruff: Fix FURB167 Use of regular expression alias.

Signed-off-by: Anders Kaseorg <anders@zulip.com>
This commit is contained in:
Anders Kaseorg 2024-06-30 14:29:07 -04:00 committed by Tim Abbott
parent 6a73006723
commit 5af8dfda3e
7 changed files with 11 additions and 10 deletions

View File

@ -147,7 +147,7 @@ NGINX_LOG_LINE_RE = re.compile(
(?P<hostname> \S+ ) \s+ (?P<hostname> \S+ ) \s+
(?P<duration> \S+ ) (?P<duration> \S+ )
""", """,
re.X, re.VERBOSE,
) )
PYTHON_LOG_LINE_RE = re.compile( PYTHON_LOG_LINE_RE = re.compile(
@ -178,7 +178,7 @@ PYTHON_LOG_LINE_RE = re.compile(
) \s+ via \s+ (?P<user_agent> .* ) ) \s+ via \s+ (?P<user_agent> .* )
\) \)
""", """,
re.X, re.VERBOSE,
) )

View File

@ -43,7 +43,7 @@ def is_outdated_server(user_profile: Optional[UserProfile]) -> bool:
def pop_numerals(ver: str) -> Tuple[List[int], str]: 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: if match is None:
return [], ver return [], ver
numerals, rest = match.groups() 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]: 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" 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 "ios"
return None return None

View File

@ -27,7 +27,7 @@ class IncludeExtension(Extension):
class IncludeBlockProcessor(BlockProcessor): 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: def __init__(self, parser: BlockParser, base_path: str) -> None:
super().__init__(parser) super().__init__(parser)

View File

@ -9,7 +9,7 @@ pattern = re.compile(
(/ (?P<version> [^/ ]* ))? (/ (?P<version> [^/ ]* ))?
([ /] .*)? ([ /] .*)?
$""", $""",
re.X, re.VERBOSE,
) )

View File

@ -11,7 +11,7 @@ attachment_url_re = re.compile(r"[/\-]user[\-_]uploads[/\.-].*?(?=[ )]|\Z)")
def attachment_url_to_path_id(attachment_url: str) -> str: def attachment_url_to_path_id(attachment_url: str) -> str:
path_id_raw = re.sub(r"[/\-]user[\-_]uploads[/\.-]", "", attachment_url) path_id_raw = re.sub(r"[/\-]user[\-_]uploads[/\.-]", "", attachment_url)
# Remove any extra '.' after file extension. These are probably added by the user # 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: def check_and_create_attachments(apps: StateApps, schema_editor: BaseDatabaseSchemaEditor) -> None:

View File

@ -170,7 +170,7 @@ def render_javascript_code_example(
) -> List[str]: ) -> List[str]:
pattern = rf'^add_example\(\s*"[^"]*",\s*{re.escape(json.dumps(function))},\s*\d+,\s*async \(client, console\) => \{{\n(.*?)^(?:\}}| *\}},\n)\);$' 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: 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: if m is None:
return [] return []
function_source_lines = dedent(m.group(1)).splitlines() function_source_lines = dedent(m.group(1)).splitlines()

View File

@ -17,7 +17,8 @@ if os.path.exists("/etc/zulip/sharding.json"):
data, # backwards compatibility data, # backwards compatibility
) )
shard_regexes = [ 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", [])
] ]