Skip to content

Commit

Permalink
Use yarl to parse url
Browse files Browse the repository at this point in the history
  • Loading branch information
davet2001 committed Apr 18, 2022
1 parent 6fdbf5f commit a0cf823
Showing 1 changed file with 3 additions and 5 deletions.
8 changes: 3 additions & 5 deletions homeassistant/components/generic/config_flow.py
Expand Up @@ -6,7 +6,6 @@
from functools import partial
import io
import logging
import re
from types import MappingProxyType
from typing import Any
from urllib.parse import urlparse, urlunparse
Expand All @@ -16,6 +15,7 @@
import av
from httpx import HTTPStatusError, RequestError, TimeoutException
import voluptuous as vol
import yarl

from homeassistant.components.stream.const import SOURCE_TIMEOUT
from homeassistant.config_entries import ConfigEntry, ConfigFlow, OptionsFlow
Expand Down Expand Up @@ -183,14 +183,12 @@ async def async_test_still(hass, info) -> tuple[dict[str, str], str | None]:
return {}, f"image/{fmt}"


URL_RE = re.compile("//.*:.*@")


def slug_url(url) -> str | None:
"""Convert a camera url into a string suitable for a camera name."""
if not url:
return None
url = URL_RE.sub("//", url)
# Strip out username/password if present
url = str(yarl.URL(url).with_user(None))
url_no_scheme = urlparse(url)._replace(scheme="")
return slugify(urlunparse(url_no_scheme).strip("/"))

Expand Down

0 comments on commit a0cf823

Please sign in to comment.