diff --git a/queenbee/base/request.py b/queenbee/base/request.py index 6c9981ba..e49a145f 100644 --- a/queenbee/base/request.py +++ b/queenbee/base/request.py @@ -4,6 +4,8 @@ from urllib import request from typing import Dict +from ..env.os import OS + USER_AGENT_STRING = 'Queenbee' @@ -14,9 +16,7 @@ def get_uri(url): elif url.startswith('http://') or url.startswith('https://'): return url - # a local file but is not formatted as local url - pre = 'file:///' if platform.system() == 'Windows' else 'file://' - return resolve_local_source(pre + url) + return resolve_local_source(OS.file_uri_prefix + url) def resolve_local_source(path, as_uri=True): @@ -24,10 +24,9 @@ def resolve_local_source(path, as_uri=True): Apparently both of them are used: https://en.wikipedia.org/wiki/File_URI_scheme """ - sep = 'file:///' if platform.system() == 'Windows' else 'file://' try: - rel_path = path.split(sep)[1] + rel_path = path.split(OS.file_uri_prefix)[1] except IndexError: raise ValueError('Invalid local path: {path}') diff --git a/queenbee/env/os.py b/queenbee/env/os.py new file mode 100644 index 00000000..70240f93 --- /dev/null +++ b/queenbee/env/os.py @@ -0,0 +1,18 @@ +import platform + + +class OS: + """A simple wrapper to handle OS-specific switches. + + Attributes: + is_windows: A boolean of whether the current system is MS Windows. + is_nix: A boolean of whether the current system is *nix (any Linux). + file_uri_prefix: A string to be used as the default prefix for URIs + which point to local files on the system. + + """ + + is_windows: bool = platform.system() == 'Windows' + is_nix: bool = not is_windows + + file_uri_prefix: str = 'file:///' if is_windows else 'file://'