本文整理汇总了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'