![]() If newwin is not None, it is # used for new=1 (open_new). # remote_action is used for new=0 (open). %action will # be replaced depending on the value of 'new' passed to open. poll () is None ) except OSError : return False class UnixBrowser ( BaseBrowser ): """Parent class for all Unix browsers with remote functionality.""" raise_opts = None background = False redirect_stdout = True # In remote_args, %s will be replaced with the requested URL. Popen ( cmdline, close_fds = True, start_new_session = True ) return ( p. audit ( "webbrowser.open", url ) try : if sys. wait () except OSError : return False class BackgroundBrowser ( GenericBrowser ): """Class for all browsers which are to be started in the background.""" def open ( self, url, new = 0, autoraise = True ): cmdline = + sys. Popen ( cmdline, close_fds = True ) return not p. audit ( "webbrowser.open", url ) cmdline = + try : if sys. name ) def open ( self, url, new = 0, autoraise = True ): sys. args = else : # name should be a list with arguments self. open ( url, 2 ) class GenericBrowser ( BaseBrowser ): """Class for all browsers started with a command and without remote functionality.""" def _init_ ( self, name ): if isinstance ( name, str ): self. open ( url, 1 ) def open_new_tab ( self, url ): return self. basename = name def open ( self, url, new = 0, autoraise = True ): raise NotImplementedError def open_new ( self, url ): return self. Do not use directly.""" args = def _init_ ( self, name = "" ): self. basename ( browser ) register ( browser, None, instance = controller, preferred = preferred ) return return # General parent classes class BaseBrowser ( object ): """Parent class for all browsers. basename : import copy controller = copy. basename ( cmd ) try : command = _browsers except KeyError : return # now attempt to clone to fit the new name: controller = command if controller and name. If we can't create a controller in this way, or if there is no executable for the requested browser, return. This is useful to create a controller when a user specifies a path to an entry in the BROWSER environment variable - we can copy a general controller to operate using a specific installation of the desired browser in this way. """ return open ( url, 2 ) def _synthesize ( browser, *, preferred = False ): """Attempt to synthesize a controller based on existing controllers. If not possible, then the behavior becomes equivalent to open_new(). def open_new_tab ( url ): """Open url in a new page ("tab") of the default browser. # It is recommended one does "import webbrowser" and uses webbrowser.open(url) # instead of "from webbrowser import *". try : command = _browsers except KeyError : command = _synthesize ( browser ) if command is not None : return command elif command is not None : return command () raise Error ( "could not locate runnable browser" ) # Please note: the following definition hides a builtin function. split ( browser ) if browser = '&' : return BackgroundBrowser ( browser ) else : return GenericBrowser ( browser ) else : # User gave us a browser name or path. Def get ( using = None ): """Return a browser launcher instance appropriate for the environment.""" if _tryorder is None : with _lock : if _tryorder is None : register_standard_browsers () if using is not None : alternatives = else : alternatives = _tryorder for browser in alternatives : if ' %s ' in browser : # User gave us a command line, split it into name and args browser = shlex.
0 Comments
Leave a Reply. |