Exemple #1
0
    def test_get_external_ip(self):
        # Test success
        with requests_mock.mock() as m:
            m.get(net_util._AWS_CHECK_IP, text="1.2.3.4")
            self.assertEqual("1.2.3.4", net_util.get_external_ip())

        net_util._external_ip = None

        # Test failure
        with requests_mock.mock() as m:
            m.get(net_util._AWS_CHECK_IP, exc=requests.exceptions.ConnectTimeout)
            self.assertEqual(None, net_util.get_external_ip())
Exemple #2
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("")
Exemple #3
0
def _print_url(is_running_hello: bool) -> None:
    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",
             session_data.get_url(config.get_option("browser.serverAddress")))
        ]

    elif (config.is_manually_set("server.address")
          and not server_address_is_unix_socket()):
        named_urls = [
            ("URL", session_data.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", session_data.get_url(internal_ip)))

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

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

        internal_ip = net_util.get_internal_ip()
        if internal_ip:
            named_urls.append(
                ("Network URL", session_data.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?")
        click.secho("  Head over to ", nl=False)
        click.secho("https://docs.streamlit.io", bold=True)
        click.secho("")
        click.secho("  May you create awesome apps!")
        click.secho("")
        click.secho("")
Exemple #4
0
    def test_get_external_ip_html(self):
        # This tests the case where the external URL returns a web page.
        # https://github.com/streamlit/streamlit/issues/554#issuecomment-604847244

        response_text = """
        <html>
            ... stuff
        </html>
        """

        with requests_mock.mock() as m:
            m.get(net_util._AWS_CHECK_IP, text=response_text)
            self.assertEqual(None, net_util.get_external_ip())

        net_util._external_ip = None
Exemple #5
0
    def serialize_running_report_to_files(self):
        """Return a running report as an easily-serializable list of tuples.

        Returns
        -------
        list of tuples
            See `CloudStorage.save_report_files()` for schema. But as to the
            output of this method, it's just a manifest pointing to the Server
            so browsers who go to the shareable report URL can connect to it
            live.

        """
        LOGGER.debug("Serializing running report")

        manifest = self._build_manifest(
            status=StaticManifest.RUNNING,
            external_server_ip=net_util.get_external_ip(),
            internal_server_ip=net_util.get_internal_ip(),
        )

        return [("reports/%s/manifest.pb" % self.report_id,
                 manifest.SerializeToString())]