Пример #1
0
            | subst(3) << octet(0x54) * octet(0x68) * octet(0x75)
            | subst(4) << octet(0x46) * octet(0x72) * octet(0x69)
            | subst(5) << octet(0x53) * octet(0x61) * octet(0x74)
            | subst(6) << octet(0x53) * octet(0x75) * octet(0x6E)) > pivot


@can_complain
def _to_date(complain, d, m, y):
    try:
        return date(y, m, d)
    except ValueError:
        complain(1222, date=u'%d-%02d-%02d' % (y, m, d))
        return Unavailable


day = int << string_times(2, 2, DIGIT) > pivot
month = (subst(1) << octet(0x4A) * octet(0x61) * octet(0x6E)
         | subst(2) << octet(0x46) * octet(0x65) * octet(0x62)
         | subst(3) << octet(0x4D) * octet(0x61) * octet(0x72)
         | subst(4) << octet(0x41) * octet(0x70) * octet(0x72)
         | subst(5) << octet(0x4D) * octet(0x61) * octet(0x79)
         | subst(6) << octet(0x4A) * octet(0x75) * octet(0x6E)
         | subst(7) << octet(0x4A) * octet(0x75) * octet(0x6C)
         | subst(8) << octet(0x41) * octet(0x75) * octet(0x67)
         | subst(9) << octet(0x53) * octet(0x65) * octet(0x70)
         | subst(10) << octet(0x4F) * octet(0x63) * octet(0x74)
         | subst(11) << octet(0x4E) * octet(0x6F) * octet(0x76)
         | subst(12) << octet(0x44) * octet(0x65) * octet(0x63)) > pivot
year = int << string_times(4, 4, DIGIT) > pivot

date1 = _to_date << day * skip(SP) * month * skip(SP) * year > pivot
Пример #2
0
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

field_name = FieldName << token                                         > pivot
field_vchar = VCHAR | obs_text                                          > auto

obs_fold = CRLF + string1(SP | HTAB)                                    > auto

# The original RFC 7230 ``field-content`` is wrong (see RFC Errata ID: 4189).
# This version seems to capture the intended behavior.
field_content = (field_vchar +
                 maybe_str(string(SP | HTAB | field_vchar) +
                           field_vchar))                                > auto

def transfer_parameter(no_q=False):
    return (
Пример #3
0
    ) > named(u'transfer-extension', RFC(7230), is_pivot=True)


def transfer_coding(no_trailers=False, no_q=False):
    exclude = _built_in_codings
    if no_trailers:
        exclude = exclude + ['trailers']
    r = transfer_extension(exclude, no_q)
    for name in _built_in_codings:
        r = r | _empty_params << (TransferCoding << literal(name))
    return r > named(u'transfer-coding', RFC(7230), is_pivot=True)


Transfer_Encoding = comma_list1(transfer_coding()) > pivot

rank = (float << '0' + maybe_str('.' + string_times(0, 3, DIGIT))
        | float << '1' + maybe_str('.' + string_times(0, 3, '0'))) > pivot
t_ranking = skip(OWS * ';' * OWS * 'q=') * rank > pivot
t_codings = (
    CaseInsensitive << literal('trailers') | Parametrized <<
    (transfer_coding(no_trailers=True, no_q=True) * maybe(t_ranking))) > pivot
TE = comma_list(t_codings) > pivot

Trailer = comma_list1(field_name) > pivot

Host = uri_host + maybe_str(':' + port) > pivot

connection_option = ConnectionOption << token > pivot
Connection = comma_list1(connection_option) > pivot

protocol_name = token > pivot
Пример #4
0
             '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) +
Пример #5
0
              | ';' | '=') > auto
unreserved = ALPHA | DIGIT | '-' | '.' | '_' | '~' > auto
pchar = unreserved | sub_delims | ':' | '@' | pct_encoded > auto

segment = string(pchar) > auto
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) + '.' +
Пример #6
0
                             string_times)
from httpolice.structure import ForwardedParam
from httpolice.syntax.common import ALPHA, DIGIT
from httpolice.syntax.rfc3986 import IPv4address, IPv6address
from httpolice.syntax.rfc7230 import comma_list1, quoted_string, token


