webbrowser.py 24 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713
  1. #! /usr/bin/env python3
  2. """Interfaces for launching and remotely controlling Web browsers."""
  3. # Maintained by Georg Brandl.
  4. import os
  5. import shlex
  6. import shutil
  7. import sys
  8. import subprocess
  9. import threading
  10. __all__ = ["Error", "open", "open_new", "open_new_tab", "get", "register"]
  11. class Error(Exception):
  12. pass
  13. _lock = threading.RLock()
  14. _browsers = {} # Dictionary of available browser controllers
  15. _tryorder = None # Preference order of available browsers
  16. _os_preferred_browser = None # The preferred browser
  17. def register(name, klass, instance=None, *, preferred=False):
  18. """Register a browser connector."""
  19. with _lock:
  20. if _tryorder is None:
  21. register_standard_browsers()
  22. _browsers[name.lower()] = [klass, instance]
  23. # Preferred browsers go to the front of the list.
  24. # Need to match to the default browser returned by xdg-settings, which
  25. # may be of the form e.g. "firefox.desktop".
  26. if preferred or (_os_preferred_browser and name in _os_preferred_browser):
  27. _tryorder.insert(0, name)
  28. else:
  29. _tryorder.append(name)
  30. def get(using=None):
  31. """Return a browser launcher instance appropriate for the environment."""
  32. if _tryorder is None:
  33. with _lock:
  34. if _tryorder is None:
  35. register_standard_browsers()
  36. if using is not None:
  37. alternatives = [using]
  38. else:
  39. alternatives = _tryorder
  40. for browser in alternatives:
  41. if '%s' in browser:
  42. # User gave us a command line, split it into name and args
  43. browser = shlex.split(browser)
  44. if browser[-1] == '&':
  45. return BackgroundBrowser(browser[:-1])
  46. else:
  47. return GenericBrowser(browser)
  48. else:
  49. # User gave us a browser name or path.
  50. try:
  51. command = _browsers[browser.lower()]
  52. except KeyError:
  53. command = _synthesize(browser)
  54. if command[1] is not None:
  55. return command[1]
  56. elif command[0] is not None:
  57. return command[0]()
  58. raise Error("could not locate runnable browser")
  59. # Please note: the following definition hides a builtin function.
  60. # It is recommended one does "import webbrowser" and uses webbrowser.open(url)
  61. # instead of "from webbrowser import *".
  62. def open(url, new=0, autoraise=True):
  63. """Display url using the default browser.
  64. If possible, open url in a location determined by new.
  65. - 0: the same browser window (the default).
  66. - 1: a new browser window.
  67. - 2: a new browser page ("tab").
  68. If possible, autoraise raises the window (the default) or not.
  69. """
  70. if _tryorder is None:
  71. with _lock:
  72. if _tryorder is None:
  73. register_standard_browsers()
  74. for name in _tryorder:
  75. browser = get(name)
  76. if browser.open(url, new, autoraise):
  77. return True
  78. return False
  79. def open_new(url):
  80. """Open url in a new window of the default browser.
  81. If not possible, then open url in the only browser window.
  82. """
  83. return open(url, 1)
  84. def open_new_tab(url):
  85. """Open url in a new page ("tab") of the default browser.
  86. If not possible, then the behavior becomes equivalent to open_new().
  87. """
  88. return open(url, 2)
  89. def _synthesize(browser, *, preferred=False):
  90. """Attempt to synthesize a controller based on existing controllers.
  91. This is useful to create a controller when a user specifies a path to
  92. an entry in the BROWSER environment variable -- we can copy a general
  93. controller to operate using a specific installation of the desired
  94. browser in this way.
  95. If we can't create a controller in this way, or if there is no
  96. executable for the requested browser, return [None, None].
  97. """
  98. cmd = browser.split()[0]
  99. if not shutil.which(cmd):
  100. return [None, None]
  101. name = os.path.basename(cmd)
  102. try:
  103. command = _browsers[name.lower()]
  104. except KeyError:
  105. return [None, None]
  106. # now attempt to clone to fit the new name:
  107. controller = command[1]
  108. if controller and name.lower() == controller.basename:
  109. import copy
  110. controller = copy.copy(controller)
  111. controller.name = browser
  112. controller.basename = os.path.basename(browser)
  113. register(browser, None, instance=controller, preferred=preferred)
  114. return [None, controller]
  115. return [None, None]
  116. # General parent classes
  117. class BaseBrowser(object):
  118. """Parent class for all browsers. Do not use directly."""
  119. args = ['%s']
  120. def __init__(self, name=""):
  121. self.name = name
  122. self.basename = name
  123. def open(self, url, new=0, autoraise=True):
  124. raise NotImplementedError
  125. def open_new(self, url):
  126. return self.open(url, 1)
  127. def open_new_tab(self, url):
  128. return self.open(url, 2)
  129. class GenericBrowser(BaseBrowser):
  130. """Class for all browsers started with a command
  131. and without remote functionality."""
  132. def __init__(self, name):
  133. if isinstance(name, str):
  134. self.name = name
  135. self.args = ["%s"]
  136. else:
  137. # name should be a list with arguments
  138. self.name = name[0]
  139. self.args = name[1:]
  140. self.basename = os.path.basename(self.name)
  141. def open(self, url, new=0, autoraise=True):
  142. sys.audit("webbrowser.open", url)
  143. cmdline = [self.name] + [arg.replace("%s", url)
  144. for arg in self.args]
  145. try:
  146. if sys.platform[:3] == 'win':
  147. p = subprocess.Popen(cmdline)
  148. else:
  149. p = subprocess.Popen(cmdline, close_fds=True)
  150. return not p.wait()
  151. except OSError:
  152. return False
  153. class BackgroundBrowser(GenericBrowser):
  154. """Class for all browsers which are to be started in the
  155. background."""
  156. def open(self, url, new=0, autoraise=True):
  157. cmdline = [self.name] + [arg.replace("%s", url)
  158. for arg in self.args]
  159. sys.audit("webbrowser.open", url)
  160. try:
  161. if sys.platform[:3] == 'win':
  162. p = subprocess.Popen(cmdline)
  163. else:
  164. p = subprocess.Popen(cmdline, close_fds=True,
  165. start_new_session=True)
  166. return (p.poll() is None)
  167. except OSError:
  168. return False
  169. class UnixBrowser(BaseBrowser):
  170. """Parent class for all Unix browsers with remote functionality."""
  171. raise_opts = None
  172. background = False
  173. redirect_stdout = True
  174. # In remote_args, %s will be replaced with the requested URL. %action will
  175. # be replaced depending on the value of 'new' passed to open.
  176. # remote_action is used for new=0 (open). If newwin is not None, it is
  177. # used for new=1 (open_new). If newtab is not None, it is used for
  178. # new=3 (open_new_tab). After both substitutions are made, any empty
  179. # strings in the transformed remote_args list will be removed.
  180. remote_args = ['%action', '%s']
  181. remote_action = None
  182. remote_action_newwin = None
  183. remote_action_newtab = None
  184. def _invoke(self, args, remote, autoraise, url=None):
  185. raise_opt = []
  186. if remote and self.raise_opts:
  187. # use autoraise argument only for remote invocation
  188. autoraise = int(autoraise)
  189. opt = self.raise_opts[autoraise]
  190. if opt: raise_opt = [opt]
  191. cmdline = [self.name] + raise_opt + args
  192. if remote or self.background:
  193. inout = subprocess.DEVNULL
  194. else:
  195. # for TTY browsers, we need stdin/out
  196. inout = None
  197. p = subprocess.Popen(cmdline, close_fds=True, stdin=inout,
  198. stdout=(self.redirect_stdout and inout or None),
  199. stderr=inout, start_new_session=True)
  200. if remote:
  201. # wait at most five seconds. If the subprocess is not finished, the
  202. # remote invocation has (hopefully) started a new instance.
  203. try:
  204. rc = p.wait(5)
  205. # if remote call failed, open() will try direct invocation
  206. return not rc
  207. except subprocess.TimeoutExpired:
  208. return True
  209. elif self.background:
  210. if p.poll() is None:
  211. return True
  212. else:
  213. return False
  214. else:
  215. return not p.wait()
  216. def open(self, url, new=0, autoraise=True):
  217. sys.audit("webbrowser.open", url)
  218. if new == 0:
  219. action = self.remote_action
  220. elif new == 1:
  221. action = self.remote_action_newwin
  222. elif new == 2:
  223. if self.remote_action_newtab is None:
  224. action = self.remote_action_newwin
  225. else:
  226. action = self.remote_action_newtab
  227. else:
  228. raise Error("Bad 'new' parameter to open(); " +
  229. "expected 0, 1, or 2, got %s" % new)
  230. args = [arg.replace("%s", url).replace("%action", action)
  231. for arg in self.remote_args]
  232. args = [arg for arg in args if arg]
  233. success = self._invoke(args, True, autoraise, url)
  234. if not success:
  235. # remote invocation failed, try straight way
  236. args = [arg.replace("%s", url) for arg in self.args]
  237. return self._invoke(args, False, False)
  238. else:
  239. return True
  240. class Mozilla(UnixBrowser):
  241. """Launcher class for Mozilla browsers."""
  242. remote_args = ['%action', '%s']
  243. remote_action = ""
  244. remote_action_newwin = "-new-window"
  245. remote_action_newtab = "-new-tab"
  246. background = True
  247. class Netscape(UnixBrowser):
  248. """Launcher class for Netscape browser."""
  249. raise_opts = ["-noraise", "-raise"]
  250. remote_args = ['-remote', 'openURL(%s%action)']
  251. remote_action = ""
  252. remote_action_newwin = ",new-window"
  253. remote_action_newtab = ",new-tab"
  254. background = True
  255. class Galeon(UnixBrowser):
  256. """Launcher class for Galeon/Epiphany browsers."""
  257. raise_opts = ["-noraise", ""]
  258. remote_args = ['%action', '%s']
  259. remote_action = "-n"
  260. remote_action_newwin = "-w"
  261. background = True
  262. class Chrome(UnixBrowser):
  263. "Launcher class for Google Chrome browser."
  264. remote_args = ['%action', '%s']
  265. remote_action = ""
  266. remote_action_newwin = "--new-window"
  267. remote_action_newtab = ""
  268. background = True
  269. Chromium = Chrome
  270. class Opera(UnixBrowser):
  271. "Launcher class for Opera browser."
  272. remote_args = ['%action', '%s']
  273. remote_action = ""
  274. remote_action_newwin = "--new-window"
  275. remote_action_newtab = ""
  276. background = True
  277. class Elinks(UnixBrowser):
  278. "Launcher class for Elinks browsers."
  279. remote_args = ['-remote', 'openURL(%s%action)']
  280. remote_action = ""
  281. remote_action_newwin = ",new-window"
  282. remote_action_newtab = ",new-tab"
  283. background = False
  284. # elinks doesn't like its stdout to be redirected -
  285. # it uses redirected stdout as a signal to do -dump
  286. redirect_stdout = False
  287. class Konqueror(BaseBrowser):
  288. """Controller for the KDE File Manager (kfm, or Konqueror).
  289. See the output of ``kfmclient --commands``
  290. for more information on the Konqueror remote-control interface.
  291. """
  292. def open(self, url, new=0, autoraise=True):
  293. sys.audit("webbrowser.open", url)
  294. # XXX Currently I know no way to prevent KFM from opening a new win.
  295. if new == 2:
  296. action = "newTab"
  297. else:
  298. action = "openURL"
  299. devnull = subprocess.DEVNULL
  300. try:
  301. p = subprocess.Popen(["kfmclient", action, url],
  302. close_fds=True, stdin=devnull,
  303. stdout=devnull, stderr=devnull)
  304. except OSError:
  305. # fall through to next variant
  306. pass
  307. else:
  308. p.wait()
  309. # kfmclient's return code unfortunately has no meaning as it seems
  310. return True
  311. try:
  312. p = subprocess.Popen(["konqueror", "--silent", url],
  313. close_fds=True, stdin=devnull,
  314. stdout=devnull, stderr=devnull,
  315. start_new_session=True)
  316. except OSError:
  317. # fall through to next variant
  318. pass
  319. else:
  320. if p.poll() is None:
  321. # Should be running now.
  322. return True
  323. try:
  324. p = subprocess.Popen(["kfm", "-d", url],
  325. close_fds=True, stdin=devnull,
  326. stdout=devnull, stderr=devnull,
  327. start_new_session=True)
  328. except OSError:
  329. return False
  330. else:
  331. return (p.poll() is None)
  332. class Grail(BaseBrowser):
  333. # There should be a way to maintain a connection to Grail, but the
  334. # Grail remote control protocol doesn't really allow that at this
  335. # point. It probably never will!
  336. def _find_grail_rc(self):
  337. import glob
  338. import pwd
  339. import socket
  340. import tempfile
  341. tempdir = os.path.join(tempfile.gettempdir(),
  342. ".grail-unix")
  343. user = pwd.getpwuid(os.getuid())[0]
  344. filename = os.path.join(glob.escape(tempdir), glob.escape(user) + "-*")
  345. maybes = glob.glob(filename)
  346. if not maybes:
  347. return None
  348. s = socket.socket(socket.AF_UNIX, socket.SOCK_STREAM)
  349. for fn in maybes:
  350. # need to PING each one until we find one that's live
  351. try:
  352. s.connect(fn)
  353. except OSError:
  354. # no good; attempt to clean it out, but don't fail:
  355. try:
  356. os.unlink(fn)
  357. except OSError:
  358. pass
  359. else:
  360. return s
  361. def _remote(self, action):
  362. s = self._find_grail_rc()
  363. if not s:
  364. return 0
  365. s.send(action)
  366. s.close()
  367. return 1
  368. def open(self, url, new=0, autoraise=True):
  369. sys.audit("webbrowser.open", url)
  370. if new:
  371. ok = self._remote("LOADNEW " + url)
  372. else:
  373. ok = self._remote("LOAD " + url)
  374. return ok
  375. #
  376. # Platform support for Unix
  377. #
  378. # These are the right tests because all these Unix browsers require either
  379. # a console terminal or an X display to run.
  380. def register_X_browsers():
  381. # use xdg-open if around
  382. if shutil.which("xdg-open"):
  383. register("xdg-open", None, BackgroundBrowser("xdg-open"))
  384. # The default GNOME3 browser
  385. if "GNOME_DESKTOP_SESSION_ID" in os.environ and shutil.which("gvfs-open"):
  386. register("gvfs-open", None, BackgroundBrowser("gvfs-open"))
  387. # The default GNOME browser
  388. if "GNOME_DESKTOP_SESSION_ID" in os.environ and shutil.which("gnome-open"):
  389. register("gnome-open", None, BackgroundBrowser("gnome-open"))
  390. # The default KDE browser
  391. if "KDE_FULL_SESSION" in os.environ and shutil.which("kfmclient"):
  392. register("kfmclient", Konqueror, Konqueror("kfmclient"))
  393. if shutil.which("x-www-browser"):
  394. register("x-www-browser", None, BackgroundBrowser("x-www-browser"))
  395. # The Mozilla browsers
  396. for browser in ("firefox", "iceweasel", "iceape", "seamonkey"):
  397. if shutil.which(browser):
  398. register(browser, None, Mozilla(browser))
  399. # The Netscape and old Mozilla browsers
  400. for browser in ("mozilla-firefox",
  401. "mozilla-firebird", "firebird",
  402. "mozilla", "netscape"):
  403. if shutil.which(browser):
  404. register(browser, None, Netscape(browser))
  405. # Konqueror/kfm, the KDE browser.
  406. if shutil.which("kfm"):
  407. register("kfm", Konqueror, Konqueror("kfm"))
  408. elif shutil.which("konqueror"):
  409. register("konqueror", Konqueror, Konqueror("konqueror"))
  410. # Gnome's Galeon and Epiphany
  411. for browser in ("galeon", "epiphany"):
  412. if shutil.which(browser):
  413. register(browser, None, Galeon(browser))
  414. # Skipstone, another Gtk/Mozilla based browser
  415. if shutil.which("skipstone"):
  416. register("skipstone", None, BackgroundBrowser("skipstone"))
  417. # Google Chrome/Chromium browsers
  418. for browser in ("google-chrome", "chrome", "chromium", "chromium-browser"):
  419. if shutil.which(browser):
  420. register(browser, None, Chrome(browser))
  421. # Opera, quite popular
  422. if shutil.which("opera"):
  423. register("opera", None, Opera("opera"))
  424. # Next, Mosaic -- old but still in use.
  425. if shutil.which("mosaic"):
  426. register("mosaic", None, BackgroundBrowser("mosaic"))
  427. # Grail, the Python browser. Does anybody still use it?
  428. if shutil.which("grail"):
  429. register("grail", Grail, None)
  430. def register_standard_browsers():
  431. global _tryorder
  432. _tryorder = []
  433. if sys.platform == 'darwin':
  434. register("MacOSX", None, MacOSXOSAScript('default'))
  435. register("chrome", None, MacOSXOSAScript('chrome'))
  436. register("firefox", None, MacOSXOSAScript('firefox'))
  437. register("safari", None, MacOSXOSAScript('safari'))
  438. # OS X can use below Unix support (but we prefer using the OS X
  439. # specific stuff)
  440. if sys.platform[:3] == "win":
  441. # First try to use the default Windows browser
  442. register("windows-default", WindowsDefault)
  443. # Detect some common Windows browsers, fallback to IE
  444. iexplore = os.path.join(os.environ.get("PROGRAMFILES", "C:\\Program Files"),
  445. "Internet Explorer\\IEXPLORE.EXE")
  446. for browser in ("firefox", "firebird", "seamonkey", "mozilla",
  447. "netscape", "opera", iexplore):
  448. if shutil.which(browser):
  449. register(browser, None, BackgroundBrowser(browser))
  450. else:
  451. # Prefer X browsers if present
  452. if os.environ.get("DISPLAY") or os.environ.get("WAYLAND_DISPLAY"):
  453. try:
  454. cmd = "xdg-settings get default-web-browser".split()
  455. raw_result = subprocess.check_output(cmd, stderr=subprocess.DEVNULL)
  456. result = raw_result.decode().strip()
  457. except (FileNotFoundError, subprocess.CalledProcessError, PermissionError, NotADirectoryError) :
  458. pass
  459. else:
  460. global _os_preferred_browser
  461. _os_preferred_browser = result
  462. register_X_browsers()
  463. # Also try console browsers
  464. if os.environ.get("TERM"):
  465. if shutil.which("www-browser"):
  466. register("www-browser", None, GenericBrowser("www-browser"))
  467. # The Links/elinks browsers <http://artax.karlin.mff.cuni.cz/~mikulas/links/>
  468. if shutil.which("links"):
  469. register("links", None, GenericBrowser("links"))
  470. if shutil.which("elinks"):
  471. register("elinks", None, Elinks("elinks"))
  472. # The Lynx browser <http://lynx.isc.org/>, <http://lynx.browser.org/>
  473. if shutil.which("lynx"):
  474. register("lynx", None, GenericBrowser("lynx"))
  475. # The w3m browser <http://w3m.sourceforge.net/>
  476. if shutil.which("w3m"):
  477. register("w3m", None, GenericBrowser("w3m"))
  478. # OK, now that we know what the default preference orders for each
  479. # platform are, allow user to override them with the BROWSER variable.
  480. if "BROWSER" in os.environ:
  481. userchoices = os.environ["BROWSER"].split(os.pathsep)
  482. userchoices.reverse()
  483. # Treat choices in same way as if passed into get() but do register
  484. # and prepend to _tryorder
  485. for cmdline in userchoices:
  486. if cmdline != '':
  487. cmd = _synthesize(cmdline, preferred=True)
  488. if cmd[1] is None:
  489. register(cmdline, None, GenericBrowser(cmdline), preferred=True)
  490. # what to do if _tryorder is now empty?
  491. #
  492. # Platform support for Windows
  493. #
  494. if sys.platform[:3] == "win":
  495. class WindowsDefault(BaseBrowser):
  496. def open(self, url, new=0, autoraise=True):
  497. sys.audit("webbrowser.open", url)
  498. try:
  499. os.startfile(url)
  500. except OSError:
  501. # [Error 22] No application is associated with the specified
  502. # file for this operation: '<URL>'
  503. return False
  504. else:
  505. return True
  506. #
  507. # Platform support for MacOS
  508. #
  509. if sys.platform == 'darwin':
  510. # Adapted from patch submitted to SourceForge by Steven J. Burr
  511. class MacOSX(BaseBrowser):
  512. """Launcher class for Aqua browsers on Mac OS X
  513. Optionally specify a browser name on instantiation. Note that this
  514. will not work for Aqua browsers if the user has moved the application
  515. package after installation.
  516. If no browser is specified, the default browser, as specified in the
  517. Internet System Preferences panel, will be used.
  518. """
  519. def __init__(self, name):
  520. self.name = name
  521. def open(self, url, new=0, autoraise=True):
  522. sys.audit("webbrowser.open", url)
  523. assert "'" not in url
  524. # hack for local urls
  525. if not ':' in url:
  526. url = 'file:'+url
  527. # new must be 0 or 1
  528. new = int(bool(new))
  529. if self.name == "default":
  530. # User called open, open_new or get without a browser parameter
  531. script = 'open location "%s"' % url.replace('"', '%22') # opens in default browser
  532. else:
  533. # User called get and chose a browser
  534. if self.name == "OmniWeb":
  535. toWindow = ""
  536. else:
  537. # Include toWindow parameter of OpenURL command for browsers
  538. # that support it. 0 == new window; -1 == existing
  539. toWindow = "toWindow %d" % (new - 1)
  540. cmd = 'OpenURL "%s"' % url.replace('"', '%22')
  541. script = '''tell application "%s"
  542. activate
  543. %s %s
  544. end tell''' % (self.name, cmd, toWindow)
  545. # Open pipe to AppleScript through osascript command
  546. osapipe = os.popen("osascript", "w")
  547. if osapipe is None:
  548. return False
  549. # Write script to osascript's stdin
  550. osapipe.write(script)
  551. rc = osapipe.close()
  552. return not rc
  553. class MacOSXOSAScript(BaseBrowser):
  554. def __init__(self, name):
  555. self._name = name
  556. def open(self, url, new=0, autoraise=True):
  557. if self._name == 'default':
  558. script = 'open location "%s"' % url.replace('"', '%22') # opens in default browser
  559. else:
  560. script = '''
  561. tell application "%s"
  562. activate
  563. open location "%s"
  564. end
  565. '''%(self._name, url.replace('"', '%22'))
  566. osapipe = os.popen("osascript", "w")
  567. if osapipe is None:
  568. return False
  569. osapipe.write(script)
  570. rc = osapipe.close()
  571. return not rc
  572. def main():
  573. import getopt
  574. usage = """Usage: %s [-n | -t] url
  575. -n: open new window
  576. -t: open new tab""" % sys.argv[0]
  577. try:
  578. opts, args = getopt.getopt(sys.argv[1:], 'ntd')
  579. except getopt.error as msg:
  580. print(msg, file=sys.stderr)
  581. print(usage, file=sys.stderr)
  582. sys.exit(1)
  583. new_win = 0
  584. for o, a in opts:
  585. if o == '-n': new_win = 1
  586. elif o == '-t': new_win = 2
  587. if len(args) != 1:
  588. print(usage, file=sys.stderr)
  589. sys.exit(1)
  590. url = args[0]
  591. open(url, new_win)
  592. print("\a")
  593. if __name__ == "__main__":
  594. main()