If a controller callable returns a string, it needs to be wrapped in a Response object. To determine if this is the case, the Application tests to see if the returned object is an instance of `basestring`. Since `basestring` doesn't exist in Python 3, only `str` is a valid return type. Unfortunately, my way of testing whether the `basestring` type existed was flawed. Instead of raising `NameError` when it doesn't exist, `UnboundLocalError` (a subclass `NameError`) is *always* raised. Since the exception handler sets `basestring` equal to `str` assuming this is Python 3, most of the time this isn't a problem. If, however, the controller returns a `unicode` object in Python 2, the `isinstance` call returns `False`, so the response is not wrapped in a Response object. Rather than try to reassign the `basestring` name, now we just use `_string`, which will either be `basestring` (in Python 2) or `str` (in Python 3). Apparently, the unit tests didn't cover this case... |
||
---|---|---|
.settings | ||
doc | ||
src/milla | ||
.hgignore | ||
.hgtags | ||
.project | ||
.pydevproject | ||
COPYING | ||
MANIFEST.in | ||
README | ||
distribute_setup.py | ||
milla.svg | ||
setup.cfg | ||
setup.py |
README
.. vim: set ft=rst : ===== Milla ===== *Milla* is a simple and lightweight web framework for Python. It built on top of `WebOb`_ and thus implements the `WSGI`_ standard. It aims to be easy to use while imposing no restrictions, allowing web developers to write code the way they want, using the tools, platform, and extensions they choose. To get started using *Milla* right away, visit `Downloads`_ to get the latest version, then read the `Documentation`_. Example ======= .. code:: python from wsgiref import simple_server from milla.dispatch import routing import milla def hello(request): return 'Hello, world!' router = routing.Router() router.add_route('/', hello) app = milla.Application(router) httpd = simple_server.make_server('', 8080, app) httpd.serve_forever() .. _WebOb: http://webob.org/ .. _WSGI: http://wsgi.readthedocs.org/ .. _Downloads: https://bitbucket.org/AdmiralNemo/milla/downloads .. _Documentation: http://milla.readthedocs.org/