Beispiel #1
0
    def __call__(self, environ, start_response):
        result = self.application(environ, start_response)

        # Bail if the returned value is not a tuple.
        if not isinstance(result, tuple):
            return result

        if len(result) == 2:
            template, data, extras = result + (dict(),)
        elif len(result) == 3:
            template, data, extras = result

        if not isinstance(template, basestring) or not isinstance(extras, dict):
            raise TypeError("Invalid tuple values returned to TemplatingMiddleware.")

        response.content_type, output = render(template, data, **extras)

        if isinstance(response.content_type, unicode):
            response.content_type = response.content_type.encode('iso-8859-1')

        if isinstance(output, str):
            response.body = output
        elif isinstance(output, unicode):
            response.unicode_body = output

        return response(environ, start_response)
Beispiel #2
0
 def response(cls, result, environ, start_response):
     try:
         from web.core import response
     
     except ImportError:
         from webob import Response
         response = Response()
     
     response.content_type = result[0]
     
     if isinstance(result[1], str):
         response.body = result[1]
     
     elif isinstance(result[1], unicode):
         response.unicode_body = result[1]
     
     return response(environ, start_response)