move files into a package structure
This commit is contained in:
28
raven/util/urlutils.py
Normal file
28
raven/util/urlutils.py
Normal file
@@ -0,0 +1,28 @@
|
||||
import os
|
||||
from urllib.parse import urlparse
|
||||
import sys
|
||||
|
||||
|
||||
def urls_to_path(urls: str) -> [str]:
|
||||
result = []
|
||||
url_list = urls.splitlines(keepends=False)
|
||||
for url in url_list:
|
||||
path = url_to_path(url)
|
||||
result.append(path)
|
||||
return result
|
||||
|
||||
def url_to_path(url: str) -> str:
|
||||
p = urlparse(url)
|
||||
if sys.platform == 'win32' or sys.platform == 'cygwin':
|
||||
return os.path.abspath(p.path[1:])
|
||||
return os.path.abspath(os.path.join(p.netloc, p.path))
|
||||
|
||||
|
||||
def url_is_file(string: str) -> bool:
|
||||
url_candidates = string.splitlines(keepends=False)
|
||||
for url in url_candidates:
|
||||
if url.startswith("file://"):
|
||||
path = url_to_path(url)
|
||||
if not os.path.isfile(path):
|
||||
return False
|
||||
return True
|
||||
Reference in New Issue
Block a user