def media_range(no_q=False): return Parametrized << ( ( literal('*/*') | type_ + '/' + '*' | MediaType << type_ + '/' + subtype ) * ( MultiDict << many( skip(OWS * ';' * OWS) * parameter(exclude=['q'] if no_q else []) ) ) ) > named(u'media-range', RFC(7231), is_pivot=True) qvalue = (float << '0' + maybe_str('.' + string_times(0, 3, DIGIT)) | float << '1' + maybe_str('.' + string_times(0, 3, '0'))) > pivot weight = skip(OWS * ';' * OWS * 'q=') * qvalue > pivot accept_ext = (skip(OWS * ';' * OWS) * token * maybe(skip('=') * (token | quoted_string))) > pivot def _prepend_q(q, xs): return MultiDict([(CaseInsensitive(u'q'), q)] + xs) accept_params = _prepend_q << weight * many(accept_ext) > pivot Accept = comma_list( Parametrized << (media_range(no_q=True) * maybe(accept_params, MultiDict()))) > pivot charset = Charset << token > pivot
Age = delta_seconds > pivot cache_directive = Parametrized << ( (CacheDirective << token) * maybe(skip('=') * (mark(token) | mark(quoted_string)))) > pivot Cache_Control = comma_list1(cache_directive) > pivot Expires = HTTP_date > pivot def extension_pragma(exclude_no_cache=False): return Parametrized << ( (token__excluding(['no-cache']) if exclude_no_cache else token) * maybe(skip('=') * (token | quoted_string)) ) > named(u'extension-pragma', RFC(7234), is_pivot=True) pragma_directive = (CaseInsensitive << literal('no-cache') | extension_pragma(exclude_no_cache=True)) > pivot Pragma = comma_list1(pragma_directive) > pivot warn_code = WarnCode << string_times(3, 3, DIGIT) > pivot warn_agent = uri_host + maybe_str(':' + port) | pseudonym > pivot warn_text = quoted_string > pivot warn_date = skip(DQUOTE) * HTTP_date * skip(DQUOTE) > pivot warning_value = WarningValue << (warn_code * skip(SP) * warn_agent * skip(SP) * warn_text * maybe(skip(SP) * warn_date)) > pivot Warning_ = comma_list1(warning_value) > pivot fill_names(globals(), RFC(7234))
(subst([None, None]) << literal(',') | (lambda x: [x]) << group(element)) + many(skip(OWS * ',') * maybe(skip(OWS) * element)) ) > named(u'#rule', RFC(7230, section=(7,))) def comma_list1(element): return _collect_elements << ( many(subst(None) << ',' * OWS) + ((lambda x: [x]) << group(element)) + many(skip(OWS * ',') * maybe(skip(OWS) * element)) ) > named(u'1#rule', RFC(7230, section=(7,))) method = Method << token > pivot absolute_path = string1('/' + segment) > pivot partial_URI = relative_part + maybe_str('?' + query) > pivot origin_form = absolute_path + maybe_str('?' + query) > pivot absolute_form = absolute_URI > pivot authority_form = authority > pivot asterisk_form = literal('*') > auto request_target = (origin_form | absolute_form | authority_form | asterisk_form) > pivot HTTP_name = octet(0x48) + octet(0x54) + octet(0x54) + octet(0x50) > auto HTTP_version = HTTPVersion << HTTP_name + '/' + DIGIT + '.' + DIGIT > pivot status_code = StatusCode << string_times(3, 3, DIGIT) > pivot reason_phrase = string(HTAB | SP | VCHAR | obs_text) > pivot
from httpolice.citation import Citation from httpolice.parse import (auto, case_sens, fill_names, literal, maybe_str, pivot) from httpolice.syntax.rfc3986 import host, port, scheme from httpolice.syntax.rfc7230 import (comma_list, comma_list1, field_name, method) from httpolice.syntax.rfc7234 import delta_seconds # WHATWG actually uses their own definitions for scheme, host, and port, # but that's a bit too far for HTTPolice, we can live with RFC 3986. origin = scheme + '://' + host + maybe_str(':' + port) > pivot origin_or_null = origin | case_sens('null') > pivot Origin = origin_or_null > pivot Access_Control_Request_Method = method > pivot Access_Control_Request_Headers = comma_list1(field_name) > pivot wildcard = literal('*') > auto Access_Control_Allow_Origin = origin_or_null | wildcard > pivot Access_Control_Allow_Credentials = case_sens('true') > pivot Access_Control_Expose_Headers = comma_list(field_name) > pivot Access_Control_Max_Age = delta_seconds > pivot Access_Control_Allow_Methods = comma_list(method) > pivot Access_Control_Allow_Headers = comma_list(field_name) > pivot X_Content_Type_Options = literal('nosniff') > pivot Cross_Origin_Resource_Policy = (case_sens('same-origin') | case_sens('same-site')) > pivot fill_names(globals(), Citation(u'WHATWG Fetch', u'https://fetch.spec.whatwg.org/'))
'cel-gaulish' | 'no-bok' | 'no-nyn' | 'zh-guoyu' | 'zh-hakka' | 'zh-min' | 'zh-min-nan' | 'zh-xiang') > auto grandfathered = irregular | regular > pivot privateuse = 'x' + string1('-' + string_times(1, 8, alphanum)) > pivot extlang = (string_times(3, 3, ALPHA) + string_times(0, 2, '-' + string_times(3, 3, ALPHA))) > pivot language = (string_times(2, 3, ALPHA) + maybe_str('-' + extlang) | string_times(4, 4, ALPHA) | string_times(5, 8, ALPHA)) > pivot script = string_times(4, 4, ALPHA) > pivot region = string_times(2, 2, ALPHA) | string_times(3, 3, DIGIT) > pivot variant = (string_times(5, 8, alphanum) | (DIGIT + string_times(3, 3, alphanum))) > pivot extension = (singleton + string1('-' + string_times(2, 8, alphanum))) > pivot langtag = (language + maybe_str('-' + script) + maybe_str('-' + region) + string('-' + variant) + string('-' + extension) + maybe_str('-' + privateuse)) > pivot Language_Tag = (LanguageTag << langtag |
return r HTTP_date = (_check_day_of_week << IMF_fixdate | _check_day_of_week << obs_date) > pivot def media_range(no_q=False): return Parametrized << ( (literal('*/*') | type_ + '/' + '*' | _check_media_type << (MediaType << type_ + '/' + subtype)) * (MultiDict << many( skip(OWS * ';' * OWS) * parameter(exclude=['q'] if no_q else []))) ) > named(u'media-range', RFC(7231), is_pivot=True) qvalue = (float << '0' + maybe_str('.' + string_times(0, 3, DIGIT)) | float << '1' + maybe_str('.' + string_times(0, 3, '0'))) > pivot weight = skip(OWS * ';' * OWS * 'q=') * qvalue > pivot accept_ext = (skip(OWS * ';' * OWS) * token * maybe(skip('=') * (token | quoted_string))) > pivot def _prepend_q(q, xs): return MultiDict([(CaseInsensitive(u'q'), q)] + xs) accept_params = _prepend_q << weight * many(accept_ext) > pivot Accept = comma_list(Parametrized << ( media_range(no_q=True) * maybe(accept_params, MultiDict()))) > pivot
protocol_id = _check_protocol_id << token > pivot @can_complain def _check_alt_authority(complain, value): return parse(value, maybe_str(uri_host) + ':' + port, complain, 1257, authority=value) alt_authority = _check_alt_authority << quoted_string > pivot alternative = protocol_id * skip('=') * alt_authority > pivot parameter = ((AltSvcParam << token) * skip('=') * (token | quoted_string)) > pivot alt_value = Parametrized << ( alternative * (MultiDict << many(skip(OWS * ';' * OWS) * parameter))) > pivot Alt_Svc = clear | comma_list1(alt_value) > pivot ma = delta_seconds > pivot persist = subst(True) << literal('1') > pivot Alt_Used = uri_host + maybe_str(':' + port) > pivot fill_names(globals(), RFC(7838))
def _check_alt_authority(complain, value): return parse(value, maybe_str(uri_host) + ':' + port, complain, 1257, authority=value)
correct_encoded_id += pct_encode(c, safe='').upper() if encoded_id != correct_encoded_id: complain(1256, actual=encoded_id, correct=correct_encoded_id) return decoded_id protocol_id = _check_protocol_id << token > pivot @can_complain def _check_alt_authority(complain, value): return parse(value, maybe_str(uri_host) + ':' + port, complain, 1257, authority=value) alt_authority = _check_alt_authority << quoted_string > pivot alternative = protocol_id * skip('=') * alt_authority > pivot parameter = ((AltSvcParam << token) * skip('=') * (token | quoted_string)) > pivot alt_value = Parametrized << ( alternative * (MultiDict << many(skip(OWS * ';' * OWS) * parameter))) > pivot Alt_Svc = clear | comma_list1(alt_value) > pivot ma = delta_seconds > pivot persist = subst(True) << literal('1') > pivot Alt_Used = uri_host + maybe_str(':' + port) > pivot fill_names(globals(), RFC(7838))
return _collect_elements << (maybe(group(element) * skip(OWS)) % many( skip(literal(',') * OWS) * maybe(group(element) * skip(OWS)))) > named( u'#rule', RFC(7230, section=u'7')) def comma_list1(element): return _collect_elements << (many(subst(None) << ',' * OWS) + ( (lambda x: [x]) << group(element)) + many( skip(OWS * ',') * maybe(skip(OWS) * element))) > named( u'1#rule', RFC(7230, section=u'7')) method = Method << token > pivot absolute_path = string1('/' + segment) > pivot partial_URI = relative_part + maybe_str('?' + query) > pivot origin_form = absolute_path + maybe_str('?' + query) > pivot absolute_form = absolute_URI > pivot authority_form = authority > pivot asterisk_form = literal('*') > auto request_target = (origin_form | absolute_form | authority_form | asterisk_form) > pivot reason_phrase = string(HTAB | SP | VCHAR | obs_text) > pivot field_name = FieldName << token > pivot def transfer_parameter(no_q=False): return ((token__excluding(['q']) if no_q else token) * skip(BWS * '=' * BWS) * (token | quoted_string)) > named(
segment_nz = string1(pchar) > auto segment_nz_nc = string1(unreserved | sub_delims | '@' | pct_encoded) > auto scheme = ALPHA + string(ALPHA | DIGIT | '+' | '-' | '.') > pivot userinfo = string(unreserved | sub_delims | ':' | pct_encoded) > pivot dec_octet = (DIGIT | octet_range(0x31, 0x39) + DIGIT | '1' + DIGIT + DIGIT | '2' + octet_range(0x30, 0x34) + DIGIT | '25' + octet_range(0x30, 0x35)) > auto IPv4address = (dec_octet + '.' + dec_octet + '.' + dec_octet + '.' + dec_octet) > pivot h16 = string_times(1, 4, HEXDIG) > auto ls32 = (h16 + ':' + h16) | IPv4address > auto IPv6address = ( string_times(6, 6, h16 + ':') + ls32 | '::' + string_times(5, 5, h16 + ':') + ls32 | maybe_str(h16) + '::' + string_times(4, 4, h16 + ':') + ls32 | maybe_str(string_times(0, 1, h16 + ':') + h16) + '::' + string_times(3, 3, h16 + ':') + ls32 | maybe_str(string_times(0, 2, h16 + ':') + h16) + '::' + string_times(2, 2, h16 + ':') + ls32 | maybe_str(string_times(0, 3, h16 + ':') + h16) + '::' + h16 + ':' + ls32 | maybe_str(string_times(0, 4, h16 + ':') + h16) + '::' + ls32 | maybe_str(string_times(0, 5, h16 + ':') + h16) + '::' + h16 | maybe_str(string_times(0, 6, h16 + ':') + h16) + '::') > pivot IPvFuture = ('v' + string1(HEXDIG) + '.' + string1(unreserved | sub_delims | ':')) > pivot # As updated by RFC 6874 ZoneID = string1(unreserved | pct_encoded) > pivot IPv6addrz = IPv6address + '%25' + ZoneID > pivot
Cache_Control = comma_list1(cache_directive) > pivot # RFC 7234 does not, strictly speaking, define these productions: no_cache = comma_list(field_name) > pivot private = comma_list(field_name) > pivot Expires = HTTP_date > pivot def extension_pragma(exclude_no_cache=False): return Parametrized << ( (token__excluding(['no-cache']) if exclude_no_cache else token) * maybe(skip('=') * (token | quoted_string))) > named( u'extension-pragma', RFC(7234), is_pivot=True) pragma_directive = (CaseInsensitive << literal('no-cache') | extension_pragma(exclude_no_cache=True)) > pivot Pragma = comma_list1(pragma_directive) > pivot warn_code = WarnCode << string_times(3, 3, DIGIT) > pivot warn_agent = uri_host + maybe_str(':' + port) | pseudonym > pivot warn_text = quoted_string > pivot warn_date = skip(DQUOTE) * HTTP_date * skip(DQUOTE) > pivot warning_value = WarningValue << (warn_code * skip(SP) * warn_agent * skip(SP) * warn_text * maybe(skip(SP) * warn_date)) > pivot Warning_ = comma_list1(warning_value) > pivot fill_names(globals(), RFC(7234))
irregular = (literal('en-GB-oed') | 'i-ami' | 'i-bnn' | 'i-default' | 'i-enochian' | 'i-hak' | 'i-klingon' | 'i-lux' | 'i-mingo' | 'i-navajo' | 'i-pwn' | 'i-tao' | 'i-tay' | 'i-tsu' | 'sgn-BE-FR' | 'sgn-BE-NL' | 'sgn-CH-DE') > auto regular = (literal('art-lojban') | 'cel-gaulish' | 'no-bok' | 'no-nyn' | 'zh-guoyu' | 'zh-hakka' | 'zh-min' | 'zh-min-nan' | 'zh-xiang') > auto grandfathered = irregular | regular > pivot privateuse = 'x' + string1('-' + string_times(1, 8, alphanum)) > pivot extlang = (string_times(3, 3, ALPHA) + string_times(0, 2, '-' + string_times(3, 3, ALPHA))) > pivot language = (string_times(2, 3, ALPHA) + maybe_str('-' + extlang) | string_times(4, 4, ALPHA) | string_times(5, 8, ALPHA)) > pivot script = string_times(4, 4, ALPHA) > pivot region = string_times(2, 2, ALPHA) | string_times(3, 3, DIGIT) > pivot variant = (string_times(5, 8, alphanum) | (DIGIT + string_times(3, 3, alphanum))) > pivot extension = (singleton + string1('-' + string_times(2, 8, alphanum))) > pivot langtag = (language + maybe_str('-' + script) + maybe_str('-' + region) + string('-' + variant) + string('-' + extension) + maybe_str('-' + privateuse)) > pivot Language_Tag = (LanguageTag << langtag | LanguageTag << privateuse | LanguageTag << grandfathered) > pivot fill_names(globals(), RFC(5646))
scheme = ALPHA + string(ALPHA | DIGIT | '+' | '-' | '.') > pivot userinfo = string(unreserved | sub_delims | ':' | pct_encoded) > pivot dec_octet = (DIGIT | octet_range(0x31, 0x39) + DIGIT | '1' + DIGIT + DIGIT | '2' + octet_range(0x30, 0x34) + DIGIT | '25' + octet_range(0x30, 0x35)) > auto IPv4address = (dec_octet + '.' + dec_octet + '.' + dec_octet + '.' + dec_octet) > pivot h16 = string_times(1, 4, HEXDIG) > auto ls32 = (h16 + ':' + h16) | IPv4address > auto IPv6address = ( string_times(6, 6, h16 + ':') + ls32 | '::' + string_times(5, 5, h16 + ':') + ls32 | maybe_str(h16) + '::' + string_times(4, 4, h16 + ':') + ls32 | maybe_str(string_times(0, 1, h16 + ':') + h16) + '::' + string_times(3, 3, h16 + ':') + ls32 | maybe_str(string_times(0, 2, h16 + ':') + h16) + '::' + string_times(2, 2, h16 + ':') + ls32 | maybe_str(string_times(0, 3, h16 + ':') + h16) + '::' + h16 + ':' + ls32 | maybe_str(string_times(0, 4, h16 + ':') + h16) + '::' + ls32 | maybe_str(string_times(0, 5, h16 + ':') + h16) + '::' + h16 | maybe_str(string_times(0, 6, h16 + ':') + h16) + '::' ) > pivot IPvFuture = ('v' + string1(HEXDIG) + '.' + string1(unreserved | sub_delims | ':')) > pivot # As updated by RFC 6874 ZoneID = string1(unreserved | pct_encoded) > pivot