author_email="python-tornado@googlegroups.com",
url="http://www.tornadoweb.org/",
license="http://www.apache.org/licenses/LICENSE-2.0",
- description="Tornado is a Python web framework and asynchronous networking library, originally developed at FriendFeed.",
+ description=("Tornado is a Python web framework and asynchronous networking library,"
+ " originally developed at FriendFeed."),
classifiers=[
'License :: OSI Approved :: Apache Software License',
'Programming Language :: Python :: 2',
"Missing OAuth request token cookie"))
return
self.clear_cookie("_oauth_request_token")
- cookie_key, cookie_secret = [base64.b64decode(escape.utf8(i)) for i in request_cookie.split("|")]
+ cookie_key, cookie_secret = [
+ base64.b64decode(escape.utf8(i)) for i in request_cookie.split("|")]
if cookie_key != request_key:
future.set_exception(AuthError(
"Request token does not match cookie"))
.. testoutput::
:hide:
- """
+ """ # noqa: E501
http = self.get_auth_http_client()
body = urllib_parse.urlencode({
"redirect_uri": redirect_uri,
http.fetch(self._OAUTH_ACCESS_TOKEN_URL,
functools.partial(self._on_access_token, callback),
- method="POST", headers={'Content-Type': 'application/x-www-form-urlencoded'}, body=body)
+ method="POST",
+ headers={'Content-Type': 'application/x-www-form-urlencoded'},
+ body=body)
def _on_access_token(self, future, response):
"""Callback function for the exchange to the access token."""
Tornado it will change from a string to an integer.
* ``id``, ``name``, ``first_name``, ``last_name``, ``locale``, ``picture``,
``link``, plus any fields named in the ``extra_fields`` argument. These
- fields are copied from the Facebook graph API `user object <https://developers.facebook.com/docs/graph-api/reference/user>`_
+ fields are copied from the Facebook graph API
+ `user object <https://developers.facebook.com/docs/graph-api/reference/user>`_
.. versionchanged:: 4.5
The ``session_expires`` field was updated to support changes made to the
# This regex should avoid those problems.
# Use to_unicode instead of tornado.util.u - we don't want backslashes getting
# processed as escapes.
-_URL_RE = re.compile(to_unicode(r"""\b((?:([\w-]+):(/{1,3})|www[.])(?:(?:(?:[^\s&()]|&|")*(?:[^!"#$%&'()*+,.:;<=>?@\[\]^`{|}~\s]))|(?:\((?:[^\s&()]|&|")*\)))+)"""))
+_URL_RE = re.compile(to_unicode(
+ r"""\b((?:([\w-]+):(/{1,3})|www[.])(?:(?:(?:[^\s&()]|&|")*(?:[^!"#$%&'()*+,.:;<=>?@\[\]^`{|}~\s]))|(?:\((?:[^\s&()]|&|")*\)))+)""" # noqa: E501
+))
def linkify(text, shorten=False, extra_params="",
import traceback
import math
-from tornado.concurrent import Future, is_future, chain_future, future_set_exc_info, future_add_done_callback
+from tornado.concurrent import Future, is_future, chain_future, future_set_exc_info, future_add_done_callback # noqa: E501
from tornado.log import app_log, gen_log
from tornado.platform.auto import set_close_exec, Waker
from tornado import stack_context
-from tornado.util import PY3, Configurable, errno_from_exception, timedelta_to_seconds, TimeoutError, unicode_type, import_object
+from tornado.util import (
+ PY3, Configurable, errno_from_exception, timedelta_to_seconds,
+ TimeoutError, unicode_type, import_object,
+)
try:
import signal
errno.ETIMEDOUT)
if hasattr(errno, "WSAECONNRESET"):
- _ERRNO_CONNRESET += (errno.WSAECONNRESET, errno.WSAECONNABORTED, errno.WSAETIMEDOUT) # type: ignore
+ _ERRNO_CONNRESET += (errno.WSAECONNRESET, errno.WSAECONNABORTED, errno.WSAETIMEDOUT) # type: ignore # noqa: E501
if sys.platform == 'darwin':
# OSX appears to have a race condition that causes send(2) to return
Added support for ``colorama``. Changed the constructor
signature to be compatible with `logging.config.dictConfig`.
"""
- DEFAULT_FORMAT = '%(color)s[%(levelname)1.1s %(asctime)s %(module)s:%(lineno)d]%(end_color)s %(message)s'
+ DEFAULT_FORMAT = \
+ '%(color)s[%(levelname)1.1s %(asctime)s %(module)s:%(lineno)d]%(end_color)s %(message)s'
DEFAULT_DATE_FORMAT = '%y%m%d %H:%M:%S'
DEFAULT_COLORS = {
logging.DEBUG: 4, # Blue
import twisted.internet.abstract # type: ignore
from twisted.internet.defer import Deferred # type: ignore
from twisted.internet.posixbase import PosixReactorBase # type: ignore
-from twisted.internet.interfaces import IReactorFDSet, IDelayedCall, IReactorTime, IReadDescriptor, IWriteDescriptor # type: ignore
+from twisted.internet.interfaces import IReactorFDSet, IDelayedCall, IReactorTime, IReadDescriptor, IWriteDescriptor # type: ignore # noqa: E501
from twisted.python import failure, log # type: ignore
from twisted.internet import error # type: ignore
import twisted.names.cache # type: ignore
# See: http://msdn.microsoft.com/en-us/library/ms724935(VS.85).aspx
SetHandleInformation = ctypes.windll.kernel32.SetHandleInformation
-SetHandleInformation.argtypes = (ctypes.wintypes.HANDLE, ctypes.wintypes.DWORD, ctypes.wintypes.DWORD)
+SetHandleInformation.argtypes = (ctypes.wintypes.HANDLE, ctypes.wintypes.DWORD, ctypes.wintypes.DWORD) # noqa: E501
SetHandleInformation.restype = ctypes.wintypes.BOOL
HANDLE_FLAG_INHERIT = 0x00000001
])
In the examples above, ``Target`` can be a nested `Router` instance, an instance of
- `~.httputil.HTTPServerConnectionDelegate` or an old-style callable, accepting a request argument.
+ `~.httputil.HTTPServerConnectionDelegate` or an old-style callable,
+ accepting a request argument.
:arg rules: a list of `Rule` instances or tuples of `Rule`
constructor arguments.
:arg str template_string: the contents of the template file.
:arg str name: the filename from which the template was loaded
(used for error message).
- :arg tornado.template.BaseLoader loader: the `~tornado.template.BaseLoader` responsible for this template,
- used to resolve ``{% include %}`` and ``{% extend %}``
- directives.
+ :arg tornado.template.BaseLoader loader: the `~tornado.template.BaseLoader` responsible
+ for this template, used to resolve ``{% include %}`` and ``{% extend %}`` directives.
:arg bool compress_whitespace: Deprecated since Tornado 4.3.
Equivalent to ``whitespace="single"`` if true and
``whitespace="all"`` if false.
except Exception:
self.__failure = sys.exc_info()
self.stop()
- self.__timeout = self.io_loop.add_timeout(self.io_loop.time() + timeout, timeout_func)
+ self.__timeout = self.io_loop.add_timeout(self.io_loop.time() + timeout,
+ timeout_func)
while True:
self.__running = True
self.io_loop.start()
By default includes a self-signed testing certificate.
"""
# Testing keys were generated with:
- # openssl req -new -keyout tornado/test/test.key -out tornado/test/test.crt -nodes -days 3650 -x509
+ # openssl req -new -keyout tornado/test/test.key \
+ # -out tornado/test/test.crt -nodes -days 3650 -x509
module_dir = os.path.dirname(__file__)
return dict(
certfile=os.path.join(module_dir, 'test', 'test.crt'),
if not isinstance(chunk, (bytes, unicode_type, dict)):
message = "write() only accepts bytes, unicode, and dict objects"
if isinstance(chunk, list):
- message += ". Lists not accepted for security reasons; see http://www.tornadoweb.org/en/stable/web.html#tornado.web.RequestHandler.write"
+ message += ". Lists not accepted for security reasons; see " + \
+ "http://www.tornadoweb.org/en/stable/web.html#tornado.web.RequestHandler.write"
raise TypeError(message)
if isinstance(chunk, dict):
chunk = escape.json_encode(chunk)
See the `file receiver demo <https://github.com/tornadoweb/tornado/tree/master/demos/file_upload/>`_
for example usage.
- """
+ """ # noqa: E501
if not issubclass(cls, RequestHandler):
raise TypeError("expected subclass of RequestHandler, got %r", cls)
cls._stream_request_body = True
pass
def transform_first_chunk(self, status_code, headers, chunk, finishing):
- # type: (int, httputil.HTTPHeaders, bytes, bool) -> typing.Tuple[int, httputil.HTTPHeaders, bytes]
+ # type: (int, httputil.HTTPHeaders, bytes, bool) -> typing.Tuple[int, httputil.HTTPHeaders, bytes] # noqa: E501
return status_code, headers, chunk
def transform_chunk(self, chunk, finishing):
return ctype.startswith('text/') or ctype in self.CONTENT_TYPES
def transform_first_chunk(self, status_code, headers, chunk, finishing):
- # type: (int, httputil.HTTPHeaders, bytes, bool) -> typing.Tuple[int, httputil.HTTPHeaders, bytes]
+ # type: (int, httputil.HTTPHeaders, bytes, bool) -> typing.Tuple[int, httputil.HTTPHeaders, bytes] # noqa: E501
# TODO: can/should this type be inherited from the superclass?
if 'Vary' in headers:
headers['Vary'] += ', Accept-Encoding'
self._compressor = None
def _create_compressor(self):
- return zlib.compressobj(self._compression_level, zlib.DEFLATED, -self._max_wbits, self._mem_level)
+ return zlib.compressobj(self._compression_level,
+ zlib.DEFLATED, -self._max_wbits, self._mem_level)
def compress(self, data):
compressor = self._compressor or self._create_compressor()