ThinkChat2.0新版上线,更智能更精彩,支持会话、画图、视频、阅读、搜索等,送10W Token,即刻开启你的AI之旅 广告
### Navigation - [index](# "General Index") - [modules](# "Python Module Index") | - [next](# "What鈥檚 new in Tornado 3.0.2") | - [previous](# "What鈥檚 new in Tornado 3.1.1") | - [Tornado 4.4.dev1 documentation](#) » - [Release notes](#) » # 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 immediatelyclosed (i.e. port scans), or other situations related to closedconnections. - Various small speedups: [`HTTPHeaders`](# "tornado.httputil.HTTPHeaders") case normalization, [`UIModule`](# "tornado.web.UIModule")proxy objects, precompile some regexes. ### [`tornado.auth`](# "tornado.auth") - [`OAuthMixin`](# "tornado.auth.OAuthMixin") always sends `oauth_version=1.0` in itsrequest as required by the spec. - [`FacebookGraphMixin`](# "tornado.auth.FacebookGraphMixin") now uses `self._FACEBOOK_BASE_URL`in [`facebook_request`](# "tornado.auth.FacebookGraphMixin.facebook_request") to allow the base url to beoverridden. - The `authenticate_redirect` and `authorize_redirect` methods in the[`tornado.auth`](# "tornado.auth") mixin classes all now return Futures. These methodsare asynchronous in [`OAuthMixin`](# "tornado.auth.OAuthMixin") and derived classes, although theydo not take a callback. The [`Future`](# "tornado.concurrent.Future") these methods return must beyielded if they are called from a function decorated with [`gen.coroutine`](# "tornado.gen.coroutine")(but not [`gen.engine`](# "tornado.gen.engine")). - [`TwitterMixin`](# "tornado.auth.TwitterMixin") now uses `/account/verify_credentials` to get informationabout the logged-in user, which is more robust against changing screennames. - The `demos` directory (in the source distribution) has a new`twitter` demo using [`TwitterMixin`](# "tornado.auth.TwitterMixin"). ### [`tornado.escape`](# "tornado.escape") - [`url_escape`](# "tornado.escape.url_escape") and [`url_unescape`](# "tornado.escape.url_unescape") have a new `plus` argument (defaultingto True for consistency with the previous behavior) which specifieswhether they work like [`urllib.parse.unquote`](https://docs.python.org/3.4/library/urllib.parse.html#urllib.parse.unquote "(in Python v3.4)") [https://docs.python.org/3.4/library/urllib.parse.html#urllib.parse.unquote] or [`urllib.parse.unquote_plus`](https://docs.python.org/3.4/library/urllib.parse.html#urllib.parse.unquote_plus "(in Python v3.4)") [https://docs.python.org/3.4/library/urllib.parse.html#urllib.parse.unquote_plus]. ### [`tornado.gen`](# "tornado.gen") - Fixed a potential memory leak with long chains of [`tornado.gen`](# "tornado.gen") coroutines. ### [`tornado.httpclient`](# "tornado.httpclient") - [`tornado.httpclient.HTTPRequest`](# "tornado.httpclient.HTTPRequest") takes a new argument `auth_mode`,which can be either `basic` or `digest`. Digest authenticationis only supported with `tornado.curl_httpclient`. - `tornado.curl_httpclient` no longer goes into an infinite loop whenpycurl returns a negative timeout. - `curl_httpclient` now supports the `PATCH` and `OPTIONS` methodswithout the use of `allow_nonstandard_methods=True`. - Worked around a class of bugs in libcurl that would result inerrors from [`IOLoop.update_handler`](# "tornado.ioloop.IOLoop.update_handler") in various scenarios includingdigest authentication and socks proxies. - The `TCP_NODELAY` flag is now set when appropriate in `simple_httpclient`. - `simple_httpclient` no longer logs exceptions, since those exceptionsare made available to the caller as `HTTPResponse.error`. ### [`tornado.httpserver`](# "tornado.httpserver") - [`tornado.httpserver.HTTPServer`](# "tornado.httpserver.HTTPServer") handles malformed HTTP headers moregracefully. - [`HTTPServer`](# "tornado.httpserver.HTTPServer") now supports lists of IPs in `X-Forwarded-For`(it chooses the last, i.e. nearest one). - Memory is now reclaimed promptly on CPython when an HTTP requestfails because it exceeded the maximum upload size. - The `TCP_NODELAY` flag is now set when appropriate in [`HTTPServer`](# "tornado.httpserver.HTTPServer"). - The [`HTTPServer`](# "tornado.httpserver.HTTPServer")`no_keep_alive` option is now respected withHTTP 1.0 connections that explicitly pass `Connection: keep-alive`. - The `Connection: keep-alive` check for HTTP 1.0 connections is nowcase-insensitive. - The [`str`](https://docs.python.org/3.4/library/stdtypes.html#str "(in Python v3.4)") [https://docs.python.org/3.4/library/stdtypes.html#str] and [`repr`](https://docs.python.org/3.4/library/functions.html#repr "(in Python v3.4)") [https://docs.python.org/3.4/library/functions.html#repr] of `tornado.httpserver.HTTPRequest` no longerinclude the request body, reducing log spam on errors (and potentialexposure/retention of private data). ### [`tornado.httputil`](# "tornado.httputil") - The cache used in [`HTTPHeaders`](# "tornado.httputil.HTTPHeaders") will no longer grow without bound. ### [`tornado.ioloop`](# "tornado.ioloop") - Some [`IOLoop`](# "tornado.ioloop.IOLoop") implementations (such as `pyzmq`) accept objectsother than integer file descriptors; these objects will now havetheir `.close()` method called when the `IOLoop` is closed with``all_fds=True`. - The stub handles left behind by [`IOLoop.remove_timeout`](# "tornado.ioloop.IOLoop.remove_timeout") will now getcleaned up instead of waiting to expire. ### [`tornado.iostream`](# "tornado.iostream") - Fixed a bug in [`BaseIOStream.read_until_close`](# "tornado.iostream.BaseIOStream.read_until_close") that would sometimescause data to be passed to the final callback instead of the streamingcallback. - The [`IOStream`](# "tornado.iostream.IOStream") close callback is now run more reliably if there isan exception in `_try_inline_read`. - New method [`BaseIOStream.set_nodelay`](# "tornado.iostream.BaseIOStream.set_nodelay") can be used to set the`TCP_NODELAY` flag. - Fixed a case where errors in `SSLIOStream.connect` (and`SimpleAsyncHTTPClient`) were not being reported correctly. ### [`tornado.locale`](# "tornado.locale") - [`Locale.format_date`](# "tornado.locale.Locale.format_date") now works on Python 3. ### [`tornado.netutil`](# "tornado.netutil") - The default [`Resolver`](# "tornado.netutil.Resolver") implementation now works on Solaris. - [`Resolver`](# "tornado.netutil.Resolver") now has a [`close`](# "tornado.netutil.Resolver.close") method. - Fixed a potential CPU DoS when `tornado.netutil.ssl_match_hostname`is used on certificates with an abusive wildcard pattern. - All instances of [`ThreadedResolver`](# "tornado.netutil.ThreadedResolver") now share a single thread pool,whose size is set by the first one to be created (or the static`Resolver.configure` method). - [`ExecutorResolver`](# "tornado.netutil.ExecutorResolver") is now documented for public use. - [`bind_sockets`](# "tornado.netutil.bind_sockets") now works in configurations with incomplete IPv6 support. ### [`tornado.options`](# "tornado.options") - [`tornado.options.define`](# "tornado.options.define") with `multiple=True` now works on Python 3. - [`tornado.options.options`](# "tornado.options.options") and other [`OptionParser`](# "tornado.options.OptionParser") instances support somenew dict-like methods: [`items()`](# "tornado.options.OptionParser.items"), iteration over keys,and (read-only) access to options with square braket syntax.[`OptionParser.group_dict`](# "tornado.options.OptionParser.group_dict") returns all options with a given groupname, and [`OptionParser.as_dict`](# "tornado.options.OptionParser.as_dict") returns all options. ### [`tornado.process`](# "tornado.process") - [`tornado.process.Subprocess`](# "tornado.process.Subprocess") no longer leaks file descriptors intothe child process, which fixes a problem in which the child could notdetect that the parent process had closed its stdin pipe. - [`Subprocess.set_exit_callback`](# "tornado.process.Subprocess.set_exit_callback") now works for subprocesses createdwithout an explicit `io_loop` parameter. ### [`tornado.stack_context`](# "tornado.stack_context") - [`tornado.stack_context`](# "tornado.stack_context") has been rewritten and is now much faster. - New function [`run_with_stack_context`](# "tornado.stack_context.run_with_stack_context") facilitates the use of stackcontexts with coroutines. ### [`tornado.tcpserver`](# "tornado.tcpserver") - The constructors of [`TCPServer`](# "tornado.tcpserver.TCPServer") and [`HTTPServer`](# "tornado.httpserver.HTTPServer") now take a`max_buffer_size` keyword argument. ### [`tornado.template`](# "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") - [`tornado.testing.AsyncTestCase.wait`](# "tornado.testing.AsyncTestCase.wait") now raises the correct exceptionwhen it has been modified by [`tornado.stack_context`](# "tornado.stack_context"). - [`tornado.testing.gen_test`](# "tornado.testing.gen_test") can now be called as `@gen_test(timeout=60)`to give some tests a longer timeout than others. - The environment variable `ASYNC_TEST_TIMEOUT` can now be set tooverride the default timeout for [`AsyncTestCase.wait`](# "tornado.testing.AsyncTestCase.wait") and [`gen_test`](# "tornado.testing.gen_test"). - [`bind_unused_port`](# "tornado.testing.bind_unused_port") now passes `None` instead of `0` as the portto `getaddrinfo`, which works better with some unusual networkconfigurations. ### [`tornado.util`](# "tornado.util") - [`tornado.util.import_object`](# "tornado.util.import_object") now works with top-level module names thatdo not contain a dot. - [`tornado.util.import_object`](# "tornado.util.import_object") now consistently raises [`ImportError`](https://docs.python.org/3.4/library/exceptions.html#ImportError "(in Python v3.4)") [https://docs.python.org/3.4/library/exceptions.html#ImportError]instead of [`AttributeError`](https://docs.python.org/3.4/library/exceptions.html#AttributeError "(in Python v3.4)") [https://docs.python.org/3.4/library/exceptions.html#AttributeError] when it fails. ### [`tornado.web`](# "tornado.web") - The `handlers` list passed to the [`tornado.web.Application`](# "tornado.web.Application") constructorand [`add_handlers`](# "tornado.web.Application.add_handlers") methods can now containlists in addition to tuples and [`URLSpec`](# "tornado.web.URLSpec") objects. - [`tornado.web.StaticFileHandler`](# "tornado.web.StaticFileHandler") now works on Windows when the clientpasses an `If-Modified-Since` timestamp before 1970. - New method [`RequestHandler.log_exception`](# "tornado.web.RequestHandler.log_exception") can be overridden tocustomize the logging behavior when an exception is uncaught. Mostapps that currently override `_handle_request_exception` can nowuse a combination of [`RequestHandler.log_exception`](# "tornado.web.RequestHandler.log_exception") and[`write_error`](# "tornado.web.RequestHandler.write_error"). - [`RequestHandler.get_argument`](# "tornado.web.RequestHandler.get_argument") now raises [`MissingArgumentError`](# "tornado.web.MissingArgumentError")(a subclass of [`tornado.web.HTTPError`](# "tornado.web.HTTPError"), which is what it raised previously)if the argument cannot be found. - [`Application.reverse_url`](# "tornado.web.Application.reverse_url") now uses [`url_escape`](# "tornado.escape.url_escape") with `plus=False`,i.e. spaces are encoded as `%20` instead of `+`. - Arguments extracted from the url path are now decoded with[`url_unescape`](# "tornado.escape.url_unescape") with `plus=False`, so plus signs are left as-isinstead of being turned into spaces. - [`RequestHandler.send_error`](# "tornado.web.RequestHandler.send_error") will now only be called once per request,even if multiple exceptions are caught by the stack context. - The [`tornado.web.asynchronous`](# "tornado.web.asynchronous") decorator is no longer necessary formethods that return a [`Future`](# "tornado.concurrent.Future") (i.e. those that use the [`gen.coroutine`](# "tornado.gen.coroutine")or [`return_future`](# "tornado.concurrent.return_future") decorators) - [`RequestHandler.prepare`](# "tornado.web.RequestHandler.prepare") may now be asynchronous if it returns a[`Future`](# "tornado.concurrent.Future"). The [`asynchronous`](# "tornado.web.asynchronous") decorator is not used with`prepare`; one of the [`Future`](# "tornado.concurrent.Future")-related decorators should be used instead. - `RequestHandler.current_user` may now be assigned to normally. - [`RequestHandler.redirect`](# "tornado.web.RequestHandler.redirect") no longer silently strips control charactersand whitespace. It is now an error to pass control characters, newlinesor tabs. - [`StaticFileHandler`](# "tornado.web.StaticFileHandler") has been reorganized internally and now has additionalextension points that can be overridden in subclasses. - [`StaticFileHandler`](# "tornado.web.StaticFileHandler") now supports HTTP `Range` requests.[`StaticFileHandler`](# "tornado.web.StaticFileHandler") is still not suitable for files too large tocomfortably fit in memory, but `Range` support is necessary in somebrowsers to enable seeking of HTML5 audio and video. - [`StaticFileHandler`](# "tornado.web.StaticFileHandler") now uses longer hashes by default, and uses the samehashes for `Etag` as it does for versioned urls. - [`StaticFileHandler.make_static_url`](# "tornado.web.StaticFileHandler.make_static_url") and [`RequestHandler.static_url`](# "tornado.web.RequestHandler.static_url")now have an additional keyword argument `include_version` to suppressthe url versioning. - [`StaticFileHandler`](# "tornado.web.StaticFileHandler") now reads its file in chunks, which will reducememory fragmentation. - Fixed a problem with the `Date` header and cookie expiration dateswhen the system locale is set to a non-english configuration. ### [`tornado.websocket`](# "tornado.websocket") - [`WebSocketHandler`](# "tornado.websocket.WebSocketHandler") now catches [`StreamClosedError`](# "tornado.iostream.StreamClosedError") and runs[`on_close`](# "tornado.websocket.WebSocketHandler.on_close") immediately instead of logging astack trace. - New method [`WebSocketHandler.set_nodelay`](# "tornado.websocket.WebSocketHandler.set_nodelay") can be used to set the`TCP_NODELAY` flag. ### [`tornado.wsgi`](# "tornado.wsgi") - Fixed an exception in [`WSGIContainer`](# "tornado.wsgi.WSGIContainer") when the connection is closedwhile output is being written. © Copyright 2009-2016, The Tornado Authors. Created using [Sphinx](http://sphinx-doc.org/) 1.3.5.