What’s new in Tornado 3.1¶
Jun 15, 2013¶
Multiple modules¶
- Many reference cycles have been broken up throughout the package, allowing for more efficient garbage collection on CPython.
- Silenced some log messages when connections are opened and immediately closed (i.e. port scans), or other situations related to closed connections.
- Various small speedups:
HTTPHeaderscase normalization,UIModuleproxy objects, precompile some regexes.
tornado.auth¶
OAuthMixinalways sendsoauth_version=1.0in its request as required by the spec.FacebookGraphMixinnow usesself._FACEBOOK_BASE_URLinfacebook_requestto allow the base url to be overridden.- The
authenticate_redirectandauthorize_redirectmethods in thetornado.authmixin classes all now return Futures. These methods are asynchronous inOAuthMixinand derived classes, although they do not take a callback. TheFuturethese methods return must be yielded if they are called from a function decorated withgen.coroutine(but notgen.engine). TwitterMixinnow uses/account/verify_credentialsto get information about the logged-in user, which is more robust against changing screen names.- The
demosdirectory (in the source distribution) has a newtwitterdemo usingTwitterMixin.
tornado.escape¶
url_escapeandurl_unescapehave a newplusargument (defaulting to True for consistency with the previous behavior) which specifies whether they work likeurllib.parse.unquoteorurllib.parse.unquote_plus.
tornado.gen¶
- Fixed a potential memory leak with long chains of
tornado.gencoroutines.
tornado.httpclient¶
tornado.httpclient.HTTPRequesttakes a new argumentauth_mode, which can be eitherbasicordigest. Digest authentication is only supported withtornado.curl_httpclient.tornado.curl_httpclientno longer goes into an infinite loop when pycurl returns a negative timeout.curl_httpclientnow supports thePATCHandOPTIONSmethods without the use ofallow_nonstandard_methods=True.- Worked around a class of bugs in libcurl that would result in
errors from
IOLoop.update_handlerin various scenarios including digest authentication and socks proxies. - The
TCP_NODELAYflag is now set when appropriate insimple_httpclient. simple_httpclientno longer logs exceptions, since those exceptions are made available to the caller asHTTPResponse.error.
tornado.httpserver¶
tornado.httpserver.HTTPServerhandles malformed HTTP headers more gracefully.HTTPServernow supports lists of IPs inX-Forwarded-For(it chooses the last, i.e. nearest one).- Memory is now reclaimed promptly on CPython when an HTTP request fails because it exceeded the maximum upload size.
- The
TCP_NODELAYflag is now set when appropriate inHTTPServer. - The
HTTPServerno_keep_aliveoption is now respected with HTTP 1.0 connections that explicitly passConnection: keep-alive. - The
Connection: keep-alivecheck for HTTP 1.0 connections is now case-insensitive. - The
strandreproftornado.httpserver.HTTPRequestno longer include the request body, reducing log spam on errors (and potential exposure/retention of private data).
tornado.httputil¶
- The cache used in
HTTPHeaderswill no longer grow without bound.
tornado.ioloop¶
- Some
IOLoopimplementations (such aspyzmq) accept objects other than integer file descriptors; these objects will now have their.close()method called when theIOLoop` is closed with ``all_fds=True. - The stub handles left behind by
IOLoop.remove_timeoutwill now get cleaned up instead of waiting to expire.
tornado.iostream¶
- Fixed a bug in
BaseIOStream.read_until_closethat would sometimes cause data to be passed to the final callback instead of the streaming callback. - The
IOStreamclose callback is now run more reliably if there is an exception in_try_inline_read. - New method
BaseIOStream.set_nodelaycan be used to set theTCP_NODELAYflag. - Fixed a case where errors in
SSLIOStream.connect(andSimpleAsyncHTTPClient) were not being reported correctly.
tornado.locale¶
Locale.format_datenow works on Python 3.
tornado.netutil¶
- The default
Resolverimplementation now works on Solaris. Resolvernow has aclosemethod.- Fixed a potential CPU DoS when
tornado.netutil.ssl_match_hostnameis used on certificates with an abusive wildcard pattern. - All instances of
ThreadedResolvernow share a single thread pool, whose size is set by the first one to be created (or the staticResolver.configuremethod). ExecutorResolveris now documented for public use.bind_socketsnow works in configurations with incomplete IPv6 support.
tornado.options¶
tornado.options.definewithmultiple=Truenow works on Python 3.tornado.options.optionsand otherOptionParserinstances support some new dict-like methods:items(), iteration over keys, and (read-only) access to options with square braket syntax.OptionParser.group_dictreturns all options with a given group name, andOptionParser.as_dictreturns all options.
tornado.process¶
tornado.process.Subprocessno longer leaks file descriptors into the child process, which fixes a problem in which the child could not detect that the parent process had closed its stdin pipe.Subprocess.set_exit_callbacknow works for subprocesses created without an explicitio_loopparameter.
tornado.stack_context¶
tornado.stack_contexthas been rewritten and is now much faster.- New function
run_with_stack_contextfacilitates the use of stack contexts with coroutines.
tornado.tcpserver¶
- The constructors of
TCPServerandHTTPServernow take amax_buffer_sizekeyword argument.
tornado.template¶
- Some internal names used by the template system have been changed;
now all “reserved” names in templates start with
_tt_.
tornado.testing¶
tornado.testing.AsyncTestCase.waitnow raises the correct exception when it has been modified bytornado.stack_context.tornado.testing.gen_testcan now be called as@gen_test(timeout=60)to give some tests a longer timeout than others.- The environment variable
ASYNC_TEST_TIMEOUTcan now be set to override the default timeout forAsyncTestCase.waitandgen_test. bind_unused_portnow passesNoneinstead of0as the port togetaddrinfo, which works better with some unusual network configurations.
tornado.util¶
tornado.util.import_objectnow works with top-level module names that do not contain a dot.tornado.util.import_objectnow consistently raisesImportErrorinstead ofAttributeErrorwhen it fails.
tornado.web¶
- The
handlerslist passed to thetornado.web.Applicationconstructor andadd_handlersmethods can now contain lists in addition to tuples andURLSpecobjects. tornado.web.StaticFileHandlernow works on Windows when the client passes anIf-Modified-Sincetimestamp before 1970.- New method
RequestHandler.log_exceptioncan be overridden to customize the logging behavior when an exception is uncaught. Most apps that currently override_handle_request_exceptioncan now use a combination ofRequestHandler.log_exceptionandwrite_error. RequestHandler.get_argumentnow raisesMissingArgumentError(a subclass oftornado.web.HTTPError, which is what it raised previously) if the argument cannot be found.Application.reverse_urlnow usesurl_escapewithplus=False, i.e. spaces are encoded as%20instead of+.- Arguments extracted from the url path are now decoded with
url_unescapewithplus=False, so plus signs are left as-is instead of being turned into spaces. RequestHandler.send_errorwill now only be called once per request, even if multiple exceptions are caught by the stack context.- The
tornado.web.asynchronousdecorator is no longer necessary for methods that return aFuture(i.e. those that use thegen.coroutineorreturn_futuredecorators) RequestHandler.preparemay now be asynchronous if it returns aFuture. Theasynchronousdecorator is not used withprepare; one of theFuture-related decorators should be used instead.RequestHandler.current_usermay now be assigned to normally.RequestHandler.redirectno longer silently strips control characters and whitespace. It is now an error to pass control characters, newlines or tabs.StaticFileHandlerhas been reorganized internally and now has additional extension points that can be overridden in subclasses.StaticFileHandlernow supports HTTPRangerequests.StaticFileHandleris still not suitable for files too large to comfortably fit in memory, butRangesupport is necessary in some browsers to enable seeking of HTML5 audio and video.StaticFileHandlernow uses longer hashes by default, and uses the same hashes forEtagas it does for versioned urls.StaticFileHandler.make_static_urlandRequestHandler.static_urlnow have an additional keyword argumentinclude_versionto suppress the url versioning.StaticFileHandlernow reads its file in chunks, which will reduce memory fragmentation.- Fixed a problem with the
Dateheader and cookie expiration dates when the system locale is set to a non-english configuration.
tornado.websocket¶
WebSocketHandlernow catchesStreamClosedErrorand runson_closeimmediately instead of logging a stack trace.- New method
WebSocketHandler.set_nodelaycan be used to set theTCP_NODELAYflag.
tornado.wsgi¶
- Fixed an exception in
WSGIContainerwhen the connection is closed while output is being written.