mirror of
https://github.com/home-assistant/core.git
synced 2025-07-26 22:57:17 +00:00
Simplify unnecessary re.findall calls (#147907)
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
This commit is contained in:
parent
ca85ffc068
commit
dcad5bbe04
@ -65,12 +65,10 @@ def download_file(service: ServiceCall) -> None:
|
||||
|
||||
else:
|
||||
if filename is None and "content-disposition" in req.headers:
|
||||
match = re.findall(
|
||||
if match := re.search(
|
||||
r"filename=(\S+)", req.headers["content-disposition"]
|
||||
)
|
||||
|
||||
if match:
|
||||
filename = match[0].strip("'\" ")
|
||||
):
|
||||
filename = match.group(1).strip("'\" ")
|
||||
|
||||
if not filename:
|
||||
filename = os.path.basename(url).strip()
|
||||
|
@ -48,11 +48,8 @@ def add_new_outputs(
|
||||
|
||||
def format_ref_id(ref_id: str) -> str | None:
|
||||
"""Format the Qbus ref_id."""
|
||||
matches: list[str] = re.findall(_REFID_REGEX, ref_id)
|
||||
|
||||
if len(matches) > 0:
|
||||
if ref_id := matches[0]:
|
||||
return ref_id.replace("/", "-")
|
||||
if match := _REFID_REGEX.search(ref_id):
|
||||
return match.group(1).replace("/", "-")
|
||||
|
||||
return None
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user