def _remove_empty(xs):
    return [x for x in xs if x is not None]


obfnode = '_' + string1(ALPHA | DIGIT | '.' | '_' | '-') > pivot
nodename = (IPv4address | skip('[') * IPv6address * skip(']') | 'unknown'
            | obfnode) > pivot

port = int << string_times(1, 5, DIGIT) > pivot
obfport = '_' + string1(ALPHA | DIGIT | '.' | '_' | '-') > pivot
node_port = port | obfport > pivot

node = nodename * maybe(skip(':') * node_port) > pivot

value = token | quoted_string > pivot
forwarded_pair = (ForwardedParam << token) * skip('=') * value > pivot

forwarded_element = _remove_empty << (
    maybe(forwarded_pair) % many(skip(';') * maybe(forwarded_pair))) > pivot

Forwarded = comma_list1(forwarded_element) > pivot

fill_names(globals(), RFC(7239))
Пример #7
0
        (TransferCoding << token__excluding(exclude or [])) *
        (MultiDict << many(skip(OWS * ';' * OWS) * transfer_parameter(no_q)))
    ) > named(u'transfer-extension', RFC(7230), is_pivot=True)

def transfer_coding(no_trailers=False, no_q=False):
    exclude = _built_in_codings
    if no_trailers:
        exclude = exclude + ['trailers']
    r = transfer_extension(exclude, no_q)
    for name in _built_in_codings:
        r = r | _empty_params << (TransferCoding << literal(name))
    return r > named(u'transfer-coding', RFC(7230), is_pivot=True)

Transfer_Encoding = comma_list1(transfer_coding())                      > pivot

rank = (float << '0' + maybe_str('.' + string_times(0, 3, DIGIT)) |
        float << '1' + maybe_str('.' + string_times(0, 3, '0')))        > pivot
t_ranking = skip(OWS * ';' * OWS * 'q=') * rank                         > pivot
t_codings = (CaseInsensitive << literal('trailers') |
             Parametrized << (transfer_coding(no_trailers=True, no_q=True) *
                              maybe(t_ranking)))                        > pivot
TE = comma_list(t_codings)                                              > pivot

Trailer = comma_list1(field_name)                                       > pivot

Host = uri_host + maybe_str(':' + port)                                 > pivot

connection_option = ConnectionOption << token                           > pivot
Connection = comma_list1(connection_option)                             > pivot

protocol_name = token                                                   > pivot
Пример #8
0
from httpolice.structure import ForwardedParam
from httpolice.syntax.common import ALPHA, DIGIT
from httpolice.syntax.rfc3986 import IPv4address, IPv6address
from httpolice.syntax.rfc7230 import comma_list1, quoted_string, token


def _remove_empty(xs):
    return [x for x in xs if x is not None]


obfnode = '_' + string1(ALPHA | DIGIT | '.' | '_' | '-')                > pivot
nodename = (IPv4address |
            skip('[') * IPv6address * skip(']') |
            'unknown' | obfnode)                                        > pivot

port = int << string_times(1, 5, DIGIT)                                 > pivot
obfport = '_' + string1(ALPHA | DIGIT | '.' | '_' | '-')                > pivot
node_port = port | obfport                                              > pivot

node = nodename * maybe(skip(':') * node_port)                          > pivot

value = token | quoted_string                                           > pivot
forwarded_pair = (ForwardedParam << token) * skip('=') * value          > pivot

forwarded_element = _remove_empty << (
    maybe(forwarded_pair) % many(skip(';') * maybe(forwarded_pair)))    > pivot

Forwarded = comma_list1(forwarded_element)                              > pivot


fill_names(globals(), RFC(7239))
Пример #9
0
singleton = (DIGIT | octet_range(0x41, 0x57) | octet_range(0x59, 0x5A)
             | octet_range(0x61, 0x77) | octet_range(0x79, 0x7A)) > auto
alphanum = ALPHA | DIGIT > auto

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
Пример #10
0
# -*- coding: utf-8; -*-

from httpolice.citation import RFC
from httpolice.parse import auto, fill_names, string_times
from httpolice.syntax.common import ALPHA, DIGIT


