ioloop.IOLoop.READ)
def stop(self):
+ """Stops listening for new connections.
+
+ Requests currently in progress may still continue after the
+ server is stopped.
+ """
for fd, sock in self._sockets.iteritems():
self.io_loop.remove_handler(fd)
sock.close()
self.stream.read_until(b("\r\n\r\n"), self._header_callback)
def write(self, chunk):
+ """Writes a chunk of output to the stream."""
assert self._request, "Request closed"
if not self.stream.closed():
self.stream.write(chunk, self._on_write_complete)
def finish(self):
+ """Finishes the request."""
assert self._request, "Request closed"
self._request_finished = True
if not self.stream.writing():
@classmethod
def initialized(cls):
+ """Returns true if the singleton instance has been created."""
return hasattr(cls, "_instance")
def add_handler(self, fd, handler, events):
"""Schedules the given callback to be called periodically.
The callback is called every callback_time milliseconds.
+
+ `start` must be called after the PeriodicCallback is created.
"""
def __init__(self, callback, callback_time, io_loop=None):
self.callback = callback
self._running = False
def start(self):
+ """Starts the timer."""
self._running = True
timeout = time.time() + self.callback_time / 1000.0
self.io_loop.add_timeout(timeout, self._run)
def stop(self):
+ """Stops the timer."""
self._running = False
def _run(self):
return bool(self._write_buffer)
def closed(self):
+ """Returns true if the stream has been closed."""
return self.socket is None
def _handle_events(self, fd, events):
class Locale(object):
+ """Object representing a locale.
+
+ After calling one of `load_translations` or `load_gettext_translations`,
+ call `get` or `get_closest` to get a Locale object.
+ """
@classmethod
def get_closest(cls, *locale_codes):
"""Returns the closest match for the given locale code."""
_("Friday"), _("Saturday"), _("Sunday")]
def translate(self, message, plural_message=None, count=None):
+ """Returns the translation for the given message for this locale.
+
+ If plural_message is given, you must also provide count. We return
+ plural_message when count != 1, and we return the singular form
+ for the given message when count == 1.
+ """
raise NotImplementedError()
def format_date(self, date, gmt_offset=0, relative=True, shorter=False,
class CSVLocale(Locale):
"""Locale implementation using tornado's CSV translation format."""
def translate(self, message, plural_message=None, count=None):
- """Returns the translation for the given message for this locale.
-
- If plural_message is given, you must also provide count. We return
- plural_message when count != 1, and we return the singular form
- for the given message when count == 1.
- """
if plural_message is not None:
assert count is not None
if count != 1:
class Error(Exception):
+ """Exception raised by errors in the options module."""
pass
class BaseLoader(object):
+ """Base class for template loaders."""
def __init__(self, root_directory, autoescape=_DEFAULT_AUTOESCAPE):
"""Creates a template loader.
self.templates = {}
def reset(self):
+ """Resets the cache of compiled templates."""
self.templates = {}
def resolve_path(self, name, parent_path=None):
+ """Converts a possibly-relative path to absolute (used internally)."""
if parent_path and not parent_path.startswith("<") and \
not parent_path.startswith("/") and \
not name.startswith("/"):
return name
def load(self, name, parent_path=None):
+ """Loads a template."""
name = self.resolve_path(name, parent_path=parent_path)
if name not in self.templates:
self.templates[name] = self._create_template(name)
"application to use %s" % (name, feature))
def reverse_url(self, name, *args):
+ """Alias for `Application.reverse_url`."""
return self.application.reverse_url(name, *args)
def compute_etag(self):
self.locale = handler.locale
def render(self, *args, **kwargs):
+ """Overridden in subclasses to return this module's output."""
raise NotImplementedError()
def embedded_javascript(self):
return None
def render_string(self, path, **kwargs):
+ """Renders a template and returns it as a string."""
return self.handler.render_string(path, **kwargs)
class _linkify(UIModule):
@staticmethod
def environ(request):
+ """Converts a `tornado.httpserver.HTTPRequest` to a WSGI environment.
+ """
hostport = request.host.split(":")
if len(hostport) == 2:
host = hostport[0]
"TemplateModule",
"url",
]
+
+coverage_ignore_functions = [
+ # various modules
+ "doctests",
+ "main",
+]
html_static_path = [os.path.abspath("../static")]
html_style = "sphinx.css"
HTTP Server
-----------
.. autoclass:: HTTPServer
+ :members:
+
.. autoclass:: HTTPConnection
+ :members:
^^^^^^^^^^^^^^^^^
.. automethod:: IOLoop.instance
+ .. automethod:: IOLoop.initialized
.. automethod:: IOLoop.start
.. automethod:: IOLoop.stop
.. automethod:: IOLoop.running
.. automethod:: IOLoop.add_timeout
.. automethod:: IOLoop.remove_timeout
.. autoclass:: PeriodicCallback
+ :members:
Debugging and error handling
^^^^^^^^^^^^^^^^^^^^^^^^^^^^
-----------
.. autofunction:: main
+
+ Helper functions
+ ----------------
+
+ .. autofunction:: get_unused_port
.. automethod:: RequestHandler.get_user_locale
.. automethod:: RequestHandler.on_connection_close
.. automethod:: RequestHandler.require_setting
+ .. automethod:: RequestHandler.reverse_url
.. autoattribute:: RequestHandler.settings
.. automethod:: RequestHandler.static_url
.. automethod:: RequestHandler.xsrf_form_html