httk.core.validation

Syntax validation predicates for IRIs and URLs.

Submodules

Functions

has_valid_percent_escapes(value)

Return whether every % in value introduces a valid percent-escape.

is_absolute_iri(value)

Return whether value is a minimally well-formed absolute IRI.

is_https_url(value, *[, allow_query])

Return whether value is a minimally well-formed absolute HTTPS URL.

is_root_relative_url(value)

Return whether value is a minimally well-formed root-relative URL.

Package Contents

httk.core.validation.has_valid_percent_escapes(value)[source]

Return whether every % in value introduces a valid percent-escape.

Each % must be followed by exactly two hexadecimal digits, including when the % sits at the end of the string, where the missing followers make the escape invalid.

Parameters:

value (str) – The candidate string.

Returns:

True if every % in value is followed by two hex digits.

Return type:

bool

httk.core.validation.is_absolute_iri(value)[source]

Return whether value is a minimally well-formed absolute IRI.

The check rejects whitespace, control characters, the C1 range, lone surrogates, the ASCII set <>"{}|\^`, and malformed percent-escapes, then requires a non-empty URL scheme.

Parameters:

value (str) – The candidate IRI string.

Returns:

True if value is a minimally well-formed absolute IRI.

Return type:

bool

httk.core.validation.is_https_url(value, *, allow_query=False)[source]

Return whether value is a minimally well-formed absolute HTTPS URL.

The value must be a well-formed absolute IRI whose scheme is exactly https, with a non-empty host, no userinfo, and no fragment; any explicit port must lie in 1..65535. A non-empty query is rejected unless allow_query is True.

Parameters:
  • value (str) – The candidate URL string.

  • allow_query (bool) – Whether a non-empty query component is permitted.

Returns:

True if value is a minimally well-formed absolute HTTPS URL.

Return type:

bool

httk.core.validation.is_root_relative_url(value)[source]

Return whether value is a minimally well-formed root-relative URL.

A root-relative URL begins with a single /, carries no scheme, network location, or fragment, and its path component is valid IRI syntax.

Parameters:

value (str) – The candidate URL string.

Returns:

True if value is a minimally well-formed root-relative URL.

Return type:

bool