restricted_name_first = ALPHA | DIGIT                                   > auto
restricted_name_chars = (ALPHA | DIGIT | '!' | '#' |
                         '$' | '&' | '-' | '^' | '_' |
                         '.' | '+')                                     > auto
restricted_name = (restricted_name_first +
                   string_times(0, 126, restricted_name_chars))         > auto

type_name = restricted_name                                             > auto
subtype_name = restricted_name                                          > auto


fill_names(globals(), RFC(6838))
Пример #11
0
# -*- coding: utf-8; -*-

from httpolice.citation import RFC
from httpolice.parse import auto, fill_names, pivot, string, string_times
from httpolice.structure import CaseInsensitive
from httpolice.syntax.common import ALPHA, DIGIT

alphanum = ALPHA | DIGIT > auto
language_range = CaseInsensitive << (string_times(
    1, 8, ALPHA) + string('-' + string_times(1, 8, alphanum)) | '*') > pivot

fill_names(globals(), RFC(4647))
Пример #12
0
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

field_name = FieldName << token > pivot
field_vchar = VCHAR | obs_text > auto

obs_fold = CRLF + string1(SP | HTAB) > auto

# The original RFC 7230 ``field-content`` is wrong (see RFC Errata ID: 4189).
# This version seems to capture the intended behavior.
field_content = (
    field_vchar +
    maybe_str(string(SP | HTAB | field_vchar) + field_vchar)) > auto


def transfer_parameter(no_q=False):
Пример #13
0
pchar = unreserved | sub_delims | ':' | '@' | pct_encoded               > auto

segment = string(pchar)                                                 > auto
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
Пример #14
0
            subst(1) << octet(0x54) * octet(0x75) * octet(0x65) |
            subst(2) << octet(0x57) * octet(0x65) * octet(0x64) |
            subst(3) << octet(0x54) * octet(0x68) * octet(0x75) |
            subst(4) << octet(0x46) * octet(0x72) * octet(0x69) |
            subst(5) << octet(0x53) * octet(0x61) * octet(0x74) |
            subst(6) << octet(0x53) * octet(0x75) * octet(0x6E))        > pivot

@can_complain
def _to_date(complain, d, m, y):
    try:
        return date(y, m, d)
    except ValueError:
        complain(1222, date=u'%d-%02d-%02d' % (y, m, d))
        return Unavailable

day = int << string_times(2, 2, DIGIT)                                  > pivot
month = (subst(1) << octet(0x4A) * octet(0x61) * octet(0x6E)  |
         subst(2) << octet(0x46) * octet(0x65) * octet(0x62)  |
         subst(3) << octet(0x4D) * octet(0x61) * octet(0x72)  |
         subst(4) << octet(0x41) * octet(0x70) * octet(0x72)  |
         subst(5) << octet(0x4D) * octet(0x61) * octet(0x79)  |
         subst(6) << octet(0x4A) * octet(0x75) * octet(0x6E)  |
         subst(7) << octet(0x4A) * octet(0x75) * octet(0x6C)  |
         subst(8) << octet(0x41) * octet(0x75) * octet(0x67)  |
         subst(9) << octet(0x53) * octet(0x65) * octet(0x70)  |
         subst(10) << octet(0x4F) * octet(0x63) * octet(0x74) |
         subst(11) << octet(0x4E) * octet(0x6F) * octet(0x76) |
         subst(12) << octet(0x44) * octet(0x65) * octet(0x63))          > pivot
year = int << string_times(4, 4, DIGIT)                                 > pivot

date1 = _to_date << day * skip(SP) * month * skip(SP) * year            > pivot
Пример #15
0
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))
Пример #16
0
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))
Пример #17
0
# -*- coding: utf-8; -*-

from httpolice.citation import RFC
from httpolice.parse import auto, fill_names, pivot, string, string_times
from httpolice.structure import CaseInsensitive
from httpolice.syntax.common import ALPHA, DIGIT


alphanum = ALPHA | DIGIT                                                > auto
language_range = CaseInsensitive << (
    string_times(1, 8, ALPHA) + string('-' + string_times(1, 8, alphanum)) |
    '*')                                                                > pivot


fill_names(globals(), RFC(4647))