01bf5dd323bebd66b7ad60fdaee34eb8f7b76aae,lib/streamlit/proxy/Proxy.py,,_print_remote_url,#Any#Any#,50

Before Change


//     config.set_option("proxy.isRemote", val)

def _print_remote_url(port, quoted_name):
    ips = []
    http_client = None
    try:
        http_client = httpclient.HTTPClient()
        for key in ("local-ipv4", "public-ipv4"):
            endpoint = os.path.join(EC2_METADATA_URL, key)
            response = http_client.fetch(endpoint, request_timeout=0.01)
            ips.append(response.body)
    except (httpclient.HTTPError, RuntimeError) as e:
        // Basically if not on EC2 do a hack and try to connect to
        // internet and see what the local ip is.
        s = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
        s.connect(("8.8.8.8", 53))
        ips.append(s.getsockname()[0])
        s.close()
    finally:
        if http_client is not None:
            http_client.close()

    timeout_secs = config.get_option("proxy.waitForConnectionSecs")
    for ip in ips:
        url = "http://{}:{}/?name={}".format(ip, port, quoted_name)
        print("Please connect to %s within %s seconds." % (url, timeout_secs))

def _launch_web_client(name):
    Launches a web browser to connect to the proxy to get the named
    report.

After Change


def _print_remote_url(port, quoted_name):
    external_ip = config.get_option("proxy.externalIP")

    if external_ip:
        LOGGER.debug(f"proxy.externalIP set to {external_ip}")
    else:
        print("proxy.externalIP not set, attempting autodetect of external IP")

        http_client = None
        try:
            http_client = httpclient.HTTPClient()
            response = http_client.fetch(AWS_CHECK_IP, request_timeout=1)
            external_ip = response.body.strip()
        except (httpclient.HTTPError, RuntimeError) as e:
            LOGGER.error(f"Error connecting to {AWS_CHECK_IP}: {e}")
        finally:
            if http_client is not None:
                http_client.close()

    if external_ip is None:
        print("Did not auto detect external ip. Please go to "
              f"{REMOTE_DOC} for debugging hints.")
        return
Italian Trulli
In pattern: SUPERPATTERN

Frequency: 4

Non-data size: 5

Instances


Project Name: streamlit/streamlit
Commit Name: 01bf5dd323bebd66b7ad60fdaee34eb8f7b76aae
Time: 2018-08-09
Author: armando@playground.global
File Name: lib/streamlit/proxy/Proxy.py
Class Name:
Method Name: _print_remote_url


Project Name: streamlit/streamlit
Commit Name: 883644354ca6c016a9b79d67e0494db88a823c23
Time: 2018-08-14
Author: armando@playground.global
File Name: lib/streamlit/proxy/Proxy.py
Class Name:
Method Name: _print_remote_url


Project Name: microsoft/nni
Commit Name: 2de52a8976971da4836727ba9242fedcc7474878
Time: 2020-01-16
Author: 656569648@qq.com
File Name: examples/model_compress/slim_torch_cifar10.py
Class Name:
Method Name: main


Project Name: ray-project/ray
Commit Name: 244aafdcf89ae814975c8c4e3faf0bd4995c7878
Time: 2020-09-05
Author: sven@anyscale.io
File Name: rllib/utils/exploration/tests/test_curiosity.py
Class Name: TestCuriosity
Method Name: test_curiosity_on_large_frozen_lake