コード例 #1
0
ファイル: rfc5988.py プロジェクト: YanLinAung/httpolice
# "its value MUST be quoted if it contains a semicolon (';') or comma (',')".

_MediaDesc = string((VCHAR | HTAB | SP) - literal('"'))
_MediaDesc_no_delim = string((VCHAR | HTAB | SP) -
                             literal('"') - literal(';') - literal(','))


# This has been slightly adapted to the rules of RFC 7230.
# The ``OWS`` are derived from the "implied ``*LWS``" requirement.

ptokenchar = (literal('!') | '#' | '$' | '%' | '&' | "'" | '(' |
              ')' | '*' | '+' | '-' | '.' | '/' | DIGIT |
              ':' | '<' | '=' | '>' | '?' | '@' | ALPHA |
              '[' | ']' | '^' | '_' | '`' | '{' | '|' |
              '}' | '~')                                                > auto
ptoken = string1(ptokenchar)                                            > auto

media_type = MediaType << type_name + '/' + subtype_name                > pivot
quoted_mt = skip('"') * media_type * skip('"')                          > pivot

reg_rel_type = RelationType << (
    LOALPHA + string(LOALPHA | DIGIT | '.' | '-'))                      > auto
ext_rel_type = URI                                                      > auto
relation_type = reg_rel_type | ext_rel_type                             > pivot
relation_types = (
    (lambda x: [x]) << relation_type |
    skip('"' * OWS) *
    (relation_type % many(skip(string1(SP)) * relation_type)) *
    skip(OWS * '"'))                                                    > pivot

def ext_name_star__excluding(exclude):
コード例 #2
0
ファイル: rfc5987.py プロジェクト: YanLinAung/httpolice
attr_char = (ALPHA | DIGIT |
             '!' | '#' | '$' | '&' | '+' | '-' | '.' |
             '^' | '_' | '`' | '|' | '~')                               > auto

def parmname__excluding(exclude):
    return (string_excluding(attr_char, [''] + exclude)
            > named(u'parmname', RFC(5987), is_pivot=True))

parmname = parmname__excluding([])

# We don't need to special-case "UTF-8" and "ISO-8859-1", simplify.
mime_charsetc = (ALPHA | DIGIT |
                 '!' | '#' | '$' | '%' | '&' | '+' | '-' | '^' | '_' | '`' |
                 '{' | '}' | '~')                                       > auto
mime_charset = string1(mime_charsetc)                                   > auto
charset = CaseInsensitive << mime_charset                               > pivot

pct_encoded = '%' + HEXDIG + HEXDIG                                     > auto
value_chars = pct_decode << (
    force_bytes << string(pct_encoded | attr_char))                     > auto

@can_complain
def _check_ext_value(complain, val):
    if val.charset in [u'UTF-8', u'ISO-8859-1']:
        try:
            val.value_bytes.decode(val.charset)
        except UnicodeError as e:
            complain(1254, charset=val.charset, error=e)
    else:
        complain(1253, charset=val.charset)
コード例 #3
0
ファイル: rfc7235.py プロジェクト: weijl6819/httpolice
# -*- coding: utf-8; -*-

from httpolice.citation import RFC
from httpolice.parse import (auto, can_complain, fill_names, mark, maybe,
                             pivot, skip, string, string1)
from httpolice.structure import (AuthScheme, CaseInsensitive, MultiDict,
                                 Parametrized)
from httpolice.syntax.common import ALPHA, DIGIT, SP
from httpolice.syntax.rfc7230 import (BWS, comma_list, comma_list1,
                                      quoted_string, token)


auth_scheme = AuthScheme << token                                       > pivot
token68 = (string1(ALPHA | DIGIT | '-' | '.' | '_' | '~' | '+' | '/') +
           string('='))                                                 > pivot

@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)),
コード例 #4
0
ファイル: rfc7233.py プロジェクト: vfaronov/httpolice
bytes_unit = RangeUnit << literal('bytes') > auto
other_range_unit = RangeUnit << token__excluding(['bytes']) > auto
range_unit = bytes_unit | other_range_unit > pivot
acceptable_ranges = (CaseInsensitive << literal('none')
                     | comma_list1(range_unit)) > pivot
Accept_Ranges = acceptable_ranges > pivot


@can_complain
def _well_formed1(complain, first, last):
    if (last is not None) and (first > last):
        complain(1133)
    return (first, last)


first_byte_pos = int << string1(DIGIT) > auto
last_byte_pos = int << string1(DIGIT) > auto
byte_range_spec = _well_formed1 << (first_byte_pos * skip('-') *
                                    maybe(last_byte_pos)) > pivot

suffix_length = int << string1(DIGIT) > auto
suffix_byte_range_spec = \
    (lambda x: (None, x)) << skip('-') * suffix_length                  > pivot

byte_range_set = comma_list1(byte_range_spec | suffix_byte_range_spec) > auto
byte_ranges_specifier = RangeSpecifier << (bytes_unit * skip('=') *
                                           byte_range_set) > pivot

other_range_set = string1(VCHAR) > auto
other_ranges_specifier = RangeSpecifier << (other_range_unit * skip('=') *
                                            other_range_set) > pivot
コード例 #5
0
ファイル: rfc7230.py プロジェクト: YanLinAung/httpolice
                                 HTTPVersion, Method, MultiDict, Parametrized,
                                 StatusCode, TransferCoding, UpgradeToken,
                                 Versioned)
from httpolice.syntax.common import (ALPHA, CRLF, DIGIT, DQUOTE, HEXDIG, HTAB,
                                     SP, VCHAR)
from httpolice.syntax.rfc3986 import (absolute_URI, authority,
                                      host as uri_host, port, query,
                                      relative_part, segment)


obs_text = octet_range(0x80, 0xFF)                                      > auto

tchar = (literal('!') | '#' | '$' | '%' | '&' | "'" | '*' | '+' | '-' | '.' |
         '^' | '_' | '`' | '|' | '~' | DIGIT | ALPHA)                   > auto

token = string1(tchar)                                                  > auto

def token__excluding(excluding):
    return string_excluding(tchar, [''] + list(excluding))

def quoted_pair(sensible_for):
    # In RFC 7230, ``<quoted-pair>`` is a single rule,
    # but we parametrize it to report no. 1017 depending on the context.
    @can_complain
    def check_sensible(complain, c):
        if c not in sensible_for:
            complain(1017, char=c)
        return c
    return (check_sensible << skip('\\') * (HTAB | SP | VCHAR | obs_text)
            > named(u'quoted-pair', RFC(7230)))
コード例 #6
0
# -*- coding: utf-8; -*-

from httpolice.citation import RFC
from httpolice.parse import auto, fill_names, many, maybe, pivot, skip, string1
from httpolice.structure import HSTSDirective, Parametrized
from httpolice.syntax.common import DIGIT
from httpolice.syntax.rfc7230 import OWS, quoted_string, token


# This has been slightly adapted to the rules of RFC 7230.
# The ``OWS`` are derived from the "implied ``*LWS``" requirement.

directive_name = HSTSDirective << token                                 > auto
directive_value = token | quoted_string                                 > auto
directive = Parametrized << (
    directive_name * maybe(skip(OWS * '=' * OWS) * directive_value))    > pivot

def _collect_elements(xs):
    return [elem for elem in xs if elem is not None]

Strict_Transport_Security = _collect_elements << (
    maybe(directive) % many(skip(OWS * ';' * OWS) * maybe(directive)))  > pivot

max_age_value = int << string1(DIGIT)                                   > pivot

fill_names(globals(), RFC(6797))
コード例 #7
0
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

Allow = comma_list(method) > pivot
Content_Encoding = comma_list1(content_coding) > pivot
Content_Language = comma_list1(language_tag) > pivot
Content_Location = absolute_URI | partial_URI > pivot
Content_Type = media_type > pivot
Date = HTTP_date > pivot
Location = URI_reference > pivot
Max_Forwards = int << string1(DIGIT) > pivot
Referer = absolute_URI | partial_URI > pivot
Vary = '*' | comma_list1(field_name) > pivot
Expect = CaseInsensitive << literal('100-continue') > pivot

fill_names(globals(), RFC(7231))
コード例 #8
0
from httpolice.citation import RFC
from httpolice.parse import (auto, fill_names, many, octet, octet_range, pivot,
                             skip, string1)
from httpolice.syntax.common import SP
from httpolice.syntax.rfc3986 import URI_reference

NQSCHAR = (octet_range(0x20, 0x21) | octet_range(0x23, 0x5B)
           | octet_range(0x5D, 0x7E)) > auto
NQCHAR = (octet(0x21) | octet_range(0x23, 0x5B)
          | octet_range(0x5D, 0x7E)) > auto

scope_token = string1(NQCHAR) > pivot
scope = scope_token % many(skip(SP) * scope_token) > pivot

error = string1(NQSCHAR) > pivot
error_description = string1(NQSCHAR) > pivot
error_uri = URI_reference > pivot

fill_names(globals(), RFC(6749))
コード例 #9
0
# "its value MUST be quoted if it contains a semicolon (';') or comma (',')".

_MediaDesc = string((VCHAR | HTAB | SP) - literal('"'))
_MediaDesc_no_delim = string((VCHAR | HTAB | SP) -
                             literal('"') - literal(';') - literal(','))


# This has been slightly adapted to the rules of RFC 7230.
# The ``OWS`` are derived from the "implied ``*LWS``" requirement.

ptokenchar = (literal('!') | '#' | '$' | '%' | '&' | "'" | '(' |
              ')' | '*' | '+' | '-' | '.' | '/' | DIGIT |
              ':' | '<' | '=' | '>' | '?' | '@' | ALPHA |
              '[' | ']' | '^' | '_' | '`' | '{' | '|' |
              '}' | '~')                                                > auto
ptoken = string1(ptokenchar)                                            > auto

media_type = MediaType << type_name + '/' + subtype_name                > pivot
quoted_mt = skip('"') * media_type * skip('"')                          > pivot

reg_rel_type = RelationType << (
    LOALPHA + string(LOALPHA | DIGIT | '.' | '-'))                      > auto
ext_rel_type = URI                                                      > auto
relation_type = reg_rel_type | ext_rel_type                             > pivot
relation_types = (
    (lambda x: [x]) << relation_type |
    skip('"' * OWS) *
    (relation_type % many(skip(string1(SP)) * relation_type)) *
    skip(OWS * '"'))                                                    > pivot

def ext_name_star__excluding(exclude):
コード例 #10
0
ファイル: internal.py プロジェクト: dfirst/httpolice
# -*- 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)
コード例 #11
0
from httpolice.structure import (CaseInsensitive, ConnectionOption, FieldName,
                                 HTTPVersion, Method, MultiDict, Parametrized,
                                 StatusCode, TransferCoding, UpgradeToken,
                                 Versioned)
from httpolice.syntax.common import (ALPHA, CRLF, DIGIT, DQUOTE, HEXDIG, HTAB,
                                     SP, VCHAR)
from httpolice.syntax.rfc3986 import (absolute_URI, authority, host as
                                      uri_host, port, query, relative_part,
                                      segment)

obs_text = octet_range(0x80, 0xFF) > auto

tchar = (literal('!') | '#' | '$' | '%' | '&' | "'" | '*' | '+' | '-' | '.'
         | '^' | '_' | '`' | '|' | '~' | DIGIT | ALPHA) > auto

token = string1(tchar) > auto


def token__excluding(excluding):
    return string_excluding(tchar, [''] + list(excluding))


def quoted_pair(sensible_for):
    # In RFC 7230, ``<quoted-pair>`` is a single rule,
    # but we parametrize it to report no. 1017 depending on the context.
    @can_complain
    def check_sensible(complain, c):
        if c not in sensible_for:
            complain(1017, char=c)
        return c
