Hello <a href="http://tornadoweb.org">http://tornadoweb.org</a>!
Parameters:
+
shorten: Long urls will be shortened for display.
+
extra_params: Extra text to include in the link tag,
e.g. linkify(text, extra_params='rel="nofollow" class="external"')
+
require_protocol: Only linkify urls which include a protocol. If this is
False, urls such as www.facebook.com will also be linkified.
+
permitted_protocols: List (or set) of protocols which should be linkified,
e.g. linkify(text, permitted_protocols=["http", "ftp", "mailto"]).
It is very unsafe to include protocols such as "javascript".
class HTTPClient(object):
"""A blocking HTTP client.
- Typical usage looks like this:
+ Typical usage looks like this::
http_client = httpclient.HTTPClient()
try:
class AsyncHTTPClient(object):
"""An non-blocking HTTP client.
- Example usage:
+ Example usage::
import ioloop
"""HTTP Response object.
Attributes:
+
* request: HTTPRequest object
+
* code: numeric HTTP status code, e.g. 200 or 404
+
* headers: httputil.HTTPHeaders object
+
* buffer: cStringIO object for response body
+
* body: respose body as string (created on demand from self.buffer)
+
* error: Exception object, if any
+
* request_time: seconds from request start to finish
+
* time_info: dictionary of diagnostic timing information from the request.
Available data are subject to change, but currently uses timings
available from http://curl.haxx.se/libcurl/c/curl_easy_getinfo.html,
"""Exception thrown for an unsuccessful HTTP request.
Attributes:
+
code - HTTP error integer error code, e.g. 404. Error code 599 is
used when no HTTP response was received, e.g. for a timeout.
+
response - HTTPResponse object, if any.
Note that if follow_redirects is False, redirects become HTTPErrors,
class HTTPServer(object):
- """A non-blocking, single-threaded HTTP server.
+ r"""A non-blocking, single-threaded HTTP server.
A server is defined by a request callback that takes an HTTPRequest
instance as an argument and writes a valid HTTP response with
request.write(). request.finish() finishes the request (but does not
necessarily close the connection in the case of HTTP/1.1 keep-alive
requests). A simple example server that echoes back the URI you
- requested:
+ requested::
import httpserver
import ioloop
HTTPServer can serve HTTPS (SSL) traffic with Python 2.6+ and OpenSSL.
To make this server serve SSL traffic, send the ssl_options dictionary
argument with the arguments required for the ssl.wrap_socket() method,
- including "certfile" and "keyfile":
+ including "certfile" and "keyfile"::
HTTPServer(applicaton, ssl_options={
"certfile": os.path.join(data_dir, "mydomain.crt"),
By default, listen() runs in a single thread in a single process. You
can utilize all available CPUs on this machine by calling bind() and
- start() instead of listen():
+ start() instead of listen()::
http_server = httpserver.HTTPServer(handle_request)
http_server.bind(8888)
"""Returns the client's SSL certificate, if any.
To use client certificates, the HTTPServer must have been constructed
- with cert_reqs set in ssl_options, e.g.:
+ with cert_reqs set in ssl_options, e.g.::
+
server = HTTPServer(app,
ssl_options=dict(
certfile="foo.crt",
connections, you should use Linux and either compile our epoll module or
use Python 2.6+ to get epoll support.
- Example usage for a simple TCP server:
+ Example usage for a simple TCP server::
import errno
import functools
A common pattern for classes that depend on IOLoops is to use
a default argument to enable programs with multiple IOLoops
- but not require the argument for simpler applications:
+ but not require the argument for simpler applications::
class MyClass(object):
def __init__(self, io_loop=None):
will return immediately.
To use asynchronous methods from otherwise-synchronous code (such as
- unit tests), you can start and stop the event loop like this:
+ unit tests), you can start and stop the event loop like this::
+
ioloop = IOLoop()
async_method(ioloop=ioloop, callback=ioloop.stop)
ioloop.start()
+
ioloop.start() will return after async_method has run its callback,
whether that callback was invoked before or after ioloop.start.
"""
ssl = None
class IOStream(object):
- """A utility class to write to and read from a non-blocking socket.
+ r"""A utility class to write to and read from a non-blocking socket.
We support three methods: write(), read_until(), and read_bytes().
All of the methods take callbacks (since writing and reading are
and may either be connected before passing it to the IOStream or
connected with IOStream.connect.
- A very simple (and broken) HTTP client using this class:
+ A very simple (and broken) HTTP client using this class::
from tornado import ioloop
from tornado import iostream
"""Translation methods for generating localized strings.
-To load a locale and generate a translated string:
+To load a locale and generate a translated string::
user_locale = locale.get("es_LA")
print user_locale.translate("Sign out")
locale.get() returns the closest matching locale, not necessarily the
specific locale you requested. You can support pluralization with
-additional arguments to translate(), e.g.:
+additional arguments to translate(), e.g.::
people = [...]
message = user_locale.translate(
"""A simple template system that compiles templates to Python code.
-Basic usage looks like:
+Basic usage looks like::
t = template.Template("<html>{{ myvalue }}</html>")
print t.generate(myvalue="XXX")
Loader is a class that loads templates from a root directory and caches
-the compiled templates:
+the compiled templates::
loader = template.Loader("/home/btaylor")
print loader.load("test.html").generate(myvalue="XXX")
We compile all templates to raw Python. Error-reporting is currently... uh,
-interesting. Syntax for the templates
+interesting. Syntax for the templates::
### base.html
<html>
Unlike most other template systems, we do not put any restrictions on the
expressions you can include in your statements. if and for blocks get
-translated exactly into Python, do you can do complex expressions like:
+translated exactly into Python, do you can do complex expressions like::
{% for student in [p for p in people if p.student and p.age > 23] %}
<li>{{ escape(student.name) }}</li>
Translating directly to Python means you can apply functions to expressions
easily, like the escape() function in the examples above. You can pass
-functions in to your template just like any other variable:
+functions in to your template just like any other variable::
### Python code
def add(x, y):
======================
.. automodule:: tornado.escape
+ :members:
======================
.. automodule:: tornado.httpclient
+ :members:
======================
.. automodule:: tornado.httpserver
+ :members:
======================
.. automodule:: tornado.ioloop
+ :members:
======================
.. automodule:: tornado.iostream
+ :members:
======================
.. automodule:: tornado.locale
+ :members:
======================
.. automodule:: tornado.template
+ :members: