Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix CI status. #75

Merged
merged 2 commits into from May 6, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
1 change: 1 addition & 0 deletions dev-requirements.txt
@@ -1,2 +1,3 @@
pytest
pytest-cov>=2.0
attrs==20.1.0
4 changes: 3 additions & 1 deletion src/rfc3986/_mixin.py
Expand Up @@ -152,7 +152,9 @@ def authority_is_valid(self, require=False):
return False

return validators.authority_is_valid(
self.authority, host=self.host, require=require,
self.authority,
host=self.host,
require=require,
)

def scheme_is_valid(self, require=False):
Expand Down
15 changes: 11 additions & 4 deletions src/rfc3986/abnf_regexp.py
Expand Up @@ -27,7 +27,7 @@
ALPHA = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz"
DIGIT = "0123456789"
# https://tools.ietf.org/html/rfc3986#section-2.3
UNRESERVED = UNRESERVED_CHARS = ALPHA + DIGIT + r'._!-~'
UNRESERVED = UNRESERVED_CHARS = ALPHA + DIGIT + r"._!-~"
UNRESERVED_CHARS_SET = set(UNRESERVED_CHARS)
NON_PCT_ENCODED_SET = RESERVED_CHARS_SET.union(UNRESERVED_CHARS_SET)
# We need to escape the '-' in this case:
Expand Down Expand Up @@ -123,11 +123,16 @@
IPv6_ADDRZ_RFC4007_RE = IPv6_RE + "(?:(?:%25|%)" + ZONE_ID + ")?"
IPv6_ADDRZ_RE = IPv6_RE + "(?:%25" + ZONE_ID + ")?"

IP_LITERAL_RE = r"\[({0}|{1})\]".format(IPv6_ADDRZ_RFC4007_RE, IPv_FUTURE_RE,)
IP_LITERAL_RE = r"\[({0}|{1})\]".format(
IPv6_ADDRZ_RFC4007_RE,
IPv_FUTURE_RE,
)

# Pattern for matching the host piece of the authority
HOST_RE = HOST_PATTERN = "({0}|{1}|{2})".format(
REG_NAME, IPv4_RE, IP_LITERAL_RE,
REG_NAME,
IPv4_RE,
IP_LITERAL_RE,
)
USERINFO_RE = (
"^([" + UNRESERVED_RE + SUB_DELIMITERS_RE + ":]|%s)+" % (PCT_ENCODED)
Expand Down Expand Up @@ -237,7 +242,9 @@
)

IHOST_RE = IHOST_PATTERN = u"({0}|{1}|{2})".format(
IREG_NAME, IPv4_RE, IP_LITERAL_RE,
IREG_NAME,
IPv4_RE,
IP_LITERAL_RE,
)

IUSERINFO_RE = (
Expand Down
7 changes: 5 additions & 2 deletions src/rfc3986/builder.py
Expand Up @@ -137,7 +137,8 @@ def add_credentials(self, username, password):

if password is not None:
userinfo = "{}:{}".format(
userinfo, normalizers.normalize_password(password),
userinfo,
normalizers.normalize_password(password),
)

return URIBuilder(
Expand Down Expand Up @@ -194,7 +195,9 @@ def add_port(self, port):
if port_int > 65535:
raise ValueError(
"ports are not allowed to be larger than 65535. "
"You provided {}".format(port_int,)
"You provided {}".format(
port_int,
)
)

return URIBuilder(
Expand Down
4 changes: 3 additions & 1 deletion src/rfc3986/exceptions.py
Expand Up @@ -74,7 +74,9 @@ def __init__(self, component_name, component_value, allowed_values):
"""Initialize the error with the unpermitted component."""
super(UnpermittedComponentError, self).__init__(
"{} was required to be one of {!r} but was {!r}".format(
component_name, list(sorted(allowed_values)), component_value,
component_name,
list(sorted(allowed_values)),
component_value,
),
component_name,
component_value,
Expand Down
4 changes: 3 additions & 1 deletion src/rfc3986/validators.py
Expand Up @@ -250,7 +250,9 @@ def ensure_one_of(allowed_values, uri, attribute):
value = getattr(uri, attribute)
if value is not None and allowed_values and value not in allowed_values:
raise exceptions.UnpermittedComponentError(
attribute, value, allowed_values,
attribute,
value,
allowed_values,
)


Expand Down
5 changes: 4 additions & 1 deletion tests/conftest.py
Expand Up @@ -58,7 +58,10 @@
"HtTpS",
]
equivalent_schemes_and_hostnames = list(
itertools.product(equivalent_schemes, equivalent_hostnames,)
itertools.product(
equivalent_schemes,
equivalent_hostnames,
)
)


Expand Down
15 changes: 13 additions & 2 deletions tests/test_builder.py
Expand Up @@ -65,7 +65,14 @@ def test_repr():


@pytest.mark.parametrize(
"scheme", ["https", "hTTps", "Https", "HtTpS", "HTTPS",]
"scheme",
[
"https",
"hTTps",
"Https",
"HtTpS",
"HTTPS",
],
)
def test_add_scheme(scheme):
"""Verify schemes are normalized when added."""
Expand Down Expand Up @@ -158,7 +165,11 @@ def test_add_port(port, expected):


@pytest.mark.parametrize(
"path", ["sigmavirus24/rfc3986", "/sigmavirus24/rfc3986",]
"path",
[
"sigmavirus24/rfc3986",
"/sigmavirus24/rfc3986",
],
)
def test_add_path(path):
"""Verify we normalize our path value."""
Expand Down
42 changes: 32 additions & 10 deletions tests/test_validators.py
Expand Up @@ -31,7 +31,8 @@ def test_allowing_schemes():
def test_allowing_hosts():
"""Verify the ability to select hosts to be allowed."""
validator = validators.Validator().allow_hosts(
"pypi.python.org", "pypi.org",
"pypi.python.org",
"pypi.org",
)

assert "pypi.python.org" in validator.allowed_hosts
Expand Down Expand Up @@ -161,7 +162,10 @@ def test_multiple_missing_components(uri):

@pytest.mark.parametrize(
"uri",
[rfc3986.uri_reference("smtp://"), rfc3986.uri_reference("telnet://"),],
[
rfc3986.uri_reference("smtp://"),
rfc3986.uri_reference("telnet://"),
],
)
def test_ensure_uri_has_a_scheme(uri):
"""Verify validation with allowed schemes."""
Expand All @@ -183,8 +187,14 @@ def test_allowed_hosts_and_schemes(uri, failed_component):
"""Verify each of these fails."""
validator = (
validators.Validator()
.allow_schemes("https", "ssh",)
.allow_hosts("github.com", "git.openstack.org",)
.allow_schemes(
"https",
"ssh",
)
.allow_hosts(
"github.com",
"git.openstack.org",
)
)
with pytest.raises(exceptions.UnpermittedComponentError) as caught_exc:
validator.validate(uri)
Expand Down Expand Up @@ -237,11 +247,22 @@ def test_allowed_hosts_and_schemes(uri, failed_component):
def test_successful_complex_validation(uri):
"""Verify we do not raise ValidationErrors for good URIs."""
validators.Validator().allow_schemes("https", "ssh",).allow_hosts(
"github.com", "bitbucket.org", "gitlab.com", "git.openstack.org",
"github.com",
"bitbucket.org",
"gitlab.com",
"git.openstack.org",
).allow_ports("22", "443",).require_presence_of(
"scheme", "host", "path",
"scheme",
"host",
"path",
).check_validity_of(
"scheme", "userinfo", "host", "port", "path", "query", "fragment",
"scheme",
"userinfo",
"host",
"port",
"path",
"query",
"fragment",
).validate(
uri
)
Expand All @@ -259,9 +280,10 @@ def test_invalid_uri_with_invalid_path(invalid_uri):
uri = rfc3986.uri_reference(invalid_uri)
uri = uri.copy_with(path="#foobar")
with pytest.raises(exceptions.InvalidComponentsError):
validators.Validator().check_validity_of("host", "path",).validate(
uri
)
validators.Validator().check_validity_of(
"host",
"path",
).validate(uri)


def test_validating_rfc_4007_ipv6_zone_ids():
Expand Down