mirror of
https://github.com/home-assistant/core.git
synced 2025-07-27 15:17:35 +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:
|
else:
|
||||||
if filename is None and "content-disposition" in req.headers:
|
if filename is None and "content-disposition" in req.headers:
|
||||||
match = re.findall(
|
if match := re.search(
|
||||||
r"filename=(\S+)", req.headers["content-disposition"]
|
r"filename=(\S+)", req.headers["content-disposition"]
|
||||||
)
|
):
|
||||||
|
filename = match.group(1).strip("'\" ")
|
||||||
if match:
|
|
||||||
filename = match[0].strip("'\" ")
|
|
||||||
|
|
||||||
if not filename:
|
if not filename:
|
||||||
filename = os.path.basename(url).strip()
|
filename = os.path.basename(url).strip()
|
||||||
|
@ -48,11 +48,8 @@ def add_new_outputs(
|
|||||||
|
|
||||||
def format_ref_id(ref_id: str) -> str | None:
|
def format_ref_id(ref_id: str) -> str | None:
|
||||||
"""Format the Qbus ref_id."""
|
"""Format the Qbus ref_id."""
|
||||||
matches: list[str] = re.findall(_REFID_REGEX, ref_id)
|
if match := _REFID_REGEX.search(ref_id):
|
||||||
|
return match.group(1).replace("/", "-")
|
||||||
if len(matches) > 0:
|
|
||||||
if ref_id := matches[0]:
|
|
||||||
return ref_id.replace("/", "-")
|
|
||||||
|
|
||||||
return None
|
return None
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user