Upgrade to latest click 8.3.1
This commit is contained in:
@@ -146,3 +146,84 @@ def is_proxy_set(socks=False):
|
||||
continue
|
||||
return True
|
||||
return False
|
||||
|
||||
|
||||
def click_launch(url, wait=False, locate=False) -> int:
|
||||
return _click_open_url(url, wait=wait, locate=locate)
|
||||
|
||||
|
||||
def _click_open_url(
|
||||
url, wait=False, locate=False
|
||||
): # pylint: disable=too-many-branches, too-many-return-statements, consider-using-with
|
||||
"""
|
||||
Issue https://github.com/pallets/click/issues/2868
|
||||
Keep in sync with https://github.com/pallets/click/blob/main/src/click/_termui_impl.py
|
||||
"""
|
||||
import subprocess
|
||||
|
||||
def _unquote_file(url) -> str:
|
||||
from urllib.parse import unquote
|
||||
|
||||
if url.startswith("file://"):
|
||||
url = unquote(url[7:])
|
||||
|
||||
return url
|
||||
|
||||
if IS_MACOS:
|
||||
args = ["open"]
|
||||
if wait:
|
||||
args.append("-W")
|
||||
if locate:
|
||||
args.append("-R")
|
||||
args.append(_unquote_file(url))
|
||||
null = open("/dev/null", "w")
|
||||
try:
|
||||
return subprocess.Popen(args, stderr=null).wait()
|
||||
finally:
|
||||
null.close()
|
||||
elif IS_WINDOWS:
|
||||
if locate:
|
||||
url = _unquote_file(url)
|
||||
args = ["explorer", f"/select,{url}"]
|
||||
else:
|
||||
args = ["start"]
|
||||
if wait:
|
||||
args.append("/WAIT")
|
||||
args.append("")
|
||||
args.append(url)
|
||||
try:
|
||||
return subprocess.call(args, shell=True)
|
||||
except OSError:
|
||||
# Command not found
|
||||
return 127
|
||||
elif IS_CYGWIN:
|
||||
if locate:
|
||||
url = _unquote_file(url)
|
||||
args = ["cygstart", os.path.dirname(url)]
|
||||
else:
|
||||
args = ["cygstart"]
|
||||
if wait:
|
||||
args.append("-w")
|
||||
args.append(url)
|
||||
try:
|
||||
return subprocess.call(args)
|
||||
except OSError:
|
||||
# Command not found
|
||||
return 127
|
||||
|
||||
try:
|
||||
if locate:
|
||||
url = os.path.dirname(_unquote_file(url)) or "."
|
||||
else:
|
||||
url = _unquote_file(url)
|
||||
c = subprocess.Popen(["xdg-open", url])
|
||||
if wait:
|
||||
return c.wait()
|
||||
return 0
|
||||
except OSError:
|
||||
if url.startswith(("http://", "https://")) and not locate and not wait:
|
||||
import webbrowser
|
||||
|
||||
webbrowser.open(url)
|
||||
return 0
|
||||
return 1
|
||||
|
||||
Reference in New Issue
Block a user