18 lines
431 B
Python
18 lines
431 B
Python
import os
|
|
from urllib.parse import urlparse
|
|
import sys
|
|
|
|
|
|
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(url: str) -> bool:
|
|
if url.startswith("file://"):
|
|
path = url_to_path(url)
|
|
return os.path.isfile(path)
|
|
return False
|