rfc3987_syntax2.syntax_helpers

Attributes

RFC3987_SYNTAX_PARSER_TYPE

RFC3987_SYNTAX_GRAMMAR_PATH

RFC3987_SYNTAX_TERMS

All supported RFC 3987 grammar rule names exposed by this module.

T_SYNTAX_PARSER_TERM

Top-level RFC 3987 parser start terms accepted by parse() and is_valid_syntax().

T_SYNTAX_VALIDATOR

Callable validator for one RFC 3987 grammar rule.

RFC3987_SYNTAX_TERM_VALIDATORS

Mapping from syntax term to validator.

grammar

Lark grammar text for RFC 3987.

syntax_parser

Lazily initialized parser for RFC 3987 syntax.

Functions

parse(→ lark.ParseTree)

Parse text as one of the top-level RFC 3987 syntax terms.

is_valid_syntax(→ bool)

Check whether text is valid for a top-level RFC 3987 syntax term.

make_syntax_validator(→ T_SYNTAX_VALIDATOR)

Create a validator function for a specific RFC 3987 grammar rule.

is_valid_syntax_iri(→ bool)

Validate that input text conforms to the RFC 3987 IRI rule.

is_valid_syntax_iri_reference(→ bool)

Validate that input text conforms to the RFC 3987 IRI-reference rule.

is_valid_syntax_absolute_iri(→ bool)

Validate that input text conforms to the RFC 3987 absolute-IRI rule.

is_valid_syntax_scheme(→ bool)

Validate that input text conforms to the RFC 3987 scheme rule.

is_valid_syntax_ihier_part(→ bool)

Validate that input text conforms to the RFC 3987 ihier-part rule.

is_valid_syntax_irelative_ref(→ bool)

Validate that input text conforms to the RFC 3987 irelative-ref rule.

is_valid_syntax_irelative_part(→ bool)

Validate that input text conforms to the RFC 3987 irelative-part rule.

is_valid_syntax_iauthority(→ bool)

Validate that input text conforms to the RFC 3987 iauthority rule.

is_valid_syntax_iuserinfo(→ bool)

Validate that input text conforms to the RFC 3987 iuserinfo rule.

is_valid_syntax_ihost(→ bool)

Validate that input text conforms to the RFC 3987 ihost rule.

is_valid_syntax_ireg_name(→ bool)

Validate that input text conforms to the RFC 3987 ireg-name rule.

is_valid_syntax_ipath(→ bool)

Validate that input text conforms to the RFC 3987 ipath rule.

is_valid_syntax_ipath_abempty(→ bool)

Validate that input text conforms to the RFC 3987 ipath-abempty rule.

is_valid_syntax_ipath_absolute(→ bool)

Validate that input text conforms to the RFC 3987 ipath-absolute rule.

is_valid_syntax_ipath_noscheme(→ bool)

Validate that input text conforms to the RFC 3987 ipath-noscheme rule.

is_valid_syntax_ipath_rootless(→ bool)

Validate that input text conforms to the RFC 3987 ipath-rootless rule.

is_valid_syntax_ipath_empty(→ bool)

Validate that input text conforms to the RFC 3987 ipath-empty rule.

is_valid_syntax_isegment(→ bool)

Validate that input text conforms to the RFC 3987 isegment rule.

is_valid_syntax_isegment_nz(→ bool)

Validate that input text conforms to the RFC 3987 isegment-nz rule.

is_valid_syntax_isegment_nz_nc(→ bool)

Validate that input text conforms to the RFC 3987 isegment-nz-nc rule.

is_valid_syntax_ipchar(→ bool)

Validate that input text conforms to the RFC 3987 ipchar rule.

is_valid_syntax_iquery(→ bool)

Validate that input text conforms to the RFC 3987 iquery rule.

is_valid_syntax_ifragment(→ bool)

Validate that input text conforms to the RFC 3987 ifragment rule.

is_valid_syntax_iunreserved(→ bool)

Validate that input text conforms to the RFC 3987 iunreserved rule.

is_valid_syntax_ucschar(→ bool)

