From 5735d2b027833628316aaf279ba8d9b074bdbedf Mon Sep 17 00:00:00 2001 From: "Dustin C. Hatch" Date: Wed, 28 Nov 2012 12:26:58 -0600 Subject: [PATCH] Better handling of string-type responses from controllers --HG-- branch : py3k --- src/milla/app.py | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/src/milla/app.py b/src/milla/app.py index d7117e1..e30da43 100644 --- a/src/milla/app.py +++ b/src/milla/app.py @@ -25,7 +25,6 @@ from milla.controllers import FaviconController from milla.util import asbool from webob.exc import HTTPNotFound, WSGIHTTPException, HTTPMethodNotAllowed import milla.dispatch -import webob __all__ = ['Application'] @@ -126,9 +125,16 @@ class Application(object): func.func.im_self.__after__(request) # The callable might have returned just a string, which is OK, - # but we need to wrap it in a WebOb response + # but we need to wrap it in a Response object + try: + # In Python 2, it could be a str or a unicode object + basestring = basestring #@UndefinedVariable + except NameError: + # Python 3 has no unicode objects and thus no need for + # basestring so we, just make it an alias for str + basestring = str if isinstance(response, basestring) or not response: - response = webob.Response(response) + response = request.ResponseClass(response) if not start_response_wrapper.called: start_response(response.status, response.headerlist)