mirror of
https://github.com/home-assistant/core.git
synced 2025-07-23 21:27:38 +00:00
Use remove-prefix/suffix introduced in Python 3.9 (#135206)
Use removeprefix/removesuffix
This commit is contained in:
parent
0cc586a3ac
commit
dd57c75e64
@ -173,8 +173,7 @@ async def fetch_blueprint_from_github_url(
|
||||
|
||||
parsed_import_url = yarl.URL(import_url)
|
||||
suggested_filename = f"{parsed_import_url.parts[1]}/{parsed_import_url.parts[-1]}"
|
||||
if suggested_filename.endswith(".yaml"):
|
||||
suggested_filename = suggested_filename[:-5]
|
||||
suggested_filename = suggested_filename.removesuffix(".yaml")
|
||||
|
||||
return ImportedBlueprint(suggested_filename, raw_yaml, blueprint)
|
||||
|
||||
|
@ -166,8 +166,7 @@ class FritzBoxToolsFlowHandler(ConfigFlow, domain=DOMAIN):
|
||||
|
||||
uuid: str | None
|
||||
if uuid := discovery_info.upnp.get(ssdp.ATTR_UPNP_UDN):
|
||||
if uuid.startswith("uuid:"):
|
||||
uuid = uuid[5:]
|
||||
uuid = uuid.removeprefix("uuid:")
|
||||
await self.async_set_unique_id(uuid)
|
||||
self._abort_if_unique_id_configured({CONF_HOST: self._host})
|
||||
|
||||
|
@ -122,8 +122,7 @@ class FritzboxConfigFlow(ConfigFlow, domain=DOMAIN):
|
||||
return self.async_abort(reason="ignore_ip6_link_local")
|
||||
|
||||
if uuid := discovery_info.upnp.get(ssdp.ATTR_UPNP_UDN):
|
||||
if uuid.startswith("uuid:"):
|
||||
uuid = uuid[5:]
|
||||
uuid = uuid.removeprefix("uuid:")
|
||||
await self.async_set_unique_id(uuid)
|
||||
self._abort_if_unique_id_configured({CONF_HOST: host})
|
||||
|
||||
|
@ -20,8 +20,7 @@ CONF_IRK = "irk"
|
||||
|
||||
|
||||
def _parse_irk(irk: str) -> bytes | None:
|
||||
if irk.startswith("irk:"):
|
||||
irk = irk[4:]
|
||||
irk = irk.removeprefix("irk:")
|
||||
|
||||
if irk.endswith("="):
|
||||
try:
|
||||
|
@ -59,7 +59,7 @@ DATA_SCHEMA = vol.Schema({vol.Required(CONF_HOST): str, vol.Required(CONF_NAME):
|
||||
|
||||
|
||||
def _strip_uuid(udn: str) -> str:
|
||||
return udn[5:] if udn.startswith("uuid:") else udn
|
||||
return udn.removeprefix("uuid:")
|
||||
|
||||
|
||||
def _entry_is_complete(
|
||||
|
@ -66,8 +66,7 @@ class FlowHandler(ConfigFlow, domain=DOMAIN):
|
||||
if user_input is not None:
|
||||
bad_prefix = False
|
||||
prefix = user_input[CONF_DISCOVERY_PREFIX]
|
||||
if prefix.endswith("/#"):
|
||||
prefix = prefix[:-2]
|
||||
prefix = prefix.removesuffix("/#")
|
||||
try:
|
||||
valid_subscribe_topic(f"{prefix}/#")
|
||||
except vol.Invalid:
|
||||
|
@ -105,8 +105,7 @@ class FlowHandler(ConfigFlow, domain=DOMAIN):
|
||||
|
||||
uuid = discovery_info.upnp[ssdp.ATTR_UPNP_UDN]
|
||||
assert uuid
|
||||
if uuid.startswith("uuid:"):
|
||||
uuid = uuid[5:]
|
||||
uuid = uuid.removeprefix("uuid:")
|
||||
await self.async_set_unique_id(uuid)
|
||||
self._abort_if_unique_id_configured({CONF_HOST: self._host})
|
||||
|
||||
|
@ -98,8 +98,7 @@ def is_host_valid(host: str) -> bool:
|
||||
return False
|
||||
if re.match(r"^[0-9\.]+$", host): # reject invalid IPv4
|
||||
return False
|
||||
if host.endswith("."): # dot at the end is correct
|
||||
host = host[:-1]
|
||||
host = host.removesuffix(".")
|
||||
allowed = re.compile(r"(?!-)[A-Z\d\-]{1,63}(?<!-)$", re.IGNORECASE)
|
||||
return all(allowed.match(x) for x in host.split("."))
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user