Back to index

python3.2  3.2.2
Classes | Functions | Variables
webbrowser Namespace Reference

Classes

class  Error
class  BaseBrowser
class  GenericBrowser
class  BackgroundBrowser
class  UnixBrowser
class  Mozilla
class  Galeon
class  Opera
class  Elinks
class  Konqueror
class  Grail
class  WindowsDefault
class  MacOSX
class  MacOSXOSAScript

Functions

def register
def get
def open
def open_new
def open_new_tab
def _synthesize
def _isexecutable
def _iscommand
def register_X_browsers
def main

Variables

list __all__ = ["Error", "open", "open_new", "open_new_tab", "get", "register"]
dictionary _browsers = {}
list _tryorder = []
 Netscape = Mozilla
tuple iexplore
list _userchoices = os.environ["BROWSER"]
tuple cmd = _synthesize(cmdline, -1)
 cmdline = None

Function Documentation

def webbrowser._iscommand (   cmd) [private]
Return True if cmd is executable or can be found on the executable
search path.

Definition at line 122 of file webbrowser.py.

00122 
00123 def _iscommand(cmd):
00124     """Return True if cmd is executable or can be found on the executable
00125     search path."""
00126     if _isexecutable(cmd):
00127         return True
00128     path = os.environ.get("PATH")
00129     if not path:
00130         return False
00131     for d in path.split(os.pathsep):
00132         exe = os.path.join(d, cmd)
00133         if _isexecutable(exe):
00134             return True
00135     return False
00136 
00137 
00138 # General parent classes

Here is the call graph for this function:

Here is the caller graph for this function:

def webbrowser._isexecutable (   cmd) [private]

Definition at line 106 of file webbrowser.py.

00106 
00107     def _isexecutable(cmd):
00108         cmd = cmd.lower()
00109         if os.path.isfile(cmd) and cmd.endswith((".exe", ".bat")):
00110             return True
00111         for ext in ".exe", ".bat":
00112             if os.path.isfile(cmd + ext):
00113                 return True
00114         return False
else:

Here is the caller graph for this function:

def webbrowser._synthesize (   browser,
  update_tryorder = 1 
) [private]
Attempt to synthesize a controller base on existing controllers.

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.

If we can't create a controller in this way, or if there is no
executable for the requested browser, return [None, None].

Definition at line 73 of file webbrowser.py.

00073 
00074 def _synthesize(browser, update_tryorder=1):
00075     """Attempt to synthesize a controller base on existing controllers.
00076 
00077     This is useful to create a controller when a user specifies a path to
00078     an entry in the BROWSER environment variable -- we can copy a general
00079     controller to operate using a specific installation of the desired
00080     browser in this way.
00081 
00082     If we can't create a controller in this way, or if there is no
00083     executable for the requested browser, return [None, None].
00084 
00085     """
00086     cmd = browser.split()[0]
00087     if not _iscommand(cmd):
00088         return [None, None]
00089     name = os.path.basename(cmd)
00090     try:
00091         command = _browsers[name.lower()]
00092     except KeyError:
00093         return [None, None]
00094     # now attempt to clone to fit the new name:
00095     controller = command[1]
00096     if controller and name.lower() == controller.basename:
00097         import copy
00098         controller = copy.copy(controller)
00099         controller.name = browser
00100         controller.basename = os.path.basename(browser)
00101         register(browser, None, controller, update_tryorder)
00102         return [None, controller]
00103     return [None, None]
00104 

Here is the call graph for this function:

Here is the caller graph for this function:

def webbrowser.get (   using = None)
Return a browser launcher instance appropriate for the environment.

Definition at line 29 of file webbrowser.py.

00029 
00030 def get(using=None):
00031     """Return a browser launcher instance appropriate for the environment."""
00032     if using is not None:
00033         alternatives = [using]
00034     else:
00035         alternatives = _tryorder
00036     for browser in alternatives:
00037         if '%s' in browser:
00038             # User gave us a command line, split it into name and args
00039             browser = shlex.split(browser)
00040             if browser[-1] == '&':
00041                 return BackgroundBrowser(browser[:-1])
00042             else:
00043                 return GenericBrowser(browser)
00044         else:
00045             # User gave us a browser name or path.
00046             try:
00047                 command = _browsers[browser.lower()]
00048             except KeyError:
00049                 command = _synthesize(browser)
00050             if command[1] is not None:
00051                 return command[1]
00052             elif command[0] is not None:
00053                 return command[0]()
00054     raise Error("could not locate runnable browser")
00055 
00056 # Please note: the following definition hides a builtin function.
00057 # It is recommended one does "import webbrowser" and uses webbrowser.open(url)
00058 # instead of "from webbrowser import *".

Here is the call graph for this function:

Here is the caller graph for this function:

def webbrowser.main ( void  )

Definition at line 643 of file webbrowser.py.

