]> git.ipfire.org Git - thirdparty/tornado.git/commitdiff
Rename WebSocketConnect to websocket_connect.
authorBen Darnell <ben@bendarnell.com>
Fri, 15 Mar 2013 03:45:48 +0000 (23:45 -0400)
committerBen Darnell <ben@bendarnell.com>
Fri, 15 Mar 2013 03:45:48 +0000 (23:45 -0400)
Add docs for undocumented functions and modules.

13 files changed:
docs/concurrent.rst [new file with mode: 0644]
docs/ioloop.rst
docs/networking.rst
docs/releases/next.rst
docs/tcpserver.rst [new file with mode: 0644]
docs/utilities.rst
docs/websocket.rst
tornado/concurrent.py
tornado/httpserver.py
tornado/ioloop.py
tornado/netutil.py
tornado/test/websocket_test.py
tornado/websocket.py

diff --git a/docs/concurrent.rst b/docs/concurrent.rst
new file mode 100644 (file)
index 0000000..c41a3dc
--- /dev/null
@@ -0,0 +1,5 @@
+``tornado.concurrent`` --- Work with threads and futures
+========================================================
+
+.. automodule:: tornado.concurrent
+    :members:
index 171ff38becaf0ff7e874e220d14b2099eceeca10..c22f414d31676e2f8d50ddb0694e8cb68fdd2403 100644 (file)
@@ -14,6 +14,8 @@
    .. automethod:: IOLoop.instance
    .. automethod:: IOLoop.initialized
    .. automethod:: IOLoop.install
+   .. automethod:: IOLoop.current
+   .. automethod:: IOLoop.make_current
    .. automethod:: IOLoop.start
    .. automethod:: IOLoop.stop
    .. automethod:: IOLoop.run_sync
index f71de718ae1426af05d9eb5f0821c3904c459681..e11b0531a416303fffb37a6a5e2d07afdc390268 100644 (file)
@@ -7,3 +7,4 @@ Asynchronous networking
    iostream
    httpclient
    netutil
+   tcpserver
index 89478dfd60affa34d75bf36594c88f319bf64373..e5a146297c5e832051719b5d8affc45900104bf9 100644 (file)
@@ -430,6 +430,6 @@ Multiple modules
 ~~~~~~~~~~~~~~~~~~~
 
 * Client-side WebSocket support is now available:
-  `tornado.websocket.WebSocketConnect`
+  `tornado.websocket.websocket_connect`
 * `WebSocketHandler` has new methods `ping` and `on_pong` to send pings
   to the browser (not supported on the ``draft76`` protocol)
diff --git a/docs/tcpserver.rst b/docs/tcpserver.rst
new file mode 100644 (file)
index 0000000..3456cc9
--- /dev/null
@@ -0,0 +1,5 @@
+``tornado.tcpserver`` --- Basic `IOStream`-based TCP server
+===========================================================
+
+.. automodule:: tornado.tcpserver
+    :members:
index 077cfda3aca975e5bcf3bc30df18f0ea39f80750..239c3c0ba6ceec87961dfb4113afef27bc133003 100644 (file)
@@ -4,6 +4,7 @@ Utilities
 .. toctree::
 
    autoreload
+   concurrent
    gen
    httputil
    log
index 0b689440781a9e40f764ec30aa5a8579e162326b..793a665fb53d1ade56b7b5f3734907d668e1253b 100644 (file)
    .. automethod:: WebSocketHandler.async_callback
    .. automethod:: WebSocketHandler.ping
    .. automethod:: WebSocketHandler.on_pong
+
+
+   Client-side support
+   -------------------
+
+   .. autofunction:: websocket_connect
+   .. autoclass:: WebSocketClientConnection
+       :members:
index 6b0121d7da82504ee166b63d1a87d9f367041318..f8ad0e2fb65ac43475e086e8651d299e10d27581 100644 (file)
@@ -132,6 +132,11 @@ dummy_executor = DummyExecutor()
 
 
 def run_on_executor(fn):
