Пример #1
0
def test_get_browser_controller_None_with_env(mock_get):
    os.environ['BOKEH_BROWSER'] = "bar"
    bub.get_browser_controller()
    assert mock_get.called
    assert mock_get.call_args[0] == ("bar",)
    assert mock_get.call_args[1] == {}
    del os.environ['BOKEH_BROWSER']
Пример #2
0
def test_get_browser_controller_value_with_env(mock_get):
    os.environ['BOKEH_BROWSER'] = "bar"
    bub.get_browser_controller('foo')
    assert mock_get.called
    assert mock_get.call_args[0] == ("bar",)
    assert mock_get.call_args[1] == {}
    del os.environ['BOKEH_BROWSER']
Пример #3
0
def test_get_browser_controller_value_with_env(mock_get) -> None:
    os.environ['BOKEH_BROWSER'] = "bar"
    bub.get_browser_controller('foo')
    assert mock_get.called
    assert mock_get.call_args[0] == ("foo", )
    assert mock_get.call_args[1] == {}
    del os.environ['BOKEH_BROWSER']
Пример #4
0
def show_session(session_id=None,
                 url='default',
                 app_path=None,
                 session=None,
                 browser=None,
                 new="tab",
                 controller=None):
    ''' Open a browser displaying a session document.

        If you have a session from ``pull_session()`` or ``push_session`` you
        can ``show_session(session=mysession)``. If you don't need to open a
        connection to the server yourself, you can show a new session in a
        browser by providing just the ``url``.

        Args:
            session_id (string, optional) :
               The name of the session, None to autogenerate a random one (default: None)

            url : (str, optional): The URL to a Bokeh application on a Bokeh server
                can also be `"default"` which will connect to the default app URL

            session (ClientSession, optional) : session to get session ID and server URL from
                If you specify this, you don't need to specify session_id and url

            browser (str, optional) : browser to show with (default: None)
                For systems that support it, the **browser** argument allows
                specifying which browser to display in, e.g. "safari", "firefox",
                "opera", "windows-default" (see the ``webbrowser`` module
                documentation in the standard lib for more details).

            new (str, optional) : new file output mode (default: "tab")
                For file-based output, opens or raises the browser window
                showing the current output file.  If **new** is 'tab', then
                opens a new tab. If **new** is 'window', then opens a new window.

        '''

    if app_path is not None:
        deprecated(
            (0, 12, 5), "app_path", "url",
            "Now pass entire app URLS in the url arguments, e.g. 'url=http://foo.com:5010/bar/myapp'"
        )
        url = url + app_path

    if session is not None:
        server_url = server_url_for_websocket_url(session._connection.url)
        session_id = session.id
    else:
        coords = _SessionCoordinates(session_id=session_id, url=url)
        server_url = coords.url
        session_id = coords.session_id

    if controller is None:
        from bokeh.util.browser import get_browser_controller
        controller = get_browser_controller(browser=browser)

    controller.open(server_url + "?bokeh-session-id=" +
                    _encode_query_param(session_id),
                    new=_new_param[new])
Пример #5
0
def show_session(session_id=None,
                 url='default',
                 app_path='/',
                 session=None,
                 browser=None,
                 new="tab",
                 controller=None):
    """Open a browser displaying a session document.

        If you have a session from ``pull_session()`` or
        ``push_session`` you can ``show_session(session=mysession)``.
        If you don't need to open a connection to the server yourself,
        you can show a new session in a browser by providing just the
        ``url`` and ``app_path``.

        Args:

        session_id : string, optional
             The name of the session, None to autogenerate a random one (default: None)

        url : str, optional
             The base server URL to connect to (default: 'default')

        app_path : str, optional
             Relative path to the app on the server (defualt: '/')

        session (ClientSession, optional) : session to get session ID and server URL from
            If you specify this, you don't need to specify session_id and url

        browser (str, optional) : browser to show with (default: None)
            For systems that support it, the **browser** argument allows
            specifying which browser to display in, e.g. "safari", "firefox",
            "opera", "windows-default" (see the ``webbrowser`` module
            documentation in the standard lib for more details).

        new (str, optional) : new file output mode (default: "tab")
            For file-based output, opens or raises the browser window
            showing the current output file.  If **new** is 'tab', then
            opens a new tab. If **new** is 'window', then opens a new window.

        """

    if session is not None:
        server_url = server_url_for_websocket_url(session._connection.url)
        session_id = session.id
    else:
        coords = _SessionCoordinates(
            dict(session_id=session_id, url=url, app_path=app_path))
        server_url = coords.server_url
        session_id = coords.session_id

    if controller is None:
        from bokeh.util.browser import get_browser_controller
        controller = get_browser_controller(browser=browser)

    controller.open(server_url + "?bokeh-session-id=" +
                    _encode_query_param(session_id),
                    new=_new_param[new])
