Beispiel #1
0
 def serve_tool(self, path_list, environ, start_response, **kwargs):
     """add???
     
     :param path_list: add???
     :param environ: add???
     :param start_response: add???
     :returns: add???
     """
     toolname = path_list[1]
     args = path_list[2:]
     tool = self.load_webtool(toolname)
     if not tool:
         return self.not_found_exception(environ, start_response)
     tool.site = self
     response = Response()
     kwargs['environ'] = environ
     kwargs['response'] = response
     result = tool(*args, **kwargs)
     content_type = getattr(tool, 'content_type')
     if content_type:
         response.content_type = content_type
     headers = getattr(tool, 'headers', [])
     for header_name, header_value in headers:
         response.add_header(header_name, header_value)
         
     if isinstance(result, unicode):
         response.content_type = 'text/plain'
         response.unicode_body = result
     elif isinstance(result, basestring):
         response.body = result
     elif isinstance(result, Response):
         response = result
     return response(environ, start_response)