MCPcopy
hub / github.com/pallets/click / open_url

Function open_url

src/click/_termui_impl.py:772–839  ·  view source on GitHub ↗
(url: str, wait: bool = False, locate: bool = False)

Source from the content-addressed store, hash-verified

770
771
772def open_url(url: str, wait: bool = False, locate: bool = False) -> int:
773 import subprocess
774
775 def _unquote_file(url: str) -> str:
776 from urllib.parse import unquote
777
778 if url.startswith("file://"):
779 url = unquote(url[7:])
780
781 return url
782
783 if sys.platform == "darwin":
784 args = ["open"]
785 if wait:
786 args.append("-W")
787 if locate:
788 args.append("-R")
789 args.append(_unquote_file(url))
790 null = open("/dev/null", "w")
791 try:
792 return subprocess.Popen(args, stderr=null).wait()
793 finally:
794 null.close()
795 elif WIN:
796 if locate:
797 url = _unquote_file(url)
798 args = ["explorer", "/select,", url]
799 try:
800 return subprocess.call(args)
801 except OSError:
802 return 127
803 else:
804 try:
805 os.startfile(url) # type: ignore[attr-defined]
806 except OSError:
807 return 127
808 return 0
809 elif CYGWIN:
810 if locate:
811 url = _unquote_file(url)
812 args = ["cygstart", os.path.dirname(url)]
813 else:
814 args = ["cygstart"]
815 if wait:
816 args.append("-w")
817 args.append(url)
818 try:
819 return subprocess.call(args)
820 except OSError:
821 # Command not found
822 return 127
823
824 try:
825 if locate:
826 url = os.path.dirname(_unquote_file(url)) or "."
827 else:
828 url = _unquote_file(url)
829 c = subprocess.Popen(["xdg-open", url])

Callers 1

launchFunction · 0.85

Calls 4

_unquote_fileFunction · 0.85
openFunction · 0.85
openMethod · 0.80
closeMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…