cpython: 7d320c3bf9c6 (original) (raw)
--- a/Lib/webbrowser.py +++ b/Lib/webbrowser.py @@ -495,23 +495,10 @@ if os.environ.get("TERM"): # if sys.platform[:3] == "win": - class WindowsDefault(BaseBrowser):
# Windows Default opening arguments.[](#l1.9)
cmd = "start"[](#l1.11)
newwindow = ""[](#l1.12)
newtab = ""[](#l1.13)
- def open(self, url, new=0, autoraise=True):
# Format the command for optional arguments and add the url.[](#l1.16)
if new == 1:[](#l1.17)
self.cmd += " " + self.newwindow[](#l1.18)
elif new == 2:[](#l1.19)
self.cmd += " " + self.newtab[](#l1.20)
self.cmd += " " + url[](#l1.21) try:[](#l1.22)
subprocess.call(self.cmd, shell=True)[](#l1.23)
os.startfile(url)[](#l1.24) except OSError:[](#l1.25) # [Error 22] No application is associated with the specified[](#l1.26) # file for this operation: '<URL>'[](#l1.27)
@@ -519,108 +506,19 @@ if sys.platform[:3] == "win": else: return True -
- class InternetExplorer(WindowsDefault):
"""Launcher class for Internet Explorer browser"""[](#l1.36)
cmd = "start iexplore.exe"[](#l1.38)
newwindow = ""[](#l1.39)
newtab = ""[](#l1.40)
- class WinChrome(WindowsDefault):
"""Launcher class for windows specific Google Chrome browser"""[](#l1.44)
cmd = "start chrome.exe"[](#l1.46)
newwindow = "-new-window"[](#l1.47)
newtab = "-new-tab"[](#l1.48)
- class WinFirefox(WindowsDefault):
"""Launcher class for windows specific Firefox browser"""[](#l1.52)
cmd = "start firefox.exe"[](#l1.54)
newwindow = "-new-window"[](#l1.55)
newtab = "-new-tab"[](#l1.56)
cmd = "start opera"[](#l1.62)
newwindow = ""[](#l1.63)
newtab = ""[](#l1.64)
- class WinSeaMonkey(WindowsDefault):
"""Launcher class for windows specific SeaMonkey browser"""[](#l1.68)
cmd = "start seamonkey"[](#l1.70)
newwinow = ""[](#l1.71)
newtab = ""[](#l1.72)
- - _tryorder = [] _browsers = {}
- def find_windows_browsers():
""" Access the windows registry to determine[](#l1.83)
what browsers are on the system.[](#l1.84)
"""[](#l1.85)
import winreg[](#l1.87)
HKLM = winreg.HKEY_LOCAL_MACHINE[](#l1.88)
subkey = r'Software\Clients\StartMenuInternet'[](#l1.89)
read32 = winreg.KEY_READ | winreg.KEY_WOW64_32KEY[](#l1.90)
read64 = winreg.KEY_READ | winreg.KEY_WOW64_64KEY[](#l1.91)
key32 = winreg.OpenKey(HKLM, subkey, access=read32)[](#l1.92)
key64 = winreg.OpenKey(HKLM, subkey, access=read64)[](#l1.93)
# Return a list of browsers found in the registry[](#l1.95)
# Check if there are any different browsers in the[](#l1.96)
# 32 bit location instead of the 64 bit location.[](#l1.97)
browsers = [][](#l1.98)
i = 0[](#l1.99)
while True:[](#l1.100)
try:[](#l1.101)
browsers.append(winreg.EnumKey(key32, i))[](#l1.102)
except EnvironmentError:[](#l1.103)
break[](#l1.104)
i += 1[](#l1.105)
i = 0[](#l1.107)
while True:[](#l1.108)
try:[](#l1.109)
browsers.append(winreg.EnumKey(key64, i))[](#l1.110)
except EnvironmentError:[](#l1.111)
break[](#l1.112)
i += 1[](#l1.113)
winreg.CloseKey(key32)[](#l1.115)
winreg.CloseKey(key64)[](#l1.116)
return browsers[](#l1.118)
Detect some common windows browsers
- for browser in find_windows_browsers():
browser = browser.lower()[](#l1.122)
if "iexplore" in browser:[](#l1.123)
register("iexplore", None, InternetExplorer("iexplore"))[](#l1.124)
elif "chrome" in browser:[](#l1.125)
register("chrome", None, WinChrome("chrome"))[](#l1.126)
elif "firefox" in browser:[](#l1.127)
register("firefox", None, WinFirefox("firefox"))[](#l1.128)
elif "opera" in browser:[](#l1.129)
register("opera", None, WinOpera("opera"))[](#l1.130)
elif "seamonkey" in browser:[](#l1.131)
register("seamonkey", None, WinSeaMonkey("seamonkey"))[](#l1.132)
else:[](#l1.133)
register(browser, None, WindowsDefault(browser))[](#l1.134)
Detect some common Windows browsers, fallback to IE
- iexplore = os.path.join(os.environ.get("PROGRAMFILES", "C:\Program Files"),
"Internet Explorer\\IEXPLORE.EXE")[](#l1.137)
- for browser in ("firefox", "firebird", "seamonkey", "mozilla",
"netscape", "opera", iexplore):[](#l1.139)
if shutil.which(browser):[](#l1.140)
register(browser, None, BackgroundBrowser(browser))[](#l1.141)