Пример #6
0
def _show_with_state(obj, state, browser, new):
    controller = browserlib.get_browser_controller(browser=browser)

    if state.notebook:
        _show_notebook_with_state(obj, state)

    elif state.server_enabled:
        _show_server_with_state(obj, state, new, controller)

    if state.file:
        _show_file_with_state(obj, state, new, controller)
Пример #7
0
def show_session(session_id=None, url='default', app_path='/',
                 session=None, browser=None, new="tab", controller=None):
        """Open a browser displaying a session document.

        If you have a session from ``pull_session()`` or
        ``push_session`` you can ``show_session(session=mysession)``.
        If you don't need to open a connection to the server yourself,
        you can show a new session in a browser by providing just the
        ``url`` and ``app_path``.

        Args:

        session_id : string, optional
             The name of the session, None to autogenerate a random one (default: None)

        url : str, optional
             The base server URL to connect to (default: 'default')

        app_path : str, optional
             Relative path to the app on the server (defualt: '/')

        session (ClientSession, optional) : session to get session ID and server URL from
            If you specify this, you don't need to specify session_id and url

        browser (str, optional) : browser to show with (default: None)
            For systems that support it, the **browser** argument allows
            specifying which browser to display in, e.g. "safari", "firefox",
            "opera", "windows-default" (see the ``webbrowser`` module
            documentation in the standard lib for more details).

        new (str, optional) : new file output mode (default: "tab")
            For file-based output, opens or raises the browser window
            showing the current output file.  If **new** is 'tab', then
            opens a new tab. If **new** is 'window', then opens a new window.

        """

        if session is not None:
            server_url = server_url_for_websocket_url(session._connection.url)
            session_id = session.id
        else:
            coords = _SessionCoordinates(dict(session_id=session_id, url=url, app_path=app_path))
            server_url = coords.server_url
            session_id = coords.session_id

        if controller is None:
            from bokeh.util.browser import get_browser_controller
            controller = get_browser_controller(browser=browser)

        controller.open(server_url + "?bokeh-session-id=" + _encode_query_param(session_id),
                        new=_new_param[new])
Пример #8
0
def _show_with_state(obj, state, browser, new, notebook_handle=False):
    controller = browserlib.get_browser_controller(browser=browser)

    comms_handle = None
    shown = False

    if state.notebook:
        comms_handle = _show_notebook_doc_with_state(obj, state, notebook_handle)
        shown = True

    if state.file or not shown:
        _show_file_with_state(obj, state, new, controller)

    return comms_handle
Пример #9
0
def _show_with_state(obj, state, browser, new, notebook_handle=False):
    controller = browserlib.get_browser_controller(browser=browser)

    comms_handle = None
    shown = False

    if state.notebook:
        comms_handle = _show_notebook_with_state(obj, state, notebook_handle)
        shown = True

    if state.file or not shown:
        _show_file_with_state(obj, state, new, controller)

    return comms_handle
