Skip to content

Commit 6bf30d0

Browse files
committed
Add/update docs for twisted, caresresolver, and util modules
1 parent 8525507 commit 6bf30d0

File tree

10 files changed

+118
-59
lines changed

10 files changed

+118
-59
lines changed

docs/caresresolver.rst

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
``tornado.platform.caresresolver`` --- Asynchronous DNS Resolver using C-Ares
2+
=============================================================================
3+
4+
.. module:: tornado.platform.caresresolver
5+
6+
This module contains a DNS resolver using the c-ares library (and its
7+
wrapper ``pycares``).
8+
9+
.. py:class:: CaresResolver
10+
11+
Name resolver based on the c-ares library.
12+
13+
This is a non-blocking and non-threaded resolver. It may not produce
14+
the same results as the system resolver, but can be used for non-blocking
15+
resolution when threads cannot be used.
16+
17+
c-ares fails to resolve some names when ``family`` is ``AF_UNSPEC``,
18+
so it is only recommended for use in ``AF_INET`` (i.e. IPv4). This is
19+
the default for ``tornado.simple_httpclient``, but other libraries
20+
may default to ``AF_UNSPEC``.

docs/integration.rst

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ Integration with other services
44
.. toctree::
55

66
auth
7+
caresresolver
78
twisted
89
websocket
910
wsgi

docs/releases/next.rst

Lines changed: 17 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -25,9 +25,9 @@ Highlights
2525
to the root logger, allowing for finer-grained configuration.
2626
* New class `tornado.process.Subprocess` wraps `subprocess.Popen` with
2727
`.PipeIOStream` access to the child's file descriptors.
28-
* `.IOLoop` now has a static ``configure`` method like the one on
29-
`.AsyncHTTPClient`, which can be used to select an IOLoop implementation
30-
other than the default.
28+
* `.IOLoop` now has a static `configure <.Configurable.configure>`
29+
method like the one on `.AsyncHTTPClient`, which can be used to
30+
select an `.IOLoop` implementation other than the default.
3131
* `.IOLoop` can now optionally use a monotonic clock if available
3232
(see below for more details).
3333

@@ -191,9 +191,9 @@ Multiple modules
191191
specific thread's (usually the main thread's) IOLoop).
192192
* New method `.IOLoop.add_future` to run a callback on the IOLoop when
193193
an asynchronous ``Future`` finishes.
194-
* `.IOLoop` now has a static ``configure`` method like the one on
195-
`.AsyncHTTPClient`, which can be used to select an IOLoop implementation
196-
other than the default.
194+
* `.IOLoop` now has a static `configure <.Configurable.configure>`
195+
method like the one on `.AsyncHTTPClient`, which can be used to
196+
select an `.IOLoop` implementation other than the default.
197197
* The `.IOLoop` poller implementations (``select``, ``epoll``, ``kqueue``)
198198
are now available as distinct subclasses of `.IOLoop`. Instantiating
199199
`.IOLoop` will continue to automatically choose the best available
@@ -262,8 +262,8 @@ Multiple modules
262262
blocking, but non-blocking implementations are available using one
263263
of three optional dependencies: `~tornado.netutil.ThreadedResolver`
264264
using the `concurrent.futures` thread pool,
265-
``tornado.platform.caresresolver.CaresResolver`` using the ``pycares``
266-
library, or ``tornado.platform.twisted.TwistedResolver`` using ``twisted``
265+
`tornado.platform.caresresolver.CaresResolver` using the ``pycares``
266+
library, or `tornado.platform.twisted.TwistedResolver` using ``twisted``
267267
* New function `tornado.netutil.is_valid_ip` returns true if a given string
268268
is a valid IP (v4 or v6) address.
269269
* `tornado.netutil.bind_sockets` has a new ``flags`` argument that can
@@ -301,19 +301,19 @@ Multiple modules
301301
* Function ``tornado.options.enable_pretty_logging`` has been moved to the
302302
`tornado.log` module.
303303

