예제 #1
0
def _print_url():
    title_message = "You can now view your Streamlit app in your browser."
    named_urls = []

    if config.is_manually_set("browser.serverAddress"):
        named_urls = [
            ("URL", Report.get_url(config.get_option("browser.serverAddress")))
        ]

    elif config.get_option("server.headless"):
        named_urls = [
            ("Network URL", Report.get_url(net_util.get_internal_ip())),
            ("External URL", Report.get_url(net_util.get_external_ip())),
        ]

    else:
        named_urls = [
            ("Local URL", Report.get_url("localhost")),
            ("Network URL", Report.get_url(net_util.get_internal_ip())),
        ]

    click.secho("")
    click.secho("  %s" % title_message, fg="blue", bold=True)
    click.secho("")

    for url_name, url in named_urls:
        url_util.print_url(url_name, url)

    click.secho("")
예제 #2
0
def _print_url():
    title_message = 'You can now view your Streamlit report in your browser.'
    named_urls = []

    if config.is_manually_set('browser.serverAddress'):
        named_urls = [
            ('URL',
             Report.get_url(config.get_option('browser.serverAddress'))),
        ]

    elif config.get_option('server.headless'):
        named_urls = [
            ('Network URL', Report.get_url(util.get_internal_ip())),
            ('External URL', Report.get_url(util.get_external_ip())),
        ]

    else:
        named_urls = [
            ('Local URL', Report.get_url('localhost')),
            ('Network URL', Report.get_url(util.get_internal_ip())),
        ]

    click.secho('')
    click.secho('  %s' % title_message, fg='green')
    click.secho('')

    for url_name, url in named_urls:
        util.print_url(url_name, url)

    click.secho('')
 def set_default_headers(self):
     self.set_header("Access-Control-Allow-Headers", "X-Xsrftoken")
     self.set_header(
         "Access-Control-Allow-Origin",
         Report.get_url(config.get_option("browser.serverAddress")))
     self.set_header("Vary", "Origin")
     self.set_header("Access-Control-Allow-Credentials", "true")
 def set_default_headers(self):
     if config.get_option("server.enableCSRFProtection"):
         self.set_header("Access-Control-Allow-Headers", "X-Xsrftoken")
         self.set_header("Access-Control-Allow-Origin", Report.get_url(config.get_option("browser.serverAddress")))
         self.set_header("Vary", "Origin")
         self.set_header("Access-Control-Allow-Credentials", "true")
     elif routes.allow_cross_origin_requests():
         self.set_header("Access-Control-Allow-Origin", "*")
    def set_default_headers(self):
        # This works whether XSRF protection is on or off.
        self.set_header("Access-Control-Allow-Headers", "X-XSRFToken")

        self.set_header(
            "Access-Control-Allow-Origin",
            Report.get_url(config.get_option("browser.serverAddress")),
        )
        self.set_header("Vary", "Origin")
        self.set_header("Access-Control-Allow-Credentials", "true")
예제 #6
0
    def test_get_url(self, baseUrl, port, expected_url):
        options = {"global.useNode": False, "server.headless": False}

        if baseUrl:
            options["server.baseUrlPath"] = baseUrl

        if port:
            options["server.port"] = port

        mock_get_option = testutil.build_mock_config_get_option(options)

        with patch.object(config, "get_option", new=mock_get_option):
            actual_url = Report.get_url("the_ip_address")

        self.assertEqual(expected_url, actual_url)
예제 #7
0
    def maybe_open_browser():
        if config.get_option("server.headless"):
            # Don't open browser when in headless mode.
            return

        if server.browser_is_connected:
            # Don't auto-open browser if there's already a browser connected.
            # This can happen if there's an old tab repeatedly trying to
            # connect, and it happens to success before we launch the browser.
            return

        if config.is_manually_set("browser.serverAddress"):
            addr = config.get_option("browser.serverAddress")
        else:
            addr = "localhost"

        util.open_browser(Report.get_url(addr))
예제 #8
0
def _print_url(is_running_hello):
    if is_running_hello:
        title_message = "Welcome to Streamlit. Check out our demo in your browser."
    else:
        title_message = "You can now view your Streamlit app in your browser."

    named_urls = []

    if config.is_manually_set("browser.serverAddress"):
        named_urls = [
            ("URL", Report.get_url(config.get_option("browser.serverAddress")))
        ]

    elif config.is_manually_set("server.address"):
        named_urls = [
            ("URL", Report.get_url(config.get_option("server.address"))),
        ]

    elif config.get_option("server.headless"):
        internal_ip = net_util.get_internal_ip()
        if internal_ip:
            named_urls.append(("Network URL", Report.get_url(internal_ip)))

        external_ip = net_util.get_external_ip()
        if external_ip:
            named_urls.append(("External URL", Report.get_url(external_ip)))

    else:
        named_urls = [
            ("Local URL", Report.get_url("localhost")),
        ]

        internal_ip = net_util.get_internal_ip()
        if internal_ip:
            named_urls.append(("Network URL", Report.get_url(internal_ip)))

    click.secho("")
    click.secho("  %s" % title_message, fg="blue", bold=True)
    click.secho("")

    for url_name, url in named_urls:
        url_util.print_url(url_name, url)

    click.secho("")

    if is_running_hello:
        click.secho(
            "  Ready to create your own Python apps super quickly? Just head over to:"
        )
        click.secho("  https://docs.streamlit.io")
        click.secho("  May you create awesome apps!")
        click.secho("")