Пример #10
0
def show_session(session_id=None, url='default', app_path=None, session=None, browser=None, new="tab", controller=None):
        ''' Open a browser displaying a session document.

        If you have a session from ``pull_session()`` or ``push_session`` you
        can ``show_session(session=mysession)``. If you don't need to open a
        connection to the server yourself, you can show a new session in a
        browser by providing just the ``url``.

        Args:
            session_id (string, optional) :
               The name of the session, None to autogenerate a random one (default: None)

            url : (str, optional): The URL to a Bokeh application on a Bokeh server
                can also be `"default"` which will connect to the default app URL

            session (ClientSession, optional) : session to get session ID and server URL from
                If you specify this, you don't need to specify session_id and url

            browser (str, optional) : browser to show with (default: None)
                For systems that support it, the **browser** argument allows
                specifying which browser to display in, e.g. "safari", "firefox",
                "opera", "windows-default" (see the ``webbrowser`` module
                documentation in the standard lib for more details).

            new (str, optional) : new file output mode (default: "tab")
                For file-based output, opens or raises the browser window
                showing the current output file.  If **new** is 'tab', then
                opens a new tab. If **new** is 'window', then opens a new window.

        '''

        if app_path is not None:
            deprecated((0, 12, 5), "app_path", "url", "Now pass entire app URLS in the url arguments, e.g. 'url=http://foo.com:5010/bar/myapp'")
            url = url + app_path

        if session is not None:
            server_url = server_url_for_websocket_url(session._connection.url)
            session_id = session.id
        else:
            coords = _SessionCoordinates(session_id=session_id, url=url)
            server_url = coords.url
            session_id = coords.session_id

        if controller is None:
            from bokeh.util.browser import get_browser_controller
            controller = get_browser_controller(browser=browser)

        controller.open(server_url + "?bokeh-session-id=" + _encode_query_param(session_id),
                        new=_new_param[new])
Пример #11
0
def show_session(session_id: ID | None = None,
                 url: str = "default",
                 session: ClientSession | None = None,
                 browser: str | None = None,
                 new: BrowserTarget = "tab",
                 controller: BrowserLike | None = None) -> None:
    ''' Open a browser displaying a session document.

        If you have a session from ``pull_session()`` or ``push_session`` you
        can ``show_session(session=mysession)``. If you don't need to open a
        connection to the server yourself, you can show a new session in a
        browser by providing just the ``url``.

        Args:
            session_id (string, optional) :
               The name of the session, None to autogenerate a random one (default: None)

            url : (str, optional): The URL to a Bokeh application on a Bokeh server
                can also be `"default"` which will connect to the default app URL

            session (ClientSession, optional) : session to get session ID and server URL from
                If you specify this, you don't need to specify session_id and url

            browser (str, optional) : browser to show with (default: None)
                For systems that support it, the **browser** argument allows
                specifying which browser to display in, e.g. "safari", "firefox",
                "opera", "windows-default" (see the :doc:`webbrowser <python:library/webbrowser>`
                module documentation in the standard lib for more details).

            new (str, optional) : new file output mode (default: "tab")
                For file-based output, opens or raises the browser window
                showing the current output file.  If **new** is 'tab', then
                opens a new tab. If **new** is 'window', then opens a new window.

        '''
    if session is not None:
        server_url = server_url_for_websocket_url(session._connection.url)
        session_id = session.id
    else:
        coords = SessionCoordinates(session_id=session_id, url=url)
        server_url = coords.url
        session_id = coords.session_id

    if controller is None:
        from bokeh.util.browser import get_browser_controller
        controller = get_browser_controller(browser=browser)

    controller.open(server_url + "?bokeh-session-id=" + quote_plus(session_id),
                    new=NEW_PARAM[new])
Пример #12
0
def _show_with_state(obj, state, browser, new):
    controller = browserlib.get_browser_controller(browser=browser)

    comms_handle = None

    if state.notebook:
        comms_handle = _show_notebook_with_state(obj, state)

    elif state.server_enabled:
        _show_server_with_state(obj, state, new, controller)

    if state.file:
        _show_file_with_state(obj, state, new, controller)

    return comms_handle
