Ejemplo n.º 1
0
def test_build_url_from_netloc_and_parse_netloc(
    netloc,
    expected_url,
    expected_host_port,
):
    assert build_url_from_netloc(netloc) == expected_url
    assert parse_netloc(netloc) == expected_host_port
Ejemplo n.º 2
0
    def add_trusted_host(self, host, source=None, suppress_logging=False):
        # type: (str, Optional[str], bool) -> None
        """
        :param host: It is okay to provide a host that has previously been
            added.
        :param source: An optional source string, for logging where the host
            string came from.
        """
        if not suppress_logging:
            msg = 'adding trusted host: {!r}'.format(host)
            if source is not None:
                msg += ' (from {})'.format(source)
            logger.info(msg)

        host_port = parse_netloc(host)
        if host_port not in self.pip_trusted_origins:
            self.pip_trusted_origins.append(host_port)

        self.mount(
            build_url_from_netloc(host) + '/',
            self._trusted_host_adapter
        )
        if not host_port[1]:
            # Mount wildcard ports for the same host.
            self.mount(
                build_url_from_netloc(host) + ':',
                self._trusted_host_adapter
            )
Ejemplo n.º 3
0
    def add_trusted_host(self,
                         host: str,
                         source: Optional[str] = None,
                         suppress_logging: bool = False) -> None:
        """
        :param host: It is okay to provide a host that has previously been
            added.
        :param source: An optional source string, for logging where the host
            string came from.
        """
        if not suppress_logging:
            msg = f"adding trusted host: {host!r}"
            if source is not None:
                msg += f" (from {source})"
            logger.info(msg)

        host_port = parse_netloc(host)
        if host_port not in self.pip_trusted_origins:
            self.pip_trusted_origins.append(host_port)

        self.mount(
            build_url_from_netloc(host, scheme="http") + "/",
            self._trusted_host_adapter)
        self.mount(
            build_url_from_netloc(host) + "/", self._trusted_host_adapter)
        if not host_port[1]:
            self.mount(
                build_url_from_netloc(host, scheme="http") + ":",
                self._trusted_host_adapter,
            )
            # Mount wildcard ports for the same host.
            self.mount(
                build_url_from_netloc(host) + ":", self._trusted_host_adapter)
Ejemplo n.º 4
0
def test_build_url_from_netloc_and_parse_netloc(
    netloc: str,
    expected_url: str,
    expected_host_port: Tuple[str, Optional[int]],
) -> None:
    assert build_url_from_netloc(netloc) == expected_url
    assert parse_netloc(netloc) == expected_host_port