Ben Darnell [Wed, 21 Apr 2010 20:57:05 +0000 (13:57 -0700)]
cStringIO's constructor uses a 16-bit encoding when given a unicode
string. This is inconsistent with its write method, which encodes all
strings as ascii (and rejects unicode strings iff they have any
non-ascii characters). This change uses utf-8 as the default encoding
when constructing cStringIO objects in tornado.
Ben Darnell [Tue, 20 Apr 2010 22:40:33 +0000 (15:40 -0700)]
Send all logging to the root logger instead of per-module loggers.
This undoes the effect of
http://github.com/facebook/tornado/commit/e391fd289ed085671344504cc5b1fa84f5a3c774
Per-module loggers are problematic because only the top-level convenience
logging.{error,warning,...} functions configure logging on-demand, so
an app that only uses per-module loggers will produce no output except
"no handlers found for logger X". Since tornado.ioloop swallows and logs
all exceptions, this makes it too hard to tell what's going on for apps
that do not configure logging explicitly.
Instead of setting log levels on individual module's loggers,
logging.Handler.addFilter can be used with a filter that examines
the module attribute of the log record.
Ben Darnell [Mon, 19 Apr 2010 18:20:03 +0000 (11:20 -0700)]
Better HTTP header parsing: Allow (and strip) any amount of leading
and trailing whitespace around header values instead of just a single
space. Such whitespace is legal but appears to be uncommon (and nginx
apparently normalizes everything to a single space)
http://tools.ietf.org/html/rfc2616#page-31
Ben Darnell [Mon, 5 Apr 2010 19:23:24 +0000 (12:23 -0700)]
Make options.__getattr__ raise AttributeError instead of Error for consistency
with standard attribute lookups (so getattr(options, 'foo', None) works
if no option 'foo' has been defined).
Ben Darnell [Fri, 26 Mar 2010 22:55:04 +0000 (15:55 -0700)]
Make add_handlers (for multiple hostnames) usable with static_path (which
forces the creation of a wildcard handler) by maintaining a sensible order
for handler groups.
Dolapo Falola [Thu, 18 Mar 2010 01:44:16 +0000 (18:44 -0700)]
add a template_loader application setting for using custom template loaders. a slight refactoring of TemplateLoader's load method to expose some internals. also, add a reset method to the loader that's called in debug mode to flush the template cache.
Ben Darnell [Tue, 9 Mar 2010 17:17:23 +0000 (09:17 -0800)]
Fix bug with IOLoop's 'waker' pipe which rendered it ineffective on linux
and mac (where pipes are unidirectional) and caused high cpu usage
on solaris (where pipes are bidirectional). Thanks to Jari Ahonen for
finding the bug.
Ben Darnell [Thu, 4 Mar 2010 20:30:26 +0000 (12:30 -0800)]
Set the close-on-exec flag on file descriptors used by IOLoop (epoll/kqueue
and pipe) so that long-lived autoreloading processes don't leak file
descriptors.
Ben Darnell [Thu, 4 Mar 2010 19:52:18 +0000 (11:52 -0800)]
Use a WeakKeyDictionary instead of a regular dictionary to associate
IOLoop and AsyncHTTPClients. This prevents leaks of memory and file
descriptors when one process (in my case a unit test runner) create
many IOLoop/AsyncHTTPClient pairs.
Ben Darnell [Tue, 2 Mar 2010 02:55:38 +0000 (18:55 -0800)]
Revamp logging configuration.
* If --logging=none, tornado will not touch the python logging config.
* Colored output is optional. If curses is not available or stderr is not
a tty, non-colorized output will be used.
* Log output to stderr can be suppressed with --log_to_stderr=false
* Logs can be written to a file (non-colorized) with --log_file_prefix.
Logs will be rotated, which can be controlled with --log_file_max_size
and --log_file_num_backups.
* By default, logs go to a file if --log_file_prefix is set and to stderr
if it is not. To log to both stderr and a file, --log_to_stderr must
be set to true explicitly.
Bret Taylor [Fri, 5 Feb 2010 18:24:57 +0000 (10:24 -0800)]
Support passing in cookie value directly in cases where you have to parse the value from other sources (e.g., from the URL for Flash requests). Also fix documentation error for Facebook Connect.
Ben Darnell [Thu, 4 Feb 2010 21:18:43 +0000 (13:18 -0800)]
Don't set content-length in StaticFileHandler unless we're actually
sending the content. Some browsers get confused by this (e.g. the
version of webkit embedded in fluid, but not the version used in chrome).
Ben Darnell [Wed, 3 Feb 2010 20:18:44 +0000 (12:18 -0800)]
Include cookie name in signature so that a value signed for use in one
cookie can't be used in another. Note that this invalidates all existing
signed cookies.
Bret Taylor [Mon, 18 Jan 2010 05:12:24 +0000 (21:12 -0800)]
Fix httpclient / epoll interaction errors, per http://groups.google.com/group/python-tornado/browse_thread/thread/276059a076593266. Thanks everyone for the patch and discussion.
Ben Darnell [Sat, 16 Jan 2010 02:42:00 +0000 (18:42 -0800)]
Catch IOError in addition to OSError in IOLoop.remove_handler
(friendfeed's epoll module throws OSError, while the one in the standard
library throws IOError)
Ben Darnell [Fri, 8 Jan 2010 03:06:11 +0000 (19:06 -0800)]
Add a method to RequestHandler that can be used to detect when the connection
has been closed by the client.
This has always been supported via
self.request.connection.stream.set_close_callback, but putting it in
RequestHandler directly is more discoverable and less fragile.
Ben Darnell [Fri, 8 Jan 2010 02:53:47 +0000 (18:53 -0800)]
Add a kqueue-based implementation of IOLoop for BSD/Mac systems.
The main reason for this is to be able to detect when a connection has
been closed on the other side.
(http://github.com/facebook/tornado/issues/#issue/37)
This has been supported with epoll but not select, and it turned out to be
easier to add kqueue support than to figure out how to detect and handle
this case with select.
This change has not been tested in a production environment, but I have tested
it on my mac (10.6) and everything appears to work, and
IOStream.set_close_callback now works as expected.
Ben Darnell [Thu, 17 Dec 2009 01:01:37 +0000 (17:01 -0800)]
If IOLoop.stop is called before the loop is running, make the next
call to IOLoop.start return immediately, so that one call each to start
and stop will result in the loop not running rather than running
infinitely, even if the call to stop happens first.
Chris Wetherell [Mon, 14 Dec 2009 23:21:26 +0000 (15:21 -0800)]
Added kwargs to get_error_html in the RequestHandler so that downstream actors can render or otherwise use the exception object thrown. This is a backwards-incompatible change for anyone who has overridden get_error_html().
Ben Darnell [Thu, 10 Dec 2009 00:44:19 +0000 (16:44 -0800)]
Add Application.reverse_url, which can generate a url to a handler by name.
This minimizes repetition of url patterns for links and redirects.
Internally, handler mappings are now maintained as a list of URLSpec objects
instead of tuples. The Application constructor and add_handlers method
will accept either URLSpecs or (pattern, handler, [kwargs]) tuples.