Пример #13
0
def _show_with_state(obj, state, browser, new):
    controller = browserlib.get_browser_controller(browser=browser)

    comms_handle = None

    if state.notebook:
        comms_handle = _show_notebook_with_state(obj, state)

    elif state.server_enabled:
        _show_server_with_state(obj, state, new, controller)

    if state.file:
        _show_file_with_state(obj, state, new, controller)

    return comms_handle
Пример #14
0
def _show_with_state(obj, state, browser, new, notebook_handle=False):
    controller = browserlib.get_browser_controller(browser=browser)

    comms_handle = None
    shown = False

    if state.notebook:
        if state.notebook_type == 'jupyter':
            comms_handle = _show_jupyter_with_state(obj, state, notebook_handle)
        else:
            comms_handle = _show_zeppelin_with_state(obj, state, notebook_handle)
        shown = True

    if state.file or not shown:
        _show_file_with_state(obj, state, new, controller)

    return comms_handle
Пример #15
0
def _show_with_state(obj, state, browser, new, notebook_handle=False):
    controller = browserlib.get_browser_controller(browser=browser)

    comms_handle = None
    shown = False

    if state.notebook:
        if state.notebook_type == 'jupyter':
            comms_handle = _show_jupyter_with_state(obj, state, notebook_handle)
        else:
            comms_handle = _show_zeppelin_with_state(obj, state, notebook_handle)
        shown = True

    if state.file or not shown:
        _show_file_with_state(obj, state, new, controller)

    return comms_handle
Пример #16
0
def session_diagnostics(session):
    djs = session.document.to_json_string()
    msg = djs
    msg += ''
    sid = session.id
    msg += "Session_id = %s" % (sid,)
    si_map = session.request_server_info()
    print ('a')
    for k, v in si_map.items():
        msg += "\n%s: %s" % (str(k), str(v))
    logger = logging.getLogger(__name__)
    logger.info(msg)
    from bokeh.util.browser import get_browser_controller
    
    from bokeh.settings import settings    
    browser = settings.browser(None)    
    controller = get_browser_controller(browser=browser)
    print (dir(controller))
Пример #17
0
def test_get_browser_controller_None():
    b = bub.get_browser_controller(None)
    assert b == webbrowser
Пример #18
0
def test_get_browser_controller_dummy_with_env(mock_get) -> None:
    os.environ['BOKEH_BROWSER'] = "bar"
    bub.get_browser_controller('none')
    del os.environ['BOKEH_BROWSER']
Пример #19
0
def test_get_browser_controller_value(mock_get) -> None:
    bub.get_browser_controller('foo')
    assert mock_get.called
    assert mock_get.call_args[0] == ("foo", )
    assert mock_get.call_args[1] == {}
Пример #20
0
def test_get_browser_controller_None() -> None:
    b = bub.get_browser_controller(None)
    assert b == webbrowser
Пример #21
0
def test_get_browser_controller_dummy() -> None:
    b = bub.get_browser_controller('none')
    assert isinstance(b, bub.DummyWebBrowser)
Пример #22
0
def test_get_browser_controller_dummy_with_env(mock_get: MagicMock) -> None:
    with envset(BOKEH_BROWSER="bar"):
        bub.get_browser_controller('none')
Пример #23
0
def test_get_browser_controller_value_with_env(mock_get: MagicMock) -> None:
    with envset(BOKEH_BROWSER="bar"):
        bub.get_browser_controller('foo')
        assert mock_get.called
        assert mock_get.call_args[0] == ("foo", )
        assert mock_get.call_args[1] == {}
Пример #24
0
def test_get_browser_controller_value(mock_get):
    bub.get_browser_controller('foo')
    assert mock_get.called
    assert mock_get.call_args[0] == ("foo",)
    assert mock_get.call_args[1] == {}
Пример #25
0
def test_get_browser_controller_dummy():
    b = bub.get_browser_controller('none')
    assert isinstance(b, bub.DummyWebBrowser)