Example #1
0
from httpolice.parse import (auto, can_complain, fill_names, group, literal,
                             many, maybe, maybe_str, named, octet, octet_range,
                             pivot, recursive, skip, string, string1,
                             string_excluding, string_times, subst)
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:
Example #2
0
    fill_names,
    maybe,
    octet,
    octet_range,
    pivot,
    string,
    subst,
)
from httpolice.structure import EntityTag
from httpolice.syntax.common import DQUOTE
from httpolice.syntax.rfc7230 import comma_list1, obs_text
from httpolice.syntax.rfc7231 import HTTP_date


weak = subst(True) << octet(0x57) * octet(0x2F)                         > auto
etagc = octet(0x21) | octet_range(0x23, 0x7E) | obs_text                > auto

@can_complain
def _no_backslashes(complain, s):
    if u'\\' in s:
        complain(1119)
    return s

opaque_tag = _no_backslashes << DQUOTE + string(etagc) + DQUOTE         > auto
entity_tag = EntityTag << maybe(weak, False) * opaque_tag               > pivot

ETag = entity_tag                                                       > pivot
Last_Modified = HTTP_date                                               > pivot

If_Match = '*' | comma_list1(entity_tag)                                > pivot
If_None_Match = '*' | comma_list1(entity_tag)                           > pivot
Example #3
0
# -*- coding: utf-8; -*-

from httpolice.citation import RFC
from httpolice.parse import auto, fill_names, octet, octet_range


ALPHA = octet_range(0x41, 0x5A) | octet_range(0x61, 0x7A)               > auto
CHAR = octet_range(0x01, 0x7F)                                          > auto
CTL = octet_range(0x00, 0x1F) | octet(0x7F)                             > auto
CR = octet(0x0D)                                                        > auto
DIGIT = octet_range(0x30, 0x39)                                         > auto
DQUOTE = octet(0x22)                                                    > auto
HEXDIG = DIGIT | 'A' | 'B' | 'C' | 'D' | 'E' | 'F'                      > auto
HTAB = octet(0x09)                                                      > auto
LF = octet(0x0A)                                                        > auto
SP = octet(0x20)                                                        > auto
VCHAR = octet_range(0x21, 0x7E)                                         > auto

CRLF = CR + LF                                                          > auto

fill_names(globals(), RFC(5234))
Example #4
0
# -*- coding: utf-8; -*-

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


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
Example #5
0
# -*- coding: utf-8; -*-

from httpolice.citation import RFC
from httpolice.parse import (auto, can_complain, fill_names, maybe, octet,
                             octet_range, pivot, string, subst)
from httpolice.structure import EntityTag
from httpolice.syntax.common import DQUOTE
from httpolice.syntax.rfc7230 import comma_list1, obs_text
from httpolice.syntax.rfc7231 import HTTP_date

weak = subst(True) << octet(0x57) * octet(0x2F) > auto
etagc = octet(0x21) | octet_range(0x23, 0x7E) | obs_text > auto


@can_complain
def _no_backslashes(complain, s):
    if u'\\' in s:
        complain(1119)
    return s


opaque_tag = _no_backslashes << DQUOTE + string(etagc) + DQUOTE > auto
entity_tag = EntityTag << maybe(weak, False) * opaque_tag > pivot

ETag = entity_tag > pivot
Last_Modified = HTTP_date > pivot

If_Match = '*' | comma_list1(entity_tag) > pivot
If_None_Match = '*' | comma_list1(entity_tag) > pivot
If_Modified_Since = HTTP_date > pivot
If_Unmodified_Since = HTTP_date > pivot
Example #6
0
# -*- coding: utf-8; -*-

from httpolice.citation import RFC
from httpolice.parse import auto, fill_names, octet_range
from httpolice.syntax.rfc7230 import quoted_string, token


LOALPHA = octet_range(0x61, 0x7A)                                       > auto

value = token | quoted_string                                           > auto


fill_names(globals(), RFC(2616))
Example #7
0
from httpolice.citation import RFC
from httpolice.parse import (auto, can_complain, fill_names, group, literal,
                             many, maybe, maybe_str, named, octet, octet_range,
                             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:
Example #8
0
                             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
    | 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
Example #9
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))
Example #10
0
from httpolice.citation import RFC
from httpolice.parse import (auto, fill_names, literal, maybe_str, octet_range,
                             pivot, string, string1, string_times)
from httpolice.structure import LanguageTag
from httpolice.syntax.common import ALPHA, DIGIT

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
Example #11
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))
Example #12
0
# -*- coding: utf-8; -*-

from httpolice.citation import RFC
from httpolice.parse import auto, fill_names, octet, octet_range

ALPHA = octet_range(0x41, 0x5A) | octet_range(0x61, 0x7A) > auto
CHAR = octet_range(0x01, 0x7F) > auto
CTL = octet_range(0x00, 0x1F) | octet(0x7F) > auto
CR = octet(0x0D) > auto
DIGIT = octet_range(0x30, 0x39) > auto
DQUOTE = octet(0x22) > auto
HEXDIG = DIGIT | 'A' | 'B' | 'C' | 'D' | 'E' | 'F' > auto
HTAB = octet(0x09) > auto
LF = octet(0x0A) > auto
SP = octet(0x20) > auto
VCHAR = octet_range(0x21, 0x7E) > auto

CRLF = CR + LF > auto

fill_names(globals(), RFC(5234))
Example #13
0
from httpolice.citation import RFC
from httpolice.parse import auto, fill_names, octet_range
from httpolice.syntax.rfc7230 import quoted_string, token

LOALPHA = octet_range(0x61, 0x7A) > auto

value = token | quoted_string > auto

fill_names(globals(), RFC(2616))
Example #14
0

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 |
    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 |