コード例 #12
0
        if name == u'rev':
            complain(1226)
    if u'rel' not in seen:
        complain(1309)
    return MultiDict(r)


link_param = ((CaseInsensitive << token) * skip(BWS) * maybe(
    skip(literal('=') * BWS) * (mark(token) | mark(quoted_string)))) > pivot

link_value = Parametrized << (
    skip('<') * URI_Reference * skip('>') *
    (_process_params << many(skip(OWS * ';' * OWS) * link_param))) > pivot

Link = comma_list(link_value) > pivot

anchor = URI_Reference > auto

reg_rel_type = CaseInsensitive << (LOALPHA +
                                   string(LOALPHA | DIGIT | '.' | '-')) > auto
ext_rel_type = URI > auto
relation_type = reg_rel_type | ext_rel_type > pivot
rel = rev = relation_type % many(skip(string1(SP)) * relation_type) > auto

hreflang = Language_Tag > auto

type_ = check_media_type << (
    MediaType << type_name + '/' + subtype_name) > auto

fill_names(globals(), RFC(8288))
コード例 #13
0
ファイル: rfc3986.py プロジェクト: YanLinAung/httpolice
from httpolice.citation import RFC
from httpolice.parse import (auto, empty, fill_names, literal, maybe_str,
                             octet_range, pivot, string, string1, string_times,
                             subst)
from httpolice.syntax.common import ALPHA, DIGIT, HEXDIG


pct_encoded = '%' + HEXDIG + HEXDIG                                     > auto
sub_delims = (literal('!') | '$' | '&' | "'" | '(' | ')' | '*' | '+' |
              ',' | ';' | '=')                                          > 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 |
コード例 #14
0
ファイル: rfc7239.py プロジェクト: vfaronov/httpolice
# -*- coding: utf-8; -*-

from httpolice.citation import RFC
from httpolice.parse import (fill_names, many, maybe, pivot, skip, string1,
                             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
コード例 #15
0
# -*- coding: utf-8; -*-

from httpolice.citation import RFC
from httpolice.parse import (fill_names, many, maybe, pivot, skip, string1,
                             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
コード例 #16
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
コード例 #17
0
                             pivot, recursive, skip, string, string1,
                             string_excluding, string_times, subst)
from httpolice.structure import (CaseInsensitive, ConnectionOption, FieldName,
                                 Method, MultiDict, Parametrized,
                                 TransferCoding, UpgradeToken, Versioned)
from httpolice.syntax.common import ALPHA, DIGIT, DQUOTE, HTAB, SP, VCHAR
from httpolice.syntax.rfc3986 import (absolute_URI, authority, host as
                                      uri_host, port, query, relative_part,
                                      segment)

obs_text = octet_range(0x80, 0xFF) > auto

tchar = (literal('!') | '#' | '$' | '%' | '&' | "'" | '*' | '+' | '-' | '.'
         | '^' | '_' | '`' | '|' | '~' | DIGIT | ALPHA) > auto

token = string1(tchar) > auto


def token__excluding(excluding):
    return string_excluding(tchar, [''] + list(excluding))


def quoted_pair(sensible_for):
    # In RFC 7230, ``<quoted-pair>`` is a single rule,
    # but we parametrize it to report no. 1017 depending on the context.
    @can_complain
    def check_sensible(complain, c):
        if c not in sensible_for:
            complain(1017, char=c)
        return c
コード例 #18
0
ファイル: rfc7233.py プロジェクト: YanLinAung/httpolice
bytes_unit = RangeUnit << literal('bytes')                              > auto
other_range_unit = RangeUnit << token__excluding(['bytes'])             > auto
range_unit = bytes_unit | other_range_unit                              > pivot
acceptable_ranges = (
    subst([]) << literal('none') |
    comma_list1(range_unit))                                            > pivot
Accept_Ranges = acceptable_ranges                                       > pivot

@can_complain
def _well_formed1(complain, first, last):
    if (last is not None) and (first > last):
        complain(1133)
    return (first, last)

first_byte_pos = int << string1(DIGIT)                                  > auto
last_byte_pos = int << string1(DIGIT)                                   > auto
byte_range_spec = _well_formed1 << (first_byte_pos * skip('-') *
                                    maybe(last_byte_pos))               > pivot

suffix_length = int << string1(DIGIT)                                   > auto
suffix_byte_range_spec = \
    (lambda x: (None, x)) << skip('-') * suffix_length                  > pivot

byte_range_set = comma_list1(byte_range_spec | suffix_byte_range_spec)  > auto
byte_ranges_specifier = RangeSpecifier << (
    bytes_unit * skip('=') * byte_range_set)                            > pivot

other_range_set = string1(VCHAR)                                        > auto
other_ranges_specifier = RangeSpecifier << (
    other_range_unit * skip('=') * other_range_set)                     > pivot
コード例 #19
0
ファイル: rfc5646.py プロジェクト: YanLinAung/httpolice
             '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) +
コード例 #20
0
ファイル: rfc7230.py プロジェクト: vfaronov/httpolice
                             string_excluding, string_times, subst)
