Esempio n. 1
0
    def target_form(self):
        try:
            target = self.target.encode('iso-8859-1')
        except UnicodeError as e:
            self.complain(1045, error=e)
            return None

        if self.method == m.CONNECT:
            parser = mark(authority_form)
        elif self.method == m.OPTIONS:
            parser = (mark(origin_form) | mark(asterisk_form)
                      | mark(absolute_form))
        else:
            parser = mark(origin_form) | mark(absolute_form)

        r = simple_parse(target,
                         parser,
                         self.complain,
                         1045,
                         place=u'request target')
        if okay(r):
            (symbol, _) = r
            return symbol
        else:
            return None
Esempio n. 2
0
 def target_form(self):
     if self.method == m.CONNECT:
         symbol = mark(authority_form)
     elif self.method == m.OPTIONS:
         symbol = (mark(origin_form) | mark(asterisk_form)
                   | mark(absolute_form))
     else:
         symbol = mark(origin_form) | mark(absolute_form)
     r = simple_parse(self.target,
                      symbol,
                      self.complain,
                      1045,
                      place=u'request target')
     if okay(r):
         (symbol, _) = r
         return symbol
     else:
         return r
Esempio n. 3
0
    def target_form(self):
        try:
            target = self.target.encode('iso-8859-1')
        except UnicodeError as e:
            self.complain(1045, error=e)
            return None

        if self.method == m.CONNECT:
            parser = mark(authority_form)
        elif self.method == m.OPTIONS:
            parser = (mark(origin_form) | mark(asterisk_form) |
                      mark(absolute_form))
        else:
            parser = mark(origin_form) | mark(absolute_form)

        r = simple_parse(target, parser,
                         self.complain, 1045, place=u'request target')
        if okay(r):
            (symbol, _) = r
            return symbol
        else:
            return None
Esempio n. 4
0
    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)

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
Esempio n. 5
0
from httpolice import known, message
from httpolice.blackboard import derived_property
from httpolice.known import auth, cache, cc, h, m, prefer, tc, upgrade
from httpolice.parse import mark, parse
from httpolice.structure import (EntityTag, Method, MultiDict, Parametrized,
                                 Versioned, http2, http10, http11, okay)
from httpolice.syntax import rfc7230
from httpolice.syntax.common import CTL
from httpolice.syntax.rfc7230 import (absolute_form, asterisk_form,
                                      authority_form, origin_form)
from httpolice.util.data import duplicates
from httpolice.util.text import force_unicode


normal_target = mark(origin_form) | mark(absolute_form)
options_target = mark(origin_form) | mark(asterisk_form) | mark(absolute_form)
connect_target = mark(authority_form)


class Request(message.Message):

    def __init__(self, scheme, method, target, version, header_entries,
                 body, trailer_entries=None, remark=None):
        # pylint: disable=redefined-outer-name
        """
        :param scheme:
            The scheme of the request URI, as a Unicode string
            (usually ``u'http'`` or ``u'https'``),
            or `None` if unknown (this disables some checks).
Esempio n. 6
0
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) *
        maybe(skip('=') * (token | quoted_string))) > named(
            u'extension-pragma', RFC(7234), is_pivot=True)
Esempio n. 7
0
            value = parse(value,
                          symbol,
                          complain,
                          1158,
                          name=name,
                          value=value)
        r.append((name, value))
        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
Esempio n. 8
0

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)),
          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
Esempio n. 9
0
            u'anchor': URI_Reference, u'rel': rel, u'rev': rev,
            u'hreflang': hreflang, u'type': type_, u'title*': ext_value,
        }.get(name)
        if symbol is not None:
            value = parse(value, symbol, complain, 1158,
                          name=name, value=value)
        r.append((name, value))
        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