blackbull.protocol.field_grammar¶
blackbull.protocol.field_grammar
¶
Shared HTTP field, authority and URI scheme grammar.
authority_is_valid = lru_cache(maxsize=256)(authority_is_valid)
module-attribute
¶
Whether value is a URI authority host [":" port] (RFC 3986 §3.2):
ASCII, no userinfo, a reg-name, IPv4 or bracketed IPv6 host.
FieldError
¶
Bases: ValueError
A field section that breaks the field grammar; the request gets 400.
field_line(line, *, check=True)
¶
Split one HTTP/1.1 field line (no CRLF) into its lowercase tchar name and its value without edge SP/HTAB (RFC 9112 §5).
The value carries no CTL unless check is false because the caller has
already proved the octets clean. Raises FieldError for obs-fold, a
missing colon, whitespace before the colon, a name outside tchar, or a CTL.
field_value(raw, *, check=True)
¶
Return raw without its edge SP/HTAB.
The result carries no CTL: raises FieldError for one, unless check
is false because the caller has already proved the octets clean.
host_field_value(fields)
¶
Return the value of the one host field in fields, or None when
there is none.
fields are (name, value) pairs whose values carry no edge SP/HTAB.
Raises FieldError for more than one field, an empty value, or a value
that is not an authority.
if_none_match_hit(value, etag)
¶
Whether an If-None-Match value matches etag by weak comparison:
*, or any listed entity-tag with W/ ignored (RFC 9110 §13.1.2).
list_members(value)
¶
Return the lowercase members of a comma-separated list value without OWS, empty members dropped (RFC 9110 §5.6.1). Not for case-sensitive members such as entity-tags.
media_type(value)
¶
Return the lowercase type/subtype of a media type or media range,
without its parameters (RFC 9110 §8.3.1); b'' for an empty value.
method_token_is_valid(value)
¶
RFC 9110 §9.1 method = token (§5.6.2 token = 1*tchar).
Both transports grade their method with this — HTTP/1.1 its request line,
HTTP/2 :method — so a method one of them refuses cannot run on the
other.
normalized_fields(pairs)
¶
Return pairs with every name lowercased and every value's edge SP/HTAB removed, in order.
Every returned name is lowercase tchar and every value is free of CTL.
Raises FieldError for a pair that is not two bytes, a name
outside tchar, or a value with a CTL.