from httpolice.structure import (CaseInsensitive, ConnectionOption, FieldName,
                                 Method, MultiDict, Parametrized,
                                 TransferCoding, UpgradeToken, Versioned)
from httpolice.syntax.common import ALPHA, DIGIT, DQUOTE, HTAB, SP, VCHAR
from httpolice.syntax.rfc3986 import (absolute_URI, authority,
                                      host as uri_host, port, query,
                                      relative_part, segment)


obs_text = octet_range(0x80, 0xFF)                                      > auto

tchar = (literal('!') | '#' | '$' | '%' | '&' | "'" | '*' | '+' | '-' | '.' |
         '^' | '_' | '`' | '|' | '~' | DIGIT | ALPHA)                   > auto

token = string1(tchar)                                                  > auto

def token__excluding(excluding):
    return string_excluding(tchar, [''] + list(excluding))

def quoted_pair(sensible_for):
    # In RFC 7230, ``<quoted-pair>`` is a single rule,
    # but we parametrize it to report no. 1017 depending on the context.
    @can_complain
    def check_sensible(complain, c):
        if c not in sensible_for:
            complain(1017, char=c)
        return c
    return (check_sensible << skip('\\') * (HTAB | SP | VCHAR | obs_text)
            > named(u'quoted-pair', RFC(7230)))
コード例 #21
0
from httpolice.citation import RFC
from httpolice.parse import (auto, can_complain, fill_names, maybe, pivot,
                             skip, string, string1)
from httpolice.structure import CaseInsensitive, ExtValue
from httpolice.syntax.common import ALPHA, DIGIT, HEXDIG
from httpolice.syntax.rfc5646 import Language_Tag as language
from httpolice.util.text import force_bytes

attr_char = (ALPHA | DIGIT | '!' | '#' | '$' | '&' | '+' | '-' | '.' | '^'
             | '_' | '`' | '|' | '~') > auto
parmname = string(attr_char) > pivot

# We don't need to special-case "UTF-8", simplify.
mime_charsetc = (ALPHA | DIGIT | '!' | '#' | '$' | '%' | '&' | '+' | '-' | '^'
                 | '_' | '`' | '{' | '}' | '~') > auto
mime_charset = string1(mime_charsetc) > auto
charset = CaseInsensitive << mime_charset > pivot

pct_encoded = '%' + HEXDIG + HEXDIG > auto
value_chars = pct_decode << (
    force_bytes << string(pct_encoded | attr_char)) > auto


@can_complain
def _check_ext_value(complain, val):
    if val.charset == u'UTF-8':
        try:
            val.value_bytes.decode(val.charset)
        except UnicodeError as e:
            complain(1254, charset=val.charset, error=e)
    else:
コード例 #22
0
ファイル: rfc7234.py プロジェクト: weijl6819/httpolice
# -*- coding: utf-8; -*-

from httpolice.citation import RFC
from httpolice.parse import (fill_names, literal, mark, maybe, maybe_str,
                             named, pivot, skip, string1, string_times)
