How to use rfc3986 - 10 common examples

To help you get started, we’ve selected a few rfc3986 examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github python-hyper / rfc3986 / tests / test_unicode_support.py View on Github external
def test_unsplit_idna_a_unicode_hostname():
    parsed = urlparse(SNOWMAN_HOST)
    assert parsed.unsplit(use_idna=True) == SNOWMAN_IDNA_HOST
github python-hyper / rfc3986 / tests / test_builder.py View on Github external
def test_finalize():
    """Verify the whole thing."""
    uri = (
        builder.URIBuilder()
        .add_scheme("https")
        .add_credentials("sigmavirus24", "not-my-re@l-password")
        .add_host("github.com")
        .add_path("sigmavirus24/rfc3986")
        .finalize()
        .unsplit()
    )
    expected = (
        "https://sigmavirus24:not-my-re%40l-password@github.com/"
        "sigmavirus24/rfc3986"
    )
    assert expected == uri
github python-hyper / rfc3986 / tests / test_parseresult.py View on Github external
def test_uri_with_everything(self, uri_with_everything):
        uri = pr.ParseResult.from_string(uri_with_everything)
        assert uri.host == uri.hostname
        assert uri.netloc == uri.authority
        assert uri.query == uri.params
        assert uri.geturl() == uri.unsplit()
github python-hyper / rfc3986 / tests / test_parseresult.py View on Github external
def test_eager_normalization_from_string(self):
        uri = pr.ParseResultBytes.from_string(
            b"http://" + SNOWMAN + b".com/path",
            strict=False,
            lazy_normalize=False,
        )
        assert uri.unsplit() == b"http:/path"
github python-hyper / rfc3986 / tests / test_parseresult.py View on Github external
def test_unsplit(self):
        uri = pr.ParseResultBytes.from_string(
            b"http://" + SNOWMAN + b".com/path", strict=False
        )
        idna_encoded = SNOWMAN_IDNA_HOST.encode("utf-8") + b"/path"
        assert uri.unsplit(use_idna=True) == idna_encoded
github python-hyper / rfc3986 / tests / test_iri.py View on Github external
def test_encode_iri(iri, uri):
    assert rfc3986.iri_reference(iri).encode().unsplit() == uri
github python-hyper / rfc3986 / tests / test_parseresult.py View on Github external
def test_from_parts(parts, unsplit):
    uri = pr.ParseResult.from_parts(*parts)
    assert uri.unsplit() == unsplit
github python-hyper / rfc3986 / tests / test_parseresult.py View on Github external
b"https://httpbin.org:443/get",
        ),
        (("HTTPS", None, "HTTPBIN.ORG"), b"https://httpbin.org"),
    ],
)
def test_bytes_from_parts(parts, unsplit):
    uri = pr.ParseResultBytes.from_parts(*parts)
    assert uri.unsplit() == unsplit


class TestParseResultParsesURIs(base.BaseTestParsesURIs):
    test_class = pr.ParseResult


class TestParseResultUnsplits(base.BaseTestUnsplits):
    test_class = pr.ParseResult


def test_normalizes_uris_when_using_from_string(uri_to_normalize):
    """Verify we always get the same thing out as we expect."""
    result = pr.ParseResult.from_string(
        uri_to_normalize, lazy_normalize=False
    )
    assert result.scheme == "https"
    assert result.host == "example.com"


class TestStdlibShims:
    def test_uri_with_everything(self, uri_with_everything):
        uri = pr.ParseResult.from_string(uri_with_everything)
        assert uri.host == uri.hostname
        assert uri.netloc == uri.authority
github python-hyper / rfc3986 / tests / test_validators.py View on Github external
        rfc3986.uri_reference("https://gitlab.com/sigmavirus24"),
        rfc3986.uri_reference("ssh://gitlab.com/sigmavirus24"),
        rfc3986.uri_reference("ssh://ssh@gitlab.com:22/sigmavirus24"),
        rfc3986.uri_reference("https://gitlab.com:443/sigmavirus24"),
        rfc3986.uri_reference("https://bitbucket.org/sigmavirus24"),
        rfc3986.uri_reference("ssh://bitbucket.org/sigmavirus24"),
        rfc3986.uri_reference("ssh://ssh@bitbucket.org:22/sigmavirus24"),
        rfc3986.uri_reference("https://bitbucket.org:443/sigmavirus24"),
        rfc3986.uri_reference("https://git.openstack.org/sigmavirus24"),
        rfc3986.uri_reference("ssh://git.openstack.org/sigmavirus24"),
        rfc3986.uri_reference("ssh://ssh@git.openstack.org:22/sigmavirus24"),
        rfc3986.uri_reference("https://git.openstack.org:443/sigmavirus24"),
        rfc3986.uri_reference(
            "ssh://ssh@git.openstack.org:22/sigmavirus24?foo=bar#fragment"
        ),
        rfc3986.uri_reference(
            "ssh://git.openstack.org:22/sigmavirus24?foo=bar#fragment"
github python-hyper / rfc3986 / tests / test_builder.py View on Github external
def test_extend_query_with(uri, extend_with, expected_query):
    """Verify the behaviour of extend_query_with."""
    uribuilder = (
        builder.URIBuilder()
        .from_uri(uri_reference(uri))
        .extend_query_with(extend_with)
    )
    assert parse_qs(uribuilder.query) == expected_query