Validate that input text conforms to the RFC 3987 ucschar rule.

is_valid_syntax_iprivate(→ bool)

Validate that input text conforms to the RFC 3987 iprivate rule.

is_valid_syntax_sub_delims(→ bool)

Validate that input text conforms to the RFC 3987 sub-delims rule.

is_valid_syntax_ip_literal(→ bool)

Validate that input text conforms to the RFC 3987 IP-literal rule.

is_valid_syntax_ipvfuture(→ bool)

Validate that input text conforms to the RFC 3987 IPvFuture rule.

is_valid_syntax_ipv6address(→ bool)

Validate that input text conforms to the RFC 3987 IPv6address rule.

is_valid_syntax_h16(→ bool)

Validate that input text conforms to the RFC 3987 h16 rule.

is_valid_syntax_ls32(→ bool)

Validate that input text conforms to the RFC 3987 ls32 rule.

is_valid_syntax_ipv4address(→ bool)

Validate that input text conforms to the RFC 3987 IPv4address rule.

is_valid_syntax_dec_octet(→ bool)

Validate that input text conforms to the RFC 3987 dec-octet rule.

is_valid_syntax_digit(→ bool)

Validate that input text conforms to the RFC 3987 DIGIT rule.

is_valid_syntax_unreserved(→ bool)

Validate that input text conforms to the RFC 3987 unreserved rule.

is_valid_syntax_alpha(→ bool)

Validate that input text conforms to the RFC 3987 ALPHA rule.

is_valid_syntax_hexdig(→ bool)

Validate that input text conforms to the RFC 3987 HEXDIG rule.

is_valid_syntax_port(→ bool)

Validate that input text conforms to the RFC 3987 port rule.

is_valid_syntax_pct_encoded(→ bool)

Validate that input text conforms to the RFC 3987 pct-encoded rule.

Module Contents

rfc3987_syntax2.syntax_helpers.RFC3987_SYNTAX_PARSER_TYPE: Final[str] = 'earley'
rfc3987_syntax2.syntax_helpers.RFC3987_SYNTAX_GRAMMAR_PATH: Final[pathlib.Path]
rfc3987_syntax2.syntax_helpers.RFC3987_SYNTAX_TERMS: Final[Sequence[str]] = ['iri', 'iri_reference', 'absolute_iri', 'scheme', 'ihier_part', 'irelative_ref',...

All supported RFC 3987 grammar rule names exposed by this module.

These term names can be used to select validators from RFC3987_SYNTAX_TERM_VALIDATORS and correspond to rules defined in the RFC 3987 Lark grammar.

rfc3987_syntax2.syntax_helpers.T_SYNTAX_PARSER_TERM

Top-level RFC 3987 parser start terms accepted by parse() and is_valid_syntax().

Allowed values are "iri", "iri_reference", and "absolute_iri".

rfc3987_syntax2.syntax_helpers.parse(term: T_SYNTAX_PARSER_TERM, value: str) → lark.ParseTree

Parse text as one of the top-level RFC 3987 syntax terms.

Parameters:
  • term – Start rule used for parsing. Must be one of "iri", "iri_reference", or "absolute_iri".

  • value – Input text to parse.

Returns:

The Lark parse tree for value under the selected start rule.

Raises:

lark.exceptions.LarkError – If parser initialization fails or parsing cannot be completed.

rfc3987_syntax2.syntax_helpers.is_valid_syntax(term: T_SYNTAX_PARSER_TERM, value: str) → bool

Check whether text is valid for a top-level RFC 3987 syntax term.

This is a boolean convenience wrapper around parse().

Warning

Emits a RuntimeWarning (via warnings.warn()) when a non-UnexpectedInput lark.exceptions.LarkError occurs.

Parameters:
  • term – Start rule used for validation. Must be one of "iri", "iri_reference", or "absolute_iri".

  • value – Input text to validate.

Returns:

True if parsing succeeds; otherwise False.

rfc3987_syntax2.syntax_helpers.T_SYNTAX_VALIDATOR

Callable validator for one RFC 3987 grammar rule.

Parameters:

text – Input text to validate.

Returns:

True if text matches the target rule, otherwise False.

rfc3987_syntax2.syntax_helpers.make_syntax_validator(rule_name: str) → T_SYNTAX_VALIDATOR

Create a validator function for a specific RFC 3987 grammar rule.

The returned callable lazily initializes and caches a dedicated lark.Lark parser configured with start=rule_name and parser=RFC3987_SYNTAX_PARSER_TYPE.

Parameters:

rule_name – Grammar rule name to validate against. Must be a value from RFC3987_SYNTAX_TERMS.

Returns:

A callable (text: str) -> bool that returns True when parsing succeeds and False if a lark.exceptions.LarkError is raised.

rfc3987_syntax2.syntax_helpers.is_valid_syntax_iri(text: str) → bool

Validate that input text conforms to the RFC 3987 IRI rule.

rfc3987_syntax2.syntax_helpers.is_valid_syntax_iri_reference(text: str) → bool

Validate that input text conforms to the RFC 3987 IRI-reference rule.

rfc3987_syntax2.syntax_helpers.is_valid_syntax_absolute_iri(text: str) → bool

Validate that input text conforms to the RFC 3987 absolute-IRI rule.

rfc3987_syntax2.syntax_helpers.is_valid_syntax_scheme(text: str) → bool

Validate that input text conforms to the RFC 3987 scheme rule.

rfc3987_syntax2.syntax_helpers.is_valid_syntax_ihier_part(text: str) → bool

Validate that input text conforms to the RFC 3987 ihier-part rule.

rfc3987_syntax2.syntax_helpers.is_valid_syntax_irelative_ref(text: str) → bool

Validate that input text conforms to the RFC 3987 irelative-ref rule.

rfc3987_syntax2.syntax_helpers.is_valid_syntax_irelative_part(text: str) → bool

Validate that input text conforms to the RFC 3987 irelative-part rule.

rfc3987_syntax2.syntax_helpers.is_valid_syntax_iauthority(text: str) → bool

Validate that input text conforms to the RFC 3987 iauthority rule.

rfc3987_syntax2.syntax_helpers.is_valid_syntax_iuserinfo(text: str) → bool

Validate that input text conforms to the RFC 3987 iuserinfo rule.

rfc3987_syntax2.syntax_helpers.is_valid_syntax_ihost(text: str) → bool

Validate that input text conforms to the RFC 3987 ihost rule.

rfc3987_syntax2.syntax_helpers.is_valid_syntax_ireg_name(text: str) → bool

Validate that input text conforms to the RFC 3987 ireg-name rule.

rfc3987_syntax2.syntax_helpers.is_valid_syntax_ipath(text: str) → bool

Validate that input text conforms to the RFC 3987 ipath rule.

rfc3987_syntax2.syntax_helpers.is_valid_syntax_ipath_abempty(text: str) → bool

Validate that input text conforms to the RFC 3987 ipath-abempty rule.

rfc3987_syntax2.syntax_helpers.is_valid_syntax_ipath_absolute(text: str) → bool

Validate that input text conforms to the RFC 3987 ipath-absolute rule.

rfc3987_syntax2.syntax_helpers.is_valid_syntax_ipath_noscheme(text: str) → bool

Validate that input text conforms to the RFC 3987 ipath-noscheme rule.

rfc3987_syntax2.syntax_helpers.is_valid_syntax_ipath_rootless(text: str) → bool

Validate that input text conforms to the RFC 3987 ipath-rootless rule.

rfc3987_syntax2.syntax_helpers.is_valid_syntax_ipath_empty(text: str) → bool

Validate that input text conforms to the RFC 3987 ipath-empty rule.

rfc3987_syntax2.syntax_helpers.is_valid_syntax_isegment(text: str) → bool

Validate that input text conforms to the RFC 3987 isegment rule.

rfc3987_syntax2.syntax_helpers.is_valid_syntax_isegment_nz(text: str) → bool

Validate that input text conforms to the RFC 3987 isegment-nz rule.

rfc3987_syntax2.syntax_helpers.is_valid_syntax_isegment_nz_nc(text: str) → bool

Validate that input text conforms to the RFC 3987 isegment-nz-nc rule.

rfc3987_syntax2.syntax_helpers.is_valid_syntax_ipchar(text: str) → bool

Validate that input text conforms to the RFC 3987 ipchar rule.

rfc3987_syntax2.syntax_helpers.is_valid_syntax_iquery(text: str) → bool

Validate that input text conforms to the RFC 3987 iquery rule.

rfc3987_syntax2.syntax_helpers.is_valid_syntax_ifragment(text: str) → bool

Validate that input text conforms to the RFC 3987 ifragment rule.

rfc3987_syntax2.syntax_helpers.is_valid_syntax_iunreserved(text: str) → bool

Validate that input text conforms to the RFC 3987 iunreserved rule.

rfc3987_syntax2.syntax_helpers.is_valid_syntax_ucschar(text: str) → bool

Validate that input text conforms to the RFC 3987 ucschar rule.

rfc3987_syntax2.syntax_helpers.is_valid_syntax_iprivate(text: str) → bool

Validate that input text conforms to the RFC 3987 iprivate rule.

rfc3987_syntax2.syntax_helpers.is_valid_syntax_sub_delims(text: str) → bool

Validate that input text conforms to the RFC 3987 sub-delims rule.

rfc3987_syntax2.syntax_helpers.is_valid_syntax_ip_literal(text: str) → bool

Validate that input text conforms to the RFC 3987 IP-literal rule.

rfc3987_syntax2.syntax_helpers.is_valid_syntax_ipvfuture(text: str) → bool

Validate that input text conforms to the RFC 3987 IPvFuture rule.

rfc3987_syntax2.syntax_helpers.is_valid_syntax_ipv6address(text: str) → bool

Validate that input text conforms to the RFC 3987 IPv6address rule.

rfc3987_syntax2.syntax_helpers.is_valid_syntax_h16(text: str) → bool

Validate that input text conforms to the RFC 3987 h16 rule.

rfc3987_syntax2.syntax_helpers.is_valid_syntax_ls32(text: str) → bool

Validate that input text conforms to the RFC 3987 ls32 rule.

rfc3987_syntax2.syntax_helpers.is_valid_syntax_ipv4address(text: str) → bool

Validate that input text conforms to the RFC 3987 IPv4address rule.

rfc3987_syntax2.syntax_helpers.is_valid_syntax_dec_octet(text: str) → bool

Validate that input text conforms to the RFC 3987 dec-octet rule.

rfc3987_syntax2.syntax_helpers.is_valid_syntax_digit(text: str) → bool

Validate that input text conforms to the RFC 3987 DIGIT rule.

rfc3987_syntax2.syntax_helpers.is_valid_syntax_unreserved(text: str) → bool

Validate that input text conforms to the RFC 3987 unreserved rule.

rfc3987_syntax2.syntax_helpers.is_valid_syntax_alpha(text: str) → bool

Validate that input text conforms to the RFC 3987 ALPHA rule.

rfc3987_syntax2.syntax_helpers.is_valid_syntax_hexdig(text: str) → bool

Validate that input text conforms to the RFC 3987 HEXDIG rule.

rfc3987_syntax2.syntax_helpers.is_valid_syntax_port(text: str) → bool

Validate that input text conforms to the RFC 3987 port rule.

rfc3987_syntax2.syntax_helpers.is_valid_syntax_pct_encoded(text: str) → bool

Validate that input text conforms to the RFC 3987 pct-encoded rule.

rfc3987_syntax2.syntax_helpers.RFC3987_SYNTAX_TERM_VALIDATORS: Final[Mapping[str, T_SYNTAX_VALIDATOR]]

Mapping from syntax term to validator.

Allowed keys are the RFC3987 term literals (see RFC3987_SYNTAX_TERMS).

rfc3987_syntax2.syntax_helpers.grammar: Final[str]

Lark grammar text for RFC 3987.

rfc3987_syntax2.syntax_helpers.syntax_parser: Final[lark.Lark]

Lazily initialized parser for RFC 3987 syntax.