from httpolice.structure import (CacheDirective, CaseInsensitive, Parametrized,
                                 WarnCode, WarningValue)
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) *
コード例 #23
0
# -*- 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)
コード例 #24
0
ファイル: rfc3986.py プロジェクト: weijl6819/httpolice
# -*- coding: utf-8; -*-

from httpolice.citation import RFC
from httpolice.parse import (auto, empty, fill_names, literal, maybe_str,
                             octet_range, pivot, string, string1, string_times,
                             subst)
from httpolice.syntax.common import ALPHA, DIGIT, HEXDIG

pct_encoded = '%' + HEXDIG + HEXDIG > auto
sub_delims = (literal('!') | '$' | '&' | "'" | '(' | ')' | '*' | '+' | ','
              | ';' | '=') > 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
コード例 #25
0
ファイル: rfc7231.py プロジェクト: dfirst/httpolice
                     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

Allow = comma_list(method)                                              > pivot
Content_Encoding = comma_list1(content_coding)                          > pivot
Content_Language = comma_list1(language_tag)                            > pivot
Content_Location = absolute_URI | partial_URI                           > pivot
Content_Type = media_type                                               > pivot
Date = HTTP_date                                                        > pivot
Location = URI_reference                                                > pivot
Max_Forwards = int << string1(DIGIT)                                    > pivot
Referer = absolute_URI | partial_URI                                    > pivot
Vary = '*' | comma_list1(field_name)                                    > pivot
Expect = CaseInsensitive << literal('100-continue')                     > pivot

fill_names(globals(), RFC(7231))
コード例 #26
0
ファイル: rfc6749.py プロジェクト: dfirst/httpolice
from httpolice.citation import RFC
from httpolice.parse import (
    auto,
    fill_names,
    many,
    octet,
    octet_range,
    pivot,
    skip,
    string1,
)
from httpolice.syntax.common import SP
from httpolice.syntax.rfc3986 import URI_reference


NQSCHAR = (octet_range(0x20, 0x21) | octet_range(0x23, 0x5B) |
           octet_range(0x5D, 0x7E))                                     > auto
NQCHAR = (octet(0x21) | octet_range(0x23, 0x5B) |
          octet_range(0x5D, 0x7E))                                      > auto

scope_token = string1(NQCHAR)                                           > pivot
scope = scope_token % many(skip(SP) * scope_token)                      > pivot

error = string1(NQSCHAR)                                                > pivot
error_description = string1(NQSCHAR)                                    > pivot
error_uri = URI_reference                                               > pivot


fill_names(globals(), RFC(6749))
コード例 #27
0
ファイル: rfc7234.py プロジェクト: dfirst/httpolice
    WarningValue,
)
from httpolice.syntax.common import DIGIT, DQUOTE, SP
from httpolice.syntax.rfc7230 import (
    comma_list1,
    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

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)
コード例 #28
0
ファイル: rfc8288.py プロジェクト: vfaronov/httpolice
        complain(1309)
    return MultiDict(r)

link_param = (
    (CaseInsensitive << token) * skip(BWS) *
    maybe(skip(literal('=') * BWS) * (mark(token) |
                                      mark(quoted_string))))            > pivot

link_value = Parametrized << (
    skip('<') * URI_Reference * skip('>') *
    (_process_params << many(skip(OWS * ';' * OWS) * link_param)))      > pivot

Link = comma_list(link_value)                                           > pivot


anchor = URI_Reference                                                  > auto

reg_rel_type = CaseInsensitive << (
    LOALPHA + string(LOALPHA | DIGIT | '.' | '-'))                      > auto
ext_rel_type = URI                                                      > auto
relation_type = reg_rel_type | ext_rel_type                             > pivot
rel = rev = relation_type % many(skip(string1(SP)) * relation_type)     > auto

hreflang = Language_Tag                                                 > auto

type_ = check_media_type << (
    MediaType << type_name + '/' + subtype_name)                        > auto


fill_names(globals(), RFC(8288))