def test_comma_list(): p = rfc7230.comma_list(rfc7230.token) assert parse(p, b'') == [] assert parse(p, b', ,, , ,') == [] assert parse(p, b'foo') == [u'foo'] assert parse(p, b'foo,bar') == [u'foo', u'bar'] assert parse(p, b'foo, bar,') == [u'foo', u'bar'] assert parse(p, b', ,,,foo, ,bar, baz, ,, ,') == [u'foo', u'bar', u'baz'] no_parse(p, b'foo,"bar"') no_parse(p, b'foo;bar')
{ '_': CacheDirective(u'must-revalidate'), '_citations': [RFC(7234, section=(5, 2, 2, 1))], 'argument': NO, 'for_request': False, 'for_response': True }, { '_': CacheDirective(u'no-cache'), '_citations': [RFC(7234, section=(5, 2))], '_no_sync': ['_citations'], 'argument': OPTIONAL, 'argument_form': QUOTED_STRING_PREFERRED, 'for_request': True, 'for_response': True, 'parser': rfc7230.comma_list(rfc7230.field_name) }, { '_': CacheDirective(u'no-store'), '_citations': [RFC(7234, section=(5, 2))], '_no_sync': ['_citations'], 'argument': NO, 'for_request': True, 'for_response': True }, { '_': CacheDirective(u'no-transform'), '_citations': [RFC(7234, section=(5, 2))], '_no_sync': ['_citations'], 'argument': NO, 'for_request': True,
) ) > 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 Accept_Charset = comma_list1( Parametrized << ((charset | Charset << literal('*')) * maybe(weight))) > pivot codings = (content_coding | ContentCoding << literal('identity') | literal('*')) > pivot Accept_Encoding = comma_list(Parametrized << codings * maybe(weight)) > pivot Accept_Language = comma_list1( Parametrized << language_range * maybe(weight)) > pivot
# -*- coding: utf-8; -*- from httpolice.citation import Citation from httpolice.parse import fill_names, pivot from httpolice.syntax.rfc7230 import comma_list from httpolice.syntax.rfc7231 import media_range Accept_Post = comma_list(media_range()) > pivot fill_names( globals(), Citation(u'W3C Linked Data Platform 1.0', u'https://www.w3.org/TR/ldp/'))
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/'))
# -*- coding: utf-8; -*- from httpolice.parse import (fill_names, literal, maybe, pivot, skip, string1, subst) from httpolice.syntax.common import DIGIT from httpolice.syntax.rfc7230 import RWS, comma_list notice_id = int << string1(DIGIT) > pivot resp = subst(True) << literal('resp') > pivot HTTPolice_Silence = comma_list(notice_id * maybe(skip(RWS) * resp)) > pivot fill_names(globals(), citation=None)
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 Accept_Charset = comma_list1(Parametrized << ( (charset | Charset << literal('*')) * maybe(weight))) > pivot codings = (content_coding | ContentCoding << literal('identity') | literal('*')) > pivot Accept_Encoding = comma_list(Parametrized << codings * maybe(weight)) > pivot Accept_Language = comma_list1(Parametrized << language_range * maybe(weight)) > pivot delay_seconds = int << string1(DIGIT) > pivot Retry_After = HTTP_date | delay_seconds > pivot
'for_request': True, 'for_response': False, 'parser': rfc7234.delta_seconds}, {'_': CacheDirective(u'must-revalidate'), '_citations': [RFC(7234, section=(5, 2, 2, 1))], 'argument': NO, 'for_request': False, 'for_response': True}, {'_': CacheDirective(u'no-cache'), '_citations': [RFC(7234, section=(5, 2))], '_no_sync': ['_citations'], 'argument': OPTIONAL, 'argument_form': QUOTED_STRING_PREFERRED, 'for_request': True, 'for_response': True, 'parser': rfc7230.comma_list(rfc7230.field_name)}, {'_': CacheDirective(u'no-store'), '_citations': [RFC(7234, section=(5, 2))], '_no_sync': ['_citations'], 'argument': NO, 'for_request': True, 'for_response': True}, {'_': CacheDirective(u'no-transform'), '_citations': [RFC(7234, section=(5, 2))], '_no_sync': ['_citations'], 'argument': NO, 'for_request': True, 'for_response': True}, {'_': CacheDirective(u'only-if-cached'), '_citations': [RFC(7234, section=(5, 2, 1, 7))], 'argument': NO,
link_param = link_param > pivot @can_complain def _process_params(complain, params): r = [] seen = set() for (name, value) in params: if name in seen: # The spec says "occurrences after the first must be ignored" # for ``rel``, ``title``, and ``title*``, # but not for ``media`` and ``type``. if name in [u'rel', u'title', u'title*']: complain(1225, name=name) continue elif name in [u'media', u'type']: complain(1225, name=name) seen.add(name) r.append((name, value)) if name == u'rev': complain(1226) return MultiDict(r) link_value = Parametrized << ( skip('<') * URI_Reference * skip('>') * (_process_params << many(skip(OWS * ';' * OWS) * link_param))) > pivot Link = comma_list(link_value) > pivot fill_names(globals(), RFC(5988))
from httpolice.syntax.common import DIGIT, DQUOTE, SP from httpolice.syntax.rfc7230 import (comma_list, comma_list1, field_name, port, pseudonym, quoted_string, token, token__excluding, uri_host) from httpolice.syntax.rfc7231 import HTTP_date delta_seconds = int << string1(DIGIT) > 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 # 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
from httpolice.syntax.rfc7230 import (comma_list, comma_list1, field_name, port, pseudonym, quoted_string, token, token__excluding, uri_host) from httpolice.syntax.rfc7231 import HTTP_date delta_seconds = int << string1(DIGIT) > 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 # 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
# -*- coding: utf-8; -*- from httpolice.parse import ( fill_names, literal, maybe, pivot, skip, string1, subst, ) from httpolice.syntax.common import DIGIT from httpolice.syntax.rfc7230 import RWS, comma_list notice_id = int << string1(DIGIT) > pivot resp = subst(True) << literal('resp') > pivot HTTPolice_Silence = comma_list(notice_id * maybe(skip(RWS) * resp)) > pivot fill_names(globals(), citation=None)
# -*- coding: utf-8; -*- from httpolice.citation import Citation from httpolice.parse import fill_names, pivot from httpolice.syntax.rfc7230 import comma_list from httpolice.syntax.rfc7231 import media_range Accept_Post = comma_list(media_range()) > pivot fill_names(globals(), Citation(u'W3C Linked Data Platform 1.0', u'https://www.w3.org/TR/2015/REC-ldp-20150226/'))
@can_complain def _check_realm(complain, k, v): (symbol, v) = v if k == u'realm' and symbol is not quoted_string: complain(1196) return (k, v) auth_param = _check_realm << ((CaseInsensitive << token) * skip(BWS * '=' * BWS) * (mark(token) | mark(quoted_string))) > pivot challenge = Parametrized << ( auth_scheme * maybe(skip(string1(SP)) * (token68 | MultiDict << comma_list(auth_param)), default=MultiDict())) > auto WWW_Authenticate = comma_list1(challenge) > pivot Proxy_Authenticate = comma_list1(challenge) > pivot credentials = Parametrized << ( auth_scheme * maybe(skip(string1(SP)) * (token68 | MultiDict << comma_list(auth_param)), default=MultiDict())) > auto Authorization = credentials > pivot Proxy_Authorization = credentials > pivot fill_names(globals(), RFC(7235))