示例#1
0
    def __init__(self, server, priv_request):
        log.Logger.__init__(self, server)
        log.LogProxy.__init__(self, server)
        self._server = server
        self._ref = priv_request
        self._secured = server.is_secured

        content_type = self.get_header("content-type")
        mime_type, encoding = http.parse_content_type(content_type)
        language = self.get_header("content-language") or http.DEFAULT_LANGUAGE
        location = http.path2tuple(self._ref.path)
        accept = self.get_header("accept")
        accepted_mime_types = http.parse_accepted_types(accept)
        accept_tree = http.build_mime_tree(accepted_mime_types)
        accept_charset = self.get_header("accept-charset")
        accepted_encodings = http.parse_accepted_charsets(accept_charset)
        accept_languages = self.get_header("accept-languages")
        accepted_languages = http.parse_accepted_languages(accept_languages)
        method = http.Methods[self._ref.method]
        protocol = _protocol_lookup[self._ref.clientproto]

        self._mime_type = mime_type
        self._encoding = encoding
        self._language = language
        self._location = location
        self._accepted_mime_types = accepted_mime_types
        self._accept_tree = accept_tree
        self._accepted_encodings = accepted_encodings
        self._accepted_languages = accepted_languages
        self._method = method
        self._protocol = protocol
        self._credentials = None

        self._context = {}  # Black box

        self._reading = False
        self._objects = []

        # Look for URI arguments only, the POST is content, not arguments
        uri_parts = self._ref.uri.split("?", 1)
        if len(uri_parts) > 1:
            arguments = twhttp.parse_qs(uri_parts[1], 1)
        else:
            arguments = {}

        # Look for domain information
        domain = self.get_header("host")
        if not domain:
            domain = "%s:%s" % (self._ref.host.host, self._ref.host.port)
        domain = self._decode(domain)
        content_length = self.get_header("content-length")
        length = content_length and int(content_length)

        # To prevent content being consumed
        # when it's application/x-www-form-urlencoded
        self._ref.content.seek(0, 0)

        self._arguments = arguments
        self._domain = domain
        self._length = length
示例#2
0
 def check(tup, encoding="utf8"):
     inter = http.tuple2path(tup, encoding=encoding)
     result = http.path2tuple(inter, encoding=encoding)
     self.assertEqual(result, tup)
示例#3
0
 def check(path, expected):
     result = http.path2tuple(path)
     self.assertEqual(result, expected)
示例#4
0
 def __init__(self, locations, auth_delay=None):
     self._locations = set([http.path2tuple(v) if isinstance(v, str) else v
                            for v in locations])
     self._auth_delay = auth_delay