Esempio n. 1
0
subtype = token                                                         > pivot
media_type = Parametrized << (
    (MediaType << type_ + '/' + subtype) *
    (MultiDict << many(skip(OWS * ';' * OWS) * parameter())))           > pivot

content_coding = ContentCoding << token                                 > pivot

product_version = token                                                 > pivot
product = Versioned << ((ProductName << token) *
                        maybe(skip('/') * product_version))             > pivot
User_Agent = product % many(skip(RWS) *
                            (product | comment(include_parens=False)))  > pivot
Server = product % many(skip(RWS) *
                        (product | comment(include_parens=False)))      > pivot

day_name = (subst(0) << octet(0x4D) * octet(0x6F) * octet(0x6E) |
            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
Esempio n. 2
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))
Esempio n. 3
0
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)))

qdtext = (HTAB | SP | octet(0x21) | octet_range(0x23, 0x5B) |
          octet_range(0x5D, 0x7E) | obs_text)                           > auto
quoted_string = (skip(DQUOTE) *
                 string(qdtext | quoted_pair(sensible_for=u'"\\')) *
                 skip(DQUOTE))                                          > auto

ctext = (HTAB | SP | octet_range(0x21, 0x27) | octet_range(0x2A, 0x5B) |
         octet_range(0x5D, 0x7E) | obs_text)                            > auto

def comment(include_parens=False):
    inner = recursive() > named(u'comment', RFC(7230))
    inner.rec = '(' + string(ctext | quoted_pair(sensible_for=u'()\\') |
                             inner) + ')'
    if not include_parens:
        inner = (lambda s: s[1:-1]) << inner
    return inner > named(u'comment', RFC(7230))
Esempio n. 4
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
Esempio n. 5
0
    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
Esempio n. 6
0

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


qdtext = (HTAB | SP | octet(0x21) | octet_range(0x23, 0x5B)
          | octet_range(0x5D, 0x7E) | obs_text) > auto
quoted_string = (skip(DQUOTE) *
                 string(qdtext | quoted_pair(sensible_for=u'"\\')) *
                 skip(DQUOTE)) > auto

ctext = (HTAB | SP | octet_range(0x21, 0x27) | octet_range(0x2A, 0x5B)
         | octet_range(0x5D, 0x7E) | obs_text) > auto


def comment(include_parens=False):
    inner = recursive() > named(u'comment', RFC(7230))
    inner.rec = '(' + string(ctext | quoted_pair(sensible_for=u'()\\')
                             | inner) + ')'
    if not include_parens:
        inner = (lambda s: s[1:-1]) << inner
Esempio n. 7
0
subtype = token > pivot
media_type = Parametrized << (
    (_check_media_type << (MediaType << type_ + '/' + subtype)) *
    (MultiDict << many(skip(OWS * ';' * OWS) * parameter()))) > pivot

content_coding = ContentCoding << token > pivot

product_version = token > pivot
product = Versioned << (
    (ProductName << token) * maybe(skip('/') * product_version)) > pivot
User_Agent = product % many(
    skip(RWS) * (product | comment(include_parens=False))) > pivot
Server = product % many(skip(RWS) *
                        (product | comment(include_parens=False))) > pivot

day_name = (subst(0) << octet(0x4D) * octet(0x6F) * octet(0x6E)
            | 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
Esempio n. 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))
Esempio n. 9
0
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)))

qdtext = (HTAB | SP | octet(0x21) | octet_range(0x23, 0x5B) |
          octet_range(0x5D, 0x7E) | obs_text)                           > auto
quoted_string = (skip(DQUOTE) *
                 string(qdtext | quoted_pair(sensible_for=u'"\\')) *
                 skip(DQUOTE))                                          > auto

ctext = (HTAB | SP | octet_range(0x21, 0x27) | octet_range(0x2A, 0x5B) |
         octet_range(0x5D, 0x7E) | obs_text)                            > auto

def comment(include_parens=False):
    inner = recursive() > named(u'comment', RFC(7230))
    inner.rec = '(' + string(ctext | quoted_pair(sensible_for=u'()\\') |
                             inner) + ')'
    if not include_parens:
        inner = (lambda s: s[1:-1]) << inner
    return inner > named(u'comment', RFC(7230))
Esempio n. 10
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))
Esempio n. 11
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))
Esempio n. 12
0

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


qdtext = (HTAB | SP | octet(0x21) | octet_range(0x23, 0x5B)
          | octet_range(0x5D, 0x7E) | obs_text) > auto
quoted_string = (skip(DQUOTE) *
                 string(qdtext | quoted_pair(sensible_for=u'"\\')) *
                 skip(DQUOTE)) > auto

ctext = (HTAB | SP | octet_range(0x21, 0x27) | octet_range(0x2A, 0x5B)
         | octet_range(0x5D, 0x7E) | obs_text) > auto


def comment(include_parens=False):
    inner = recursive() > named(u'comment', RFC(7230))
    inner.rec = '(' + string(ctext | quoted_pair(sensible_for=u'()\\')
                             | inner) + ')'
    if not include_parens:
        inner = (lambda s: s[1:-1]) << inner