304-
```tornado.platform.caresresolver``
305-
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
304+
`tornado.platform.caresresolver`
305+
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
306306

307307
* New module containing an asynchronous implementation of the `.Resolver`
308308
interface, using the ``pycares`` library.
309309

310310
`tornado.platform.twisted`
311311
~~~~~~~~~~~~~~~~~~~~~~~~~~
312312

313-
* New class ``tornado.platform.twisted.TwistedIOLoop`` allows Tornado
313+
* New class `tornado.platform.twisted.TwistedIOLoop` allows Tornado
314314
code to be run on the Twisted reactor (as opposed to the existing
315-
``TornadoReactor``, which bridges the gap in the other direction).
316-
* New class ``tornado.platform.twisted.TwistedResolver`` is an asynchronous
315+
`.TornadoReactor`, which bridges the gap in the other direction).
316+
* New class `tornado.platform.twisted.TwistedResolver` is an asynchronous
317317
implementation of the `.Resolver` interface.
318318

319319
`tornado.process`
@@ -325,9 +325,10 @@ Multiple modules
325325
``tornado.simple_httpclient``
326326
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
327327

328-
* ``SimpleAsyncHTTPClient`` now takes a ``resolver`` keyword argument (which
329-
may be passed to either the constructor or ``configure``), to allow it to
330-
use the new non-blocking `tornado.netutil.Resolver`.
328+
* ``SimpleAsyncHTTPClient`` now takes a ``resolver`` keyword argument
329+
(which may be passed to either the constructor or `configure
330+
<.Configurable.configure>`), to allow it to use the new non-blocking
331+
`tornado.netutil.Resolver`.
331332
* When following redirects, ``SimpleAsyncHTTPClient`` now treats a 302
332333
response code the same as a 303. This is contrary to the HTTP spec
333334
but consistent with all browsers and other major HTTP clients

docs/twisted.rst

Lines changed: 45 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -7,43 +7,63 @@ This module lets you run applications and libraries written for
77
Twisted in a Tornado application. It can be used in two modes,
88
depending on which library's underlying event loop you want to use.
99

10+
This module has been tested with Twisted versions 11.0.0 and newer.
11+
1012
Twisted on Tornado
1113
------------------
1214

13-
``TornadoReactor`` implements the Twisted reactor interface on top of
14-
the Tornado IOLoop. To use it, simply call ``install`` at the beginning
15-
of the application::
15+
.. py:class:: TornadoReactor
1616
17-
import tornado.platform.twisted
18-
tornado.platform.twisted.install()
19-
from twisted.internet import reactor
17+
``TornadoReactor`` implements the Twisted reactor interface on top of
18+
the Tornado IOLoop. To use it, simply call ``install`` at the beginning
19+
of the application::
2020

21-
When the app is ready to start, call ``IOLoop.instance().start()``
22-
instead of ``reactor.run()``.
21+
import tornado.platform.twisted
22+
tornado.platform.twisted.install()
23+
from twisted.internet import reactor
2324

24-
It is also possible to create a non-global reactor by calling
25-
``tornado.platform.twisted.TornadoReactor(io_loop)``. However, if
26-
the `.IOLoop` and reactor are to be short-lived (such as those used in
27-
unit tests), additional cleanup may be required. Specifically, it is
28-
recommended to call::
25+
When the app is ready to start, call ``IOLoop.instance().start()``
26+
instead of ``reactor.run()``.
2927

30-
reactor.fireSystemEvent('shutdown')
31-
reactor.disconnectAll()
28+
It is also possible to create a non-global reactor by calling
29+
``tornado.platform.twisted.TornadoReactor(io_loop)``. However, if
30+
the `.IOLoop` and reactor are to be short-lived (such as those used in
31+
unit tests), additional cleanup may be required. Specifically, it is
32+
recommended to call::
3233

33-
before closing the `.IOLoop`.
34+
reactor.fireSystemEvent('shutdown')
35+
reactor.disconnectAll()
36+
37+
before closing the `.IOLoop`.
3438

3539
Tornado on Twisted
3640
------------------
3741

38-
``TwistedIOLoop`` implements the Tornado IOLoop interface on top of the Twisted
39-
reactor. Recommended usage::
42+
.. py:class:: TwistedIOLoop
4043
41-
from tornado.platform.twisted import TwistedIOLoop
42-
from twisted.internet import reactor
43-
TwistedIOLoop().install()
44-
# Set up your tornado application as usual using `IOLoop.instance`
45-
reactor.run()
44+
``TwistedIOLoop`` implements the Tornado IOLoop interface on top
45+
of the Twisted reactor. Recommended usage::
4646

47-
``TwistedIOLoop`` always uses the global Twisted reactor.
47+
from tornado.platform.twisted import TwistedIOLoop
48+
from twisted.internet import reactor
49+
TwistedIOLoop().install()
50+
# Set up your tornado application as usual using `IOLoop.instance`
51+
reactor.run()
4852

49-
This module has been tested with Twisted versions 11.0.0 and newer.
53+
``TwistedIOLoop`` always uses the global Twisted reactor.
54+
55+
Twisted DNS resolver
56+
--------------------
57+
58+
.. py:class:: TwistedResolver
59+
60+
This is a non-blocking and non-threaded resolver. It is
61+
recommended only when threads cannot be used, since it has
62+
limitations compared to the standard ``getaddrinfo``-based
63+
`~tornado.netutil.Resolver` and
64+
`~tornado.netutil.ThreadedResolver`. Specifically, it returns at
65+
most one result, and arguments other than ``host`` and ``family``
66+
are ignored. It may fail to resolve when ``family`` is not
67+
``socket.AF_UNSPEC``.
68+
69+
Requires Twisted 12.1 or newer.

docs/util.rst

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
``tornado.util`` --- General-purpose utilities
2+
==============================================
3+
4+
.. automodule:: tornado.util
5+
:members:

docs/utilities.rst

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,3 +12,4 @@ Utilities
1212
process
1313
stack_context
1414
testing
15+
util

tornado/netutil.py

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -164,7 +164,8 @@ class Resolver(Configurable):
164164
165165
By default, a blocking implementation is used (which simply calls
166166
`socket.getaddrinfo`). An alternative implementation can be
167-
chosen with the ``Resolver.configure`` class method::
167+
chosen with the `Resolver.configure <.Configurable.configure>`
168+
class method::
168169
169170
Resolver.configure('tornado.netutil.ThreadedResolver')
170171
@@ -173,8 +174,8 @@ class Resolver(Configurable):
173174
* `tornado.netutil.BlockingResolver`
174175
* `tornado.netutil.ThreadedResolver`
175176
* `tornado.netutil.OverrideResolver`
176-
* ``tornado.platform.twisted.TwistedResolver``
177-
* ``tornado.platform.caresresolver.CaresResolver``
177+
* `tornado.platform.twisted.TwistedResolver`
178+
* `tornado.platform.caresresolver.CaresResolver`
178179
"""
179180
@classmethod
180181
def configurable_base(cls):

tornado/platform/caresresolver.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ class CaresResolver(Resolver):
1515
1616
c-ares fails to resolve some names when ``family`` is ``AF_UNSPEC``,
1717
so it is only recommended for use in ``AF_INET`` (i.e. IPv4). This is
18-
the default for `tornado.simple_httpclient`, but other libraries
18+
the default for ``tornado.simple_httpclient``, but other libraries
1919
may default to ``AF_UNSPEC``.
2020
"""
2121
def initialize(self, io_loop=None):

tornado/platform/twisted.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,8 @@
2222
Twisted in a Tornado application. It can be used in two modes,
2323
depending on which library's underlying event loop you want to use.
2424
25+
This module has been tested with Twisted versions 11.0.0 and newer.
26+
2527
Twisted on Tornado
2628
------------------
2729
@@ -60,8 +62,6 @@
6062
reactor.run()
6163
6264
`TwistedIOLoop` always uses the global Twisted reactor.
63-
64-
This module has been tested with Twisted versions 11.0.0 and newer.
6565
"""
6666

6767
from __future__ import absolute_import, division, print_function, with_statement

tornado/util.py

Lines changed: 22 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,14 @@
1-
"""Miscellaneous utility functions."""
1+
"""Miscellaneous utility functions and classes.
2+
3+
This module is used internally by Tornado. It is not necessarily expected
4+
that the functions and classes defined here will be useful to other
5+
applications, but they are documented here in case they are.
6+
7+
The one public-facing part of this module is the `Configurable` class
8+
and its `~Configurable.configure` method, which becomes a part of the
9+
interface of its subclasses, including `.AsyncHTTPClient`, `.IOLoop`,
10+
and `.Resolver`.
11+
"""
212

313
from __future__ import absolute_import, division, print_function, with_statement
414

@@ -8,7 +18,8 @@
818

919

1020
class ObjectDict(dict):
11-
"""Makes a dictionary behave like an object."""
21+
"""Makes a dictionary behave like an object, with attribute-style access.
22+
"""
1223
def __getattr__(self, name):
1324
try:
1425
return self[name]
@@ -115,16 +126,17 @@ class Configurable(object):
115126
The implementation subclass as well as optional keyword arguments to
116127
its initializer can be set globally at runtime with `configure`.
117128
118-
By using the constructor as the factory method, the interface looks like
119-
a normal class, ``isinstance()`` works as usual, etc. This pattern
120-
is most useful when the choice of implementation is likely to be a
121-
global decision (e.g. when epoll is available, always use it instead of
122-
select), or when a previously-monolithic class has been split into
123-
specialized subclasses.
129+
By using the constructor as the factory method, the interface
130+
looks like a normal class, `isinstance` works as usual, etc. This
131+
pattern is most useful when the choice of implementation is likely
132+
to be a global decision (e.g. when `~select.epoll` is available,
133+
always use it instead of `~select.select`), or when a
134+
previously-monolithic class has been split into specialized
135+
subclasses.
124136
125137
Configurable subclasses must define the class methods
126138
`configurable_base` and `configurable_default`, and use the instance
127-
method `initialize` instead of `__init__`.
139+
method `initialize` instead of ``__init__``.
128140
"""
129141
__impl_class = None
130142
__impl_kwargs = None
@@ -163,7 +175,7 @@ def configurable_default(cls):
163175
def initialize(self):
164176
"""Initialize a `Configurable` subclass instance.
165177
166-
Configurable classes should use `initialize` instead of `__init__`.
178+
Configurable classes should use `initialize` instead of ``__init__``.
167179
"""
168180

169181
@classmethod
@@ -210,8 +222,6 @@ class ArgReplacer(object):
210222
and similar wrappers.
211223
"""
212224
def __init__(self, func, name):
213-
"""Create an ArgReplacer for the named argument to the given function.
214-
"""
215225
self.name = name
216226
try:
217227
self.arg_pos = inspect.getargspec(func).args.index(self.name)

0 commit comments

Comments
 (0)