예제 #1
0
파일: webserver.py 프로젝트: pepribas/F3AT
    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
파일: webserver.py 프로젝트: pepribas/F3AT
 def negotiate_mime_types(self, obj, accepts={}):
     acc_types = http.build_mime_tree(accepts, True)
     priorities = {}
     for doc_type, doc_subtypes in self._mime_types.items():
         acc_subtypes = acc_types.get(doc_type, acc_types["*"])
         for doc_subtype, doc_pri in doc_subtypes.items():
             acc_pri = acc_subtypes.get(doc_subtype, acc_subtypes["*"])
             priority = doc_pri * acc_pri
             mime_type = http.tuple2mime((doc_type, doc_subtype))
             if self._registry.lookup_writer(mime_type, obj):
                 priorities[mime_type] = priority
     order = priorities.keys()
     order.sort(key=priorities.get)
     return order[::-1]