Skip to content

Commit 300d231

Browse files
committed
Finish this round of doc updates
1 parent 6d5ebab commit 300d231

File tree

10 files changed

+180
-87
lines changed

10 files changed

+180
-87
lines changed

tornado/auth.py

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -697,9 +697,9 @@ def authorize_redirect(self, oauth_scope, callback_uri=None,
697697
698698
Some of the available resources are:
699699
700-
Gmail Contacts - http://www.google.com/m8/feeds/
701-
Calendar - http://www.google.com/calendar/feeds/
702-
Finance - http://finance.google.com/finance/feeds/
700+
* Gmail Contacts - http://www.google.com/m8/feeds/
701+
* Calendar - http://www.google.com/calendar/feeds/
702+
* Finance - http://finance.google.com/finance/feeds/
703703
704704
You can authorize multiple resources by separating the resource
705705
URLs with a space.
@@ -740,6 +740,9 @@ def _oauth_get_user(self, access_token, callback):
740740
class FacebookMixin(object):
741741
"""Facebook Connect authentication.
742742
743+
New applications should consider using `FacebookGraphMixin` below instead
744+
of this class.
745+
743746
To authenticate with Facebook, register your application with
744747
Facebook at http://www.facebook.com/developers/apps.php. Then
745748
copy your API Key and Application Secret to the application settings
@@ -799,10 +802,10 @@ def authorize_redirect(self, extended_permissions, callback_uri=None,
799802
http://wiki.developers.facebook.com/index.php/Extended_permission.
800803
The most common resource types include:
801804
802-
publish_stream
803-
read_stream
804-
email
805-
sms
805+
* publish_stream
806+
* read_stream
807+
* email
808+
* sms
806809
807810
extended_permissions can be a single permission name or a list of
808811
names. To get the session secret and session key, call
@@ -918,13 +921,14 @@ def _signature(self, args):
918921
return hashlib.md5(body).hexdigest()
919922

920923
class FacebookGraphMixin(OAuth2Mixin):
924+
"""Facebook authentication using the new Graph API and OAuth2."""
921925
_OAUTH_ACCESS_TOKEN_URL = "https://graph.facebook.com/oauth/access_token?"
922926
_OAUTH_AUTHORIZE_URL = "https://graph.facebook.com/oauth/authorize?"
923927
_OAUTH_NO_CALLBACKS = False
924928

925929
def get_authenticated_user(self, redirect_uri, client_id, client_secret,
926930
code, callback, extra_fields=None):
927-
""" Handles the login for the Facebook user, returning a user object.
931+
"""Handles the login for the Facebook user, returning a user object.
928932
929933
Example usage::
930934

tornado/autoreload.py

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,14 @@
1616

1717
"""A module to automatically restart the server when a module is modified.
1818
19+
Most applications should not call this module directly. Instead, pass the
20+
keyword argument ``debug=True`` to the `tornado.web.Application` constructor.
21+
This will enable autoreload mode as well as checking for changes to templates
22+
and static resources.
23+
1924
This module depends on IOLoop, so it will not work in WSGI applications
20-
and Google AppEngine.
25+
and Google AppEngine. It also will not work correctly when HTTPServer's
26+
multi-process mode is used.
2127
"""
2228

2329
import functools

tornado/options.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -310,7 +310,10 @@ class Error(Exception):
310310

311311

312312
def enable_pretty_logging():
313-
"""Turns on formatted logging output as configured."""
313+
"""Turns on formatted logging output as configured.
314+
315+
This is called automatically by `parse_command_line`.
316+
"""
314317
root_logger = logging.getLogger()
315318
if options.log_file_prefix:
316319
channel = logging.handlers.RotatingFileHandler(

tornado/stack_context.py

Lines changed: 21 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -61,19 +61,19 @@ def __init__(self):
6161
_state = _State()
6262

6363
class StackContext(object):
64-
def __init__(self, context_factory):
65-
'''Establishes the given context as a StackContext that will be transferred.
64+
'''Establishes the given context as a StackContext that will be transferred.
6665
67-
Note that the parameter is a callable that returns a context
68-
manager, not the context itself. That is, where for a
69-
non-transferable context manager you would say::
66+
Note that the parameter is a callable that returns a context
67+
manager, not the context itself. That is, where for a
68+
non-transferable context manager you would say::
7069
71-
with my_context():
70+
with my_context():
7271
73-
StackContext takes the function itself rather than its result::
72+
StackContext takes the function itself rather than its result::
7473
75-
with StackContext(my_context):
76-
'''
74+
with StackContext(my_context):
75+
'''
76+
def __init__(self, context_factory):
7777
self.context_factory = context_factory
7878

7979
# Note that some of this code is duplicated in ExceptionStackContext
@@ -98,19 +98,19 @@ def __exit__(self, type, value, traceback):
9898
_state.contexts = self.old_contexts
9999

100100
class ExceptionStackContext(object):
101+
'''Specialization of StackContext for exception handling.
102+
103+
The supplied exception_handler function will be called in the
104+
event of an uncaught exception in this context. The semantics are
105+
similar to a try/finally clause, and intended use cases are to log
106+
an error, close a socket, or similar cleanup actions. The
107+
exc_info triple (type, value, traceback) will be passed to the
108+
exception_handler function.
109+
110+
If the exception handler returns true, the exception will be
111+
consumed and will not be propagated to other exception handlers.
112+
'''
101113
def __init__(self, exception_handler):
102-
'''Specialization of StackContext for exception handling.
103-
104-
The supplied exception_handler function will be called in the
105-
event of an uncaught exception in this context. The semantics are
106-
similar to a try/finally clause, and intended use cases are to log
107-
an error, close a socket, or similar cleanup actions. The
108-
exc_info triple (type, value, traceback) will be passed to the
109-
exception_handler function.
110-
111-
If the exception handler returns true, the exception will be
112-
consumed and will not be propagated to other exception handlers.
113-
'''
114114
self.exception_handler = exception_handler
115115

116116
def __enter__(self):

tornado/testing.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,13 +3,13 @@
33
44
This module contains three parts:
55
6-
* AsyncTestCase/AsyncHTTPTestCase: Subclasses of unittest.TestCase
6+
* `AsyncTestCase`/`AsyncHTTPTestCase`: Subclasses of unittest.TestCase
77
with additional support for testing asynchronous (IOLoop-based) code.
88
9-
* LogTrapTestCase: Subclass of unittest.TestCase that discards log output
9+
* `LogTrapTestCase`: Subclass of unittest.TestCase that discards log output
1010
from tests that pass and only produces output for failing tests.
1111
12-
* main(): A simple test runner (wrapper around unittest.main()) with support
12+
* `main()`: A simple test runner (wrapper around unittest.main()) with support
1313
for the tornado.autoreload module to rerun the tests when code changes.
1414
1515
These components may be used together or independently. In particular,

tornado/websocket.py

Lines changed: 12 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,16 @@
1+
"""Server-side implementation of the WebSocket protocol.
2+
3+
`WebSockets <http://dev.w3.org/html5/websockets/>`_ allow for bidirectional
4+
communication between the browser and server.
5+
6+
.. warning::
7+
8+
The WebSocket protocol is still in development. This module currently
9+
implements the "draft76" version of the protocol, which is supported
10+
only by Chrome and Safari. See this `browser compatibility table
11+
<http://en.wikipedia.org/wiki/WebSockets#Browser_support>`_ on Wikipedia.
12+
"""
113
# Author: Jacob Kristhammar, 2010
2-
#
3-
# Updated version of websocket.py[1] that implements latest[2] stable version
4-
# of the websocket protocol.
5-
#
6-
# NB. It's no longer possible to manually select which callback that should
7-
# be invoked upon message reception. Instead you must override the
8-
# on_message(message) method to handle incoming messsages.
9-
# This also means that you don't have to explicitly invoke
10-
# receive_message, in fact you shouldn't.
11-
#
12-
# [1] http://github.com/facebook/tornado/blob/
13-
# 2c89b89536bbfa081745336bb5ab5465c448cb8a/tornado/websocket.py
14-
# [2] http://tools.ietf.org/html/draft-hixie-thewebsocketprotocol-76
1514

1615
import functools
1716
import hashlib

tornado/wsgi.py

Lines changed: 47 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -16,38 +16,17 @@
1616

1717
"""WSGI support for the Tornado web framework.
1818
19-
We export WSGIApplication, which is very similar to web.Application, except
20-
no asynchronous methods are supported (since WSGI does not support
21-
non-blocking requests properly). If you call self.flush() or other
22-
asynchronous methods in your request handlers running in a WSGIApplication,
23-
we throw an exception.
24-
25-
Example usage::
26-
27-
import tornado.web
28-
import tornado.wsgi
29-
import wsgiref.simple_server
30-
31-
class MainHandler(tornado.web.RequestHandler):
32-
def get(self):
33-
self.write("Hello, world")
34-
35-
if __name__ == "__main__":
36-
application = tornado.wsgi.WSGIApplication([
37-
(r"/", MainHandler),
38-
])
39-
server = wsgiref.simple_server.make_server('', 8888, application)
40-
server.serve_forever()
41-
42-
See the 'appengine' demo for an example of using this module to run
43-
a Tornado app on Google AppEngine.
44-
45-
Since no asynchronous methods are available for WSGI applications, the
46-
httpclient and auth modules are both not available for WSGI applications.
47-
48-
We also export WSGIContainer, which lets you run other WSGI-compatible
49-
frameworks on the Tornado HTTP server and I/O loop. See WSGIContainer for
50-
details and documentation.
19+
WSGI is the Python standard for web servers, and allows for interoperability
20+
between Tornado and other Python web frameworks and servers. This module
21+
provides WSGI support in two ways:
22+
23+
* `WSGIApplication` is a version of `tornado.web.Application` that can run
24+
inside a WSGI server. This is useful for running a Tornado app on another
25+
HTTP server, such as Google App Engine. See the `WSGIApplication` class
26+
documentation for limitations that apply.
27+
* `WSGIContainer` lets you run other WSGI applications and frameworks on the
28+
Tornado HTTP server. For example, with this class you can mix Django
29+
and Tornado handlers in a single server.
5130
"""
5231

5332
import cgi
@@ -70,10 +49,38 @@ def get(self):
7049
from cStringIO import StringIO as BytesIO # python 2
7150

7251
class WSGIApplication(web.Application):
73-
"""A WSGI-equivalent of web.Application.
52+
"""A WSGI equivalent of `tornado.web.Application`.
7453
54+
WSGIApplication is very similar to web.Application, except no
55+
asynchronous methods are supported (since WSGI does not support
56+
non-blocking requests properly). If you call self.flush() or other
57+
asynchronous methods in your request handlers running in a
58+
WSGIApplication, we throw an exception.
59+
60+
Example usage::
61+
62+
import tornado.web
63+
import tornado.wsgi
64+
import wsgiref.simple_server
65+
66+
class MainHandler(tornado.web.RequestHandler):
67+
def get(self):
68+
self.write("Hello, world")
69+
70+
if __name__ == "__main__":
71+
application = tornado.wsgi.WSGIApplication([
72+
(r"/", MainHandler),
73+
])
74+
server = wsgiref.simple_server.make_server('', 8888, application)
75+
server.serve_forever()
76+
77+
See the 'appengine' demo for an example of using this module to run
78+
a Tornado app on Google AppEngine.
79+
80+
Since no asynchronous methods are available for WSGI applications, the
81+
httpclient and auth modules are both not available for WSGI applications.
7582
We support the same interface, but handlers running in a WSGIApplication
76-
do not support flush() or asynchronous methods.
83+
do not support flush() or asynchronous methods.
7784
"""
7885
def __init__(self, handlers=None, default_host="", **settings):
7986
web.Application.__init__(self, handlers, default_host, transforms=[],
@@ -94,7 +101,7 @@ def __call__(self, environ, start_response):
94101

95102

96103
class HTTPRequest(object):
97-
"""Mimics httpserver.HTTPRequest for WSGI applications."""
104+
"""Mimics `tornado.httpserver.HTTPRequest` for WSGI applications."""
98105
def __init__(self, environ):
99106
"""Parses the given WSGI environ to construct the request."""
100107
self.method = environ["REQUEST_METHOD"]
@@ -182,8 +189,11 @@ def simple_app(environ, start_response):
182189
tornado.ioloop.IOLoop.instance().start()
183190
184191
This class is intended to let other frameworks (Django, web.py, etc)
185-
run on the Tornado HTTP server and I/O loop. It has not yet been
186-
thoroughly tested in production.
192+
run on the Tornado HTTP server and I/O loop.
193+
194+
The `tornado.web.FallbackHandler` class is often useful for mixing
195+
Tornado and WSGI apps in the same server. See
196+
https://github.com/bdarnell/django-tornado-demo for a complete example.
187197
"""
188198
def __init__(self, wsgi_application):
189199
self.wsgi_application = wsgi_application

website/sphinx/auth.rst

Lines changed: 39 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,4 +2,42 @@
22
============================================================
33

44
.. automodule:: tornado.auth
5-
:members:
5+
6+
Common protocols
7+
----------------
8+
9+
.. autoclass:: OpenIdMixin
10+
:members:
11+
12+
.. autoclass:: OAuthMixin
13+
:members:
14+
15+
.. autoclass:: OAuth2Mixin
16+
:members:
17+
18+
Twitter
19+
-------
20+
21+
.. autoclass:: TwitterMixin
22+
:members:
23+
24+
FriendFeed
25+
----------
26+
27+
.. autoclass:: FriendFeedMixin
28+
:members:
29+
30+
Google
31+
------
32+
33+
.. autoclass:: GoogleMixin
34+
:members:
35+
36+
Facebook
37+
--------
38+
39+
.. autoclass:: FacebookMixin
40+
:members:
41+
42+
.. autoclass:: FacebookGraphMixin
43+
:members:

website/sphinx/testing.rst

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,4 +2,23 @@
22
==================================================================
33

44
.. automodule:: tornado.testing
5-
:members:
5+
6+
Asynchronous test cases
7+
-----------------------
8+
9+
.. autoclass:: AsyncTestCase
10+
:members:
11+
12+
.. autoclass:: AsyncHTTPTestCase
13+
:members:
14+
15+
Controlling log output
16+
----------------------
17+
18+
.. autoclass:: LogTrapTestCase
19+
:members:
20+
21+
Test runner
22+
-----------
23+
24+
.. autofunction:: main

website/sphinx/wsgi.rst

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,4 +2,18 @@
22
==============================================================================
33

44
.. automodule:: tornado.wsgi
5-
:members:
5+
6+
WSGIApplication
7+
---------------
8+
9+
.. autoclass:: WSGIApplication
10+
:members:
11+
12+
.. autoclass:: HTTPRequest
13+
:members:
14+
15+
WSGIContainer
16+
-------------
17+
18+
.. autoclass:: WSGIContainer
19+
:members:

0 commit comments

Comments
 (0)