speasy.core.url_utils module
- speasy.core.url_utils.ensure_url_scheme(url: str) str[source]
Adds file:// to url for local files
- Parameters:
- urlstr
url with or without scheme
- Returns
- ——-
- str
url with ‘file:’ scheme added when none was provided else input url
- speasy.core.url_utils.host_and_port(url: str) Tuple[str, int][source]
Returns the host and port of an url
- Parameters:
- urlstr
url with or without scheme
- Returns:
- Tuple[str, str]
host and port of the url, defaults to 80 if no port or scheme is provided
- speasy.core.url_utils.is_local_file(url: str)[source]
Returns true if url correspond to a local path.
- Parameters:
- urlstr
file url formatted as local path or standard URL format (https://en.wikipedia.org/wiki/URL)
- Returns:
- bool
True if matches any local path/URL
Examples
>>> from speasy.core.url_utils import is_local_file
>>> is_local_file("/some/path") True
>>> is_local_file("C:/some/path") True
>>> is_local_file("file:///some/path") True
>>> is_local_file("http://some/path") False
- speasy.core.url_utils.to_local_path(url: str) str[source]
Convert a local file URL or path into a filesystem path.
Unlike
urlparse(url).path, this preserves Windows drive letters: a path such asZ:\data\f.cdfwould otherwise have itsZ:parsed as a URL scheme and the drive silently dropped (\data\f.cdf). A leadingfile://scheme is stripped; bare paths (POSIX or Windows) are returned unchanged. Handled deterministically on every platform (url2pathnameis avoided because it rewrites separators differently per OS).>>> from speasy.core.url_utils import to_local_path
>>> to_local_path("/home/test/f.cdf") '/home/test/f.cdf'
>>> to_local_path("C:/data/f.cdf") 'C:/data/f.cdf'
>>> to_local_path("file:///home/test/f.cdf") '/home/test/f.cdf'