00643 
00644 def main():
00645     import getopt
00646     usage = """Usage: %s [-n | -t] url
00647     -n: open new window
00648     -t: open new tab""" % sys.argv[0]
00649     try:
00650         opts, args = getopt.getopt(sys.argv[1:], 'ntd')
00651     except getopt.error as msg:
00652         print(msg, file=sys.stderr)
00653         print(usage, file=sys.stderr)
00654         sys.exit(1)
00655     new_win = 0
00656     for o, a in opts:
00657         if o == '-n': new_win = 1
00658         elif o == '-t': new_win = 2
00659     if len(args) != 1:
00660         print(usage, file=sys.stderr)
00661         sys.exit(1)
00662 
00663     url = args[0]
00664     open(url, new_win)
00665 
00666     print("\a")

Here is the call graph for this function:

def webbrowser.open (   url,
  new = 0,
  autoraise = True 
)

Definition at line 59 of file webbrowser.py.

00059 
00060 def open(url, new=0, autoraise=True):
00061     for name in _tryorder:
00062         browser = get(name)
00063         if browser.open(url, new, autoraise):
00064             return True
00065     return False

Here is the call graph for this function:

Here is the caller graph for this function:

def webbrowser.open_new (   url)

Definition at line 66 of file webbrowser.py.

00066 
00067 def open_new(url):
00068     return open(url, 1)

Here is the call graph for this function:

def webbrowser.open_new_tab (   url)

Definition at line 69 of file webbrowser.py.

00069 
00070 def open_new_tab(url):
00071     return open(url, 2)
00072 

Here is the call graph for this function:

def webbrowser.register (   name,
  klass,
  instance = None,
  update_tryorder = 1 
)
Register a browser connector and, optionally, connection.

Definition at line 21 of file webbrowser.py.

00021 
00022 def register(name, klass, instance=None, update_tryorder=1):
00023     """Register a browser connector and, optionally, connection."""
00024     _browsers[name.lower()] = [klass, instance]
00025     if update_tryorder > 0:
00026         _tryorder.append(name)
00027     elif update_tryorder < 0:
00028         _tryorder.insert(0, name)

Here is the caller graph for this function:

Definition at line 437 of file webbrowser.py.

00437 
00438 def register_X_browsers():
00439 
00440     # The default GNOME browser
00441     if "GNOME_DESKTOP_SESSION_ID" in os.environ and _iscommand("gnome-open"):
00442         register("gnome-open", None, BackgroundBrowser("gnome-open"))
00443 
00444     # The default KDE browser
00445     if "KDE_FULL_SESSION" in os.environ and _iscommand("kfmclient"):
00446         register("kfmclient", Konqueror, Konqueror("kfmclient"))
00447 
00448     # The Mozilla/Netscape browsers
00449     for browser in ("mozilla-firefox", "firefox",
00450                     "mozilla-firebird", "firebird",
00451                     "seamonkey", "mozilla", "netscape"):
00452         if _iscommand(browser):
00453             register(browser, None, Mozilla(browser))
00454 
00455     # Konqueror/kfm, the KDE browser.
00456     if _iscommand("kfm"):
00457         register("kfm", Konqueror, Konqueror("kfm"))
00458     elif _iscommand("konqueror"):
00459         register("konqueror", Konqueror, Konqueror("konqueror"))
00460 
00461     # Gnome's Galeon and Epiphany
00462     for browser in ("galeon", "epiphany"):
00463         if _iscommand(browser):
00464             register(browser, None, Galeon(browser))
00465 
00466     # Skipstone, another Gtk/Mozilla based browser
00467     if _iscommand("skipstone"):
00468         register("skipstone", None, BackgroundBrowser("skipstone"))
00469 
00470     # Opera, quite popular
00471     if _iscommand("opera"):
00472         register("opera", None, Opera("opera"))
00473 
00474     # Next, Mosaic -- old but still in use.
00475     if _iscommand("mosaic"):
00476         register("mosaic", None, BackgroundBrowser("mosaic"))
00477 
00478     # Grail, the Python browser. Does anybody still use it?
00479     if _iscommand("grail"):
00480         register("grail", Grail, None)
00481 
# Prefer X browsers if present

Here is the call graph for this function:


Variable Documentation

list webbrowser.__all__ = ["Error", "open", "open_new", "open_new_tab", "get", "register"]

Definition at line 13 of file webbrowser.py.

Definition at line 18 of file webbrowser.py.

Definition at line 19 of file webbrowser.py.

Definition at line 626 of file webbrowser.py.

Definition at line 633 of file webbrowser.py.

Definition at line 636 of file webbrowser.py.

Initial value:
00001 os.path.join(os.environ.get("PROGRAMFILES", "C:\\Program Files"),
00002                             "Internet Explorer\\IEXPLORE.EXE")

Definition at line 522 of file webbrowser.py.

Definition at line 289 of file webbrowser.py.