rfc3987_syntax2.syntax_helpers ============================== .. py:module:: rfc3987_syntax2.syntax_helpers Attributes ---------- .. autoapisummary:: rfc3987_syntax2.syntax_helpers.RFC3987_SYNTAX_PARSER_TYPE rfc3987_syntax2.syntax_helpers.RFC3987_SYNTAX_GRAMMAR_PATH rfc3987_syntax2.syntax_helpers.RFC3987_SYNTAX_TERMS rfc3987_syntax2.syntax_helpers.T_SYNTAX_PARSER_TERM rfc3987_syntax2.syntax_helpers.T_SYNTAX_VALIDATOR rfc3987_syntax2.syntax_helpers.RFC3987_SYNTAX_TERM_VALIDATORS rfc3987_syntax2.syntax_helpers.grammar rfc3987_syntax2.syntax_helpers.syntax_parser Functions --------- .. autoapisummary:: rfc3987_syntax2.syntax_helpers.parse rfc3987_syntax2.syntax_helpers.is_valid_syntax rfc3987_syntax2.syntax_helpers.make_syntax_validator rfc3987_syntax2.syntax_helpers.is_valid_syntax_iri rfc3987_syntax2.syntax_helpers.is_valid_syntax_iri_reference rfc3987_syntax2.syntax_helpers.is_valid_syntax_absolute_iri rfc3987_syntax2.syntax_helpers.is_valid_syntax_scheme rfc3987_syntax2.syntax_helpers.is_valid_syntax_ihier_part rfc3987_syntax2.syntax_helpers.is_valid_syntax_irelative_ref rfc3987_syntax2.syntax_helpers.is_valid_syntax_irelative_part rfc3987_syntax2.syntax_helpers.is_valid_syntax_iauthority rfc3987_syntax2.syntax_helpers.is_valid_syntax_iuserinfo rfc3987_syntax2.syntax_helpers.is_valid_syntax_ihost rfc3987_syntax2.syntax_helpers.is_valid_syntax_ireg_name rfc3987_syntax2.syntax_helpers.is_valid_syntax_ipath rfc3987_syntax2.syntax_helpers.is_valid_syntax_ipath_abempty rfc3987_syntax2.syntax_helpers.is_valid_syntax_ipath_absolute rfc3987_syntax2.syntax_helpers.is_valid_syntax_ipath_noscheme rfc3987_syntax2.syntax_helpers.is_valid_syntax_ipath_rootless rfc3987_syntax2.syntax_helpers.is_valid_syntax_ipath_empty rfc3987_syntax2.syntax_helpers.is_valid_syntax_isegment rfc3987_syntax2.syntax_helpers.is_valid_syntax_isegment_nz rfc3987_syntax2.syntax_helpers.is_valid_syntax_isegment_nz_nc rfc3987_syntax2.syntax_helpers.is_valid_syntax_ipchar rfc3987_syntax2.syntax_helpers.is_valid_syntax_iquery rfc3987_syntax2.syntax_helpers.is_valid_syntax_ifragment rfc3987_syntax2.syntax_helpers.is_valid_syntax_iunreserved rfc3987_syntax2.syntax_helpers.is_valid_syntax_ucschar rfc3987_syntax2.syntax_helpers.is_valid_syntax_iprivate rfc3987_syntax2.syntax_helpers.is_valid_syntax_sub_delims rfc3987_syntax2.syntax_helpers.is_valid_syntax_ip_literal rfc3987_syntax2.syntax_helpers.is_valid_syntax_ipvfuture rfc3987_syntax2.syntax_helpers.is_valid_syntax_ipv6address rfc3987_syntax2.syntax_helpers.is_valid_syntax_h16 rfc3987_syntax2.syntax_helpers.is_valid_syntax_ls32 rfc3987_syntax2.syntax_helpers.is_valid_syntax_ipv4address rfc3987_syntax2.syntax_helpers.is_valid_syntax_dec_octet rfc3987_syntax2.syntax_helpers.is_valid_syntax_digit rfc3987_syntax2.syntax_helpers.is_valid_syntax_unreserved rfc3987_syntax2.syntax_helpers.is_valid_syntax_alpha rfc3987_syntax2.syntax_helpers.is_valid_syntax_hexdig rfc3987_syntax2.syntax_helpers.is_valid_syntax_port rfc3987_syntax2.syntax_helpers.is_valid_syntax_pct_encoded Module Contents --------------- .. py:data:: RFC3987_SYNTAX_PARSER_TYPE :type: Final[str] :value: 'earley' .. py:data:: RFC3987_SYNTAX_GRAMMAR_PATH :type: Final[pathlib.Path] .. py:data:: RFC3987_SYNTAX_TERMS :type: Final[Sequence[str]] :value: ['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 :data:`RFC3987_SYNTAX_TERM_VALIDATORS` and correspond to rules defined in the RFC 3987 Lark grammar. .. py:data:: T_SYNTAX_PARSER_TERM Top-level RFC 3987 parser start terms accepted by :func:`parse` and :func:`is_valid_syntax`. Allowed values are ``"iri"``, ``"iri_reference"``, and ``"absolute_iri"``. .. py:function:: parse(term: T_SYNTAX_PARSER_TERM, value: str) -> lark.ParseTree Parse text as one of the top-level RFC 3987 syntax terms. :param term: Start rule used for parsing. Must be one of ``"iri"``, ``"iri_reference"``, or ``"absolute_iri"``. :param value: Input text to parse. :return: The Lark parse tree for ``value`` under the selected start rule. :raises lark.exceptions.LarkError: If parser initialization fails or parsing cannot be completed. .. py:function:: 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 :func:`parse`. .. warning:: Emits a ``RuntimeWarning`` (via :func:`warnings.warn`) when a non-``UnexpectedInput`` ``lark.exceptions.LarkError`` occurs. :param term: Start rule used for validation. Must be one of ``"iri"``, ``"iri_reference"``, or ``"absolute_iri"``. :param value: Input text to validate. :return: ``True`` if parsing succeeds; otherwise ``False``. .. py:data:: T_SYNTAX_VALIDATOR Callable validator for one RFC 3987 grammar rule. :param text: Input text to validate. :return: ``True`` if ``text`` matches the target rule, otherwise ``False``. .. py:function:: 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 :class:`lark.Lark` parser configured with ``start=rule_name`` and ``parser=RFC3987_SYNTAX_PARSER_TYPE``. :param rule_name: Grammar rule name to validate against. Must be a value from :data:`RFC3987_SYNTAX_TERMS`. :return: A callable ``(text: str) -> bool`` that returns ``True`` when parsing succeeds and ``False`` if a ``lark.exceptions.LarkError`` is raised. .. py:function:: is_valid_syntax_iri(text: str) -> bool Validate that input text conforms to the RFC 3987 ``IRI`` rule. .. py:function:: is_valid_syntax_iri_reference(text: str) -> bool Validate that input text conforms to the RFC 3987 ``IRI-reference`` rule. .. py:function:: is_valid_syntax_absolute_iri(text: str) -> bool Validate that input text conforms to the RFC 3987 ``absolute-IRI`` rule. .. py:function:: is_valid_syntax_scheme(text: str) -> bool Validate that input text conforms to the RFC 3987 ``scheme`` rule. .. py:function:: is_valid_syntax_ihier_part(text: str) -> bool Validate that input text conforms to the RFC 3987 ``ihier-part`` rule. .. py:function:: is_valid_syntax_irelative_ref(text: str) -> bool Validate that input text conforms to the RFC 3987 ``irelative-ref`` rule. .. py:function:: is_valid_syntax_irelative_part(text: str) -> bool Validate that input text conforms to the RFC 3987 ``irelative-part`` rule. .. py:function:: is_valid_syntax_iauthority(text: str) -> bool Validate that input text conforms to the RFC 3987 ``iauthority`` rule. .. py:function:: is_valid_syntax_iuserinfo(text: str) -> bool Validate that input text conforms to the RFC 3987 ``iuserinfo`` rule. .. py:function:: is_valid_syntax_ihost(text: str) -> bool Validate that input text conforms to the RFC 3987 ``ihost`` rule. .. py:function:: is_valid_syntax_ireg_name(text: str) -> bool Validate that input text conforms to the RFC 3987 ``ireg-name`` rule. .. py:function:: is_valid_syntax_ipath(text: str) -> bool Validate that input text conforms to the RFC 3987 ``ipath`` rule. .. py:function:: is_valid_syntax_ipath_abempty(text: str) -> bool Validate that input text conforms to the RFC 3987 ``ipath-abempty`` rule. .. py:function:: is_valid_syntax_ipath_absolute(text: str) -> bool Validate that input text conforms to the RFC 3987 ``ipath-absolute`` rule. .. py:function:: is_valid_syntax_ipath_noscheme(text: str) -> bool Validate that input text conforms to the RFC 3987 ``ipath-noscheme`` rule. .. py:function:: is_valid_syntax_ipath_rootless(text: str) -> bool Validate that input text conforms to the RFC 3987 ``ipath-rootless`` rule. .. py:function:: is_valid_syntax_ipath_empty(text: str) -> bool Validate that input text conforms to the RFC 3987 ``ipath-empty`` rule. .. py:function:: is_valid_syntax_isegment(text: str) -> bool Validate that input text conforms to the RFC 3987 ``isegment`` rule. .. py:function:: is_valid_syntax_isegment_nz(text: str) -> bool Validate that input text conforms to the RFC 3987 ``isegment-nz`` rule. .. py:function:: is_valid_syntax_isegment_nz_nc(text: str) -> bool Validate that input text conforms to the RFC 3987 ``isegment-nz-nc`` rule. .. py:function:: is_valid_syntax_ipchar(text: str) -> bool Validate that input text conforms to the RFC 3987 ``ipchar`` rule. .. py:function:: is_valid_syntax_iquery(text: str) -> bool Validate that input text conforms to the RFC 3987 ``iquery`` rule. .. py:function:: is_valid_syntax_ifragment(text: str) -> bool Validate that input text conforms to the RFC 3987 ``ifragment`` rule. .. py:function:: is_valid_syntax_iunreserved(text: str) -> bool Validate that input text conforms to the RFC 3987 ``iunreserved`` rule. .. py:function:: is_valid_syntax_ucschar(text: str) -> bool Validate that input text conforms to the RFC 3987 ``ucschar`` rule. .. py:function:: is_valid_syntax_iprivate(text: str) -> bool Validate that input text conforms to the RFC 3987 ``iprivate`` rule. .. py:function:: is_valid_syntax_sub_delims(text: str) -> bool Validate that input text conforms to the RFC 3987 ``sub-delims`` rule. .. py:function:: is_valid_syntax_ip_literal(text: str) -> bool Validate that input text conforms to the RFC 3987 ``IP-literal`` rule. .. py:function:: is_valid_syntax_ipvfuture(text: str) -> bool Validate that input text conforms to the RFC 3987 ``IPvFuture`` rule. .. py:function:: is_valid_syntax_ipv6address(text: str) -> bool Validate that input text conforms to the RFC 3987 ``IPv6address`` rule. .. py:function:: is_valid_syntax_h16(text: str) -> bool Validate that input text conforms to the RFC 3987 ``h16`` rule. .. py:function:: is_valid_syntax_ls32(text: str) -> bool Validate that input text conforms to the RFC 3987 ``ls32`` rule. .. py:function:: is_valid_syntax_ipv4address(text: str) -> bool Validate that input text conforms to the RFC 3987 ``IPv4address`` rule. .. py:function:: is_valid_syntax_dec_octet(text: str) -> bool Validate that input text conforms to the RFC 3987 ``dec-octet`` rule. .. py:function:: is_valid_syntax_digit(text: str) -> bool Validate that input text conforms to the RFC 3987 ``DIGIT`` rule. .. py:function:: is_valid_syntax_unreserved(text: str) -> bool Validate that input text conforms to the RFC 3987 ``unreserved`` rule. .. py:function:: is_valid_syntax_alpha(text: str) -> bool Validate that input text conforms to the RFC 3987 ``ALPHA`` rule. .. py:function:: is_valid_syntax_hexdig(text: str) -> bool Validate that input text conforms to the RFC 3987 ``HEXDIG`` rule. .. py:function:: is_valid_syntax_port(text: str) -> bool Validate that input text conforms to the RFC 3987 ``port`` rule. .. py:function:: is_valid_syntax_pct_encoded(text: str) -> bool Validate that input text conforms to the RFC 3987 ``pct-encoded`` rule. .. py:data:: RFC3987_SYNTAX_TERM_VALIDATORS :type: Final[Mapping[str, T_SYNTAX_VALIDATOR]] Mapping from syntax term to validator. Allowed keys are the RFC3987 term literals (see :data:`RFC3987_SYNTAX_TERMS`). .. py:data:: grammar :type: Final[str] Lark grammar text for RFC 3987. .. py:data:: syntax_parser :type: Final[lark.Lark] Lazily initialized parser for RFC 3987 syntax.