+    """Decorator to run a synchronous method asynchronously on an executor.
+
+    The decorated method may be called with a ``callback`` keyword
+    argument and returns a future.
+    """
     @functools.wraps(fn)
     def wrapper(self, *args, **kwargs):
         callback = kwargs.pop("callback", None)
@@ -165,6 +170,7 @@ def return_future(f):
     `gen.engine` function, or passing it to `IOLoop.add_future`).
 
     Usage::
+
         @return_future
         def future_func(arg1, arg2, callback):
             # Do stuff (possibly asynchronous)
index 13ed97cb4e1ba1052d6c4e356b3253b1c276fe14..c52adbf8dbc9d7472e2ba80124642932c44b4206 100644 (file)
@@ -191,6 +191,11 @@ class HTTPConnection(object):
         self._close_callback = None
 
     def set_close_callback(self, callback):
+        """Sets a callback that will be run when the connection is closed.
+
+        Use this instead of accessing `HTTPConnection.stream.set_close_callback`
+        directly (which was the recommended approach prior to Tornado 3.0).
+        """
         self._close_callback = stack_context.wrap(callback)
         self.stream.set_close_callback(self._on_connection_close)
 
index 2c5152215eaa2ac2b199a4833d99e7688fa50ea6..e63ac631c9e73b89c644ef8be9fc20f423279d74 100644 (file)
@@ -163,12 +163,31 @@ class IOLoop(Configurable):
 
     @staticmethod
     def current():
+        """Returns the current thread's `IOLoop`.
+
+        If an `IOLoop` is currently running or has been marked as current
+        by `make_current`, returns that instance.  Otherwise returns
+        `IOLoop.instance()`, i.e. the main thread's `IOLoop`.
+
+        In general you should use `IOLoop.current` as the default when
+        constructing an asynchronous object, and use `IOLoop.instance`
+        when you mean to communicate to the main thread from a different
+        one.
+        """
         current = getattr(IOLoop._current, "instance", None)
         if current is None:
             return IOLoop.instance()
         return current
 
     def make_current(self):
+        """Makes this the `IOLoop` for the current thread.
+
+        An `IOLoop` automatically becomes current for its thread
+        when it is started, but it is sometimes useful to call
+        `make_current` explictly before starting the `IOLoop`,
+        so that code run at startup time can find the right
+        instance.
+        """
         IOLoop._current.instance = self
 
     @staticmethod
index 86a3fa437ba46a469a197a0fb00c59b1c6fce5d0..cbf0f8004180debb3b00e40ba16dfa873a93273a 100644 (file)
@@ -160,6 +160,22 @@ def is_valid_ip(ip):
 
 
 class Resolver(Configurable):
+    """Configurable asynchronous DNS resolver interface.
+
+    By default, a blocking implementation is used (which simply
+    calls `socket.getaddrinfo`).  An alternative implementation
+    can be chosen with the `Resolver.configure` class method::
+
+        Resolver.configure('tornado.netutil.ThreadedResolver')
+
+    The implementations of this interface included with Tornado are
+
+    * `tornado.netutil.BlockingResolver`
+    * `tornado.netutil.ThreadedResolver`
+    * `tornado.netutil.OverrideResolver`
+    * `tornado.platform.twisted.TwistedResolver`
+    * `tornado.platform.caresresolver.CaresResolver`
+    """
     @classmethod
     def configurable_base(cls):
         return Resolver
@@ -199,11 +215,27 @@ class ExecutorResolver(Resolver):
 
 
 class BlockingResolver(ExecutorResolver):
+    """Default `Resolver` implementation, using `socket.getaddrinfo`.
+
+    The `IOLoop` will be blocked during the resolution, although the
+    callback will not be run until the next `IOLoop` iteration.
+    """
     def initialize(self, io_loop=None):
         super(BlockingResolver, self).initialize(io_loop=io_loop)
 
 
 class ThreadedResolver(ExecutorResolver):
