本文整理匯總了Python中webbrowser.GenericBrowser方法的典型用法代碼示例。如果您正苦於以下問題:Python webbrowser.GenericBrowser方法的具體用法?Python webbrowser.GenericBrowser怎麽用?Python webbrowser.GenericBrowser使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類webbrowser
的用法示例。
在下文中一共展示了webbrowser.GenericBrowser方法的2個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。
示例1: start_browser
# 需要導入模塊: import webbrowser [as 別名]
# 或者: from webbrowser import GenericBrowser [as 別名]
def start_browser(self, url, name=None):
browser = None
if name is not None and name.lower() == 'none':
log.info('Will not start any browser since --browser=none')
return
try:
browser = webbrowser.get(name)
except webbrowser.Error:
old = name or 'default'
msg = 'Could not find browser: %s. Will use: %s.'
browser = webbrowser.get()
log.warn(msg, name, self.getBrowserName(browser))
if type(browser) is webbrowser.GenericBrowser:
msg = 'Will not start text-based browser: %s.'
log.info(msg % self.getBrowserName(browser))
elif browser is not None:
log.info('Starting browser: %s' % self.getBrowserName(browser))
browser.open_new(url)
示例2: test_patch_webbrowser
# 需要導入模塊: import webbrowser [as 別名]
# 或者: from webbrowser import GenericBrowser [as 別名]
def test_patch_webbrowser(*_):
# Make sure that webbrowser re-generates the browser list using the
# mocked environment
import webbrowser
webbrowser = reload_module(webbrowser)
# By default, we expect that BROWSER will be loaded as a generic browser
# This is because "safari" is not a valid script in the system PATH
assert isinstance(webbrowser.get(), webbrowser.GenericBrowser)
# After patching, the default webbrowser should now be interpreted as an
# OSAScript browser
patch_webbrowser()
assert isinstance(webbrowser.get(), webbrowser.MacOSXOSAScript)
assert webbrowser._tryorder[0] == 'safari'