當前位置: 首頁>>代碼示例>>Python>>正文


Python webbrowser.Chrome方法代碼示例

本文整理匯總了Python中webbrowser.Chrome方法的典型用法代碼示例。如果您正苦於以下問題:Python webbrowser.Chrome方法的具體用法?Python webbrowser.Chrome怎麽用?Python webbrowser.Chrome使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在webbrowser的用法示例。


在下文中一共展示了webbrowser.Chrome方法的3個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。

示例1: _make_chrome

# 需要導入模塊: import webbrowser [as 別名]
# 或者: from webbrowser import Chrome [as 別名]
def _make_chrome(path):
    new_chrome = webbrowser.Chrome()
    new_chrome.name = path
    profile_directory = tempfile.mkdtemp()
    with open(os.path.join(profile_directory, "First Run"), "wb") as firstrun:
        # This file existing prevents prompts to make the new profile directory
        # the default
        firstrun.flush()
    new_chrome.remote_args = webbrowser.Chrome.remote_args + [
        '--user-data-dir="{}"'.format(profile_directory),
        "--no-first-run",
    ]
    return new_chrome 
開發者ID:Dallinger,項目名稱:Dallinger,代碼行數:15,代碼來源:deployment.py

示例2: test_chrome_isolation

# 需要導入模塊: import webbrowser [as 別名]
# 或者: from webbrowser import Chrome [as 別名]
def test_chrome_isolation(self):
        import webbrowser

        with mock.patch("dallinger.deployment.is_command") as is_command:
            is_command.side_effect = lambda s: s == "google-chrome"
            isolated = new_webbrowser_profile()
        assert isinstance(isolated, webbrowser.Chrome)
        assert isolated.remote_args[:2] == [r"%action", r"%s"]
        assert isolated.remote_args[-2].startswith(
            '--user-data-dir="{}'.format(tempfile.gettempdir())
        )
        assert isolated.remote_args[-1] == r"--no-first-run" 
開發者ID:Dallinger,項目名稱:Dallinger,代碼行數:14,代碼來源:test_deployment.py

示例3: display_qr_code

# 需要導入模塊: import webbrowser [as 別名]
# 或者: from webbrowser import Chrome [as 別名]
def display_qr_code(png, seed):
    """
    Display MFA QR code
    :param png:
    :param seed:
    :return:
    """
    # This NamedTemporaryFile is deleted as soon as it is closed, so
    # return it to caller, who must close it (or program termination
    # could cause it to be cleaned up, that's fine too).
    # If we don't keep the file around until after the user has synced
    # his MFA, the file will possibly be already deleted by the time
    # the operating system gets around to execing the browser, if
    # we're using a browser.
    qrcode_file = tempfile.NamedTemporaryFile(suffix='.png', delete=True, mode='wt')
    qrcode_file.write(png)
    qrcode_file.flush()
    if _fabulous_available:
        fabulous.utils.term.bgcolor = 'white'
        with open(qrcode_file.name, 'rb') as png_file:
            print(fabulous.image.Image(png_file, 100))
    else:
        graphical_browsers = [webbrowser.BackgroundBrowser,
                              webbrowser.Mozilla,
                              webbrowser.Galeon,
                              webbrowser.Chrome,
                              webbrowser.Opera,
                              webbrowser.Konqueror]
        if sys.platform[:3] == 'win':
            graphical_browsers.append(webbrowser.WindowsDefault)
        elif sys.platform == 'darwin':
            graphical_browsers.append(webbrowser.MacOSXOSAScript)

        browser_type = None
        try:
            browser_type = type(webbrowser.get())
        except webbrowser.Error:
            pass

        if browser_type in graphical_browsers:
            printError("Unable to print qr code directly to your terminal, trying a web browser.")
            webbrowser.open('file://' + qrcode_file.name)
        else:
            printInfo("Unable to print qr code directly to your terminal, and no graphical web browser seems available.")
            printInfo("But, the qr code file is temporarily available as this file:")
            printInfo("\n    %s\n" % qrcode_file.name)
            printInfo("Alternately, if you feel like typing the seed manually into your MFA app:")
            # this is a base32-encoded binary string (for case
            # insensitivity) which is then dutifully base64-encoded by
            # amazon before putting it on the wire.  so the actual
            # secret is b32decode(b64decode(seed)), and what users
            # will need to type in to their app is just
            # b64decode(seed).  print that out so users can (if
            # desperate) type in their MFA app.
            printInfo("\n    %s\n" % base64.b64decode(seed))
    return qrcode_file 
開發者ID:nccgroup,項目名稱:AWS-recipes,代碼行數:58,代碼來源:awsrecipes_enable_mfa.py


注:本文中的webbrowser.Chrome方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。