+    """Multithreaded non-blocking `Resolver` implementation.
+
+    Requires the `concurrent.futures` package to be installed
+    (available in the standard library since Python 3.2,
+    installable with ``pip install futures`` in older versions).
+
+    The thread pool size can be configured with::
+
+        Resolver.configure('tornado.netutil.ThreadedResolver',
+                           num_threads=10)
+    """
     def initialize(self, io_loop=None, num_threads=10):
         from concurrent.futures import ThreadPoolExecutor
         super(ThreadedResolver, self).initialize(
index 5cd7f0f97b32d5114c173fadf6ac48eef8e4fb0d..eb961d24fde0588c980e1691547e5a106d899366 100644 (file)
@@ -1,6 +1,6 @@
 from tornado.testing import AsyncHTTPTestCase, gen_test
 from tornado.web import Application
-from tornado.websocket import WebSocketHandler, WebSocketConnect
+from tornado.websocket import WebSocketHandler, websocket_connect
 
 
 class EchoHandler(WebSocketHandler):
@@ -16,7 +16,7 @@ class WebSocketTest(AsyncHTTPTestCase):
 
     @gen_test
     def test_websocket_gen(self):
-        ws = yield WebSocketConnect(
+        ws = yield websocket_connect(
             'ws://localhost:%d/echo' % self.get_http_port(),
             io_loop=self.io_loop)
         ws.write_message('hello')
@@ -24,7 +24,7 @@ class WebSocketTest(AsyncHTTPTestCase):
         self.assertEqual(response, 'hello')
 
     def test_websocket_callbacks(self):
-        WebSocketConnect(
+        websocket_connect(
             'ws://localhost:%d/echo' % self.get_http_port(),
             io_loop=self.io_loop, callback=self.stop)
         ws = self.wait().result()
index 4bff6cd03660896344d7e536721a070c555f147a..cf1e6d1cf739ee3d4d2dddb5c15de1d92d8fefd7 100644 (file)
@@ -718,7 +718,8 @@ class WebSocketProtocol13(WebSocketProtocol):
                 self.stream.io_loop.time() + 5, self._abort)
 
 
-class _WebSocketClientConnection(simple_httpclient._HTTPConnection):
+class WebSocketClientConnection(simple_httpclient._HTTPConnection):
+    """WebSocket client connection."""
     def __init__(self, io_loop, request):
         self.connect_future = Future()
         self.read_future = None
@@ -735,7 +736,7 @@ class _WebSocketClientConnection(simple_httpclient._HTTPConnection):
             'Sec-WebSocket-Version': '13',
         })
 
-        super(_WebSocketClientConnection, self).__init__(
+        super(WebSocketClientConnection, self).__init__(
             io_loop, None, request, lambda: None, lambda response: None,
             104857600, Resolver(io_loop=io_loop))
 
@@ -759,9 +760,17 @@ class _WebSocketClientConnection(simple_httpclient._HTTPConnection):
         self.connect_future.set_result(self)
 
     def write_message(self, message, binary=False):
+        """Sends a message to the WebSocket server."""
         self.protocol.write_message(message, binary)
 
     def read_message(self, callback=None):
+        """Reads a message from the WebSocket server.
+
+        Returns a future whose result is the message, or None
+        if the connection is closed.  If a callback argument
+        is given it will be called with the future when it is
+        ready.
+        """
         assert self.read_future is None
         future = Future()
         if self.read_queue:
@@ -783,13 +792,17 @@ class _WebSocketClientConnection(simple_httpclient._HTTPConnection):
         pass
 
 
-def WebSocketConnect(url, io_loop=None, callback=None):
+def websocket_connect(url, io_loop=None, callback=None):
+    """Client-side websocket support.
+
+    Takes a url and returns a Future whose result is a `WebSocketConnection`.
+    """
     if io_loop is None:
         io_loop = IOLoop.current()
     request = httpclient.HTTPRequest(url)
     request = httpclient._RequestProxy(
         request, httpclient.HTTPRequest._DEFAULTS)
-    conn = _WebSocketClientConnection(io_loop, request)
+    conn = WebSocketClientConnection(io_loop, request)
     if callback is not None:
         io_loop.add_future(conn.connect_future, callback)
     return conn.connect_future