"""
-from __future__ import absolute_import, division, print_function, with_statement
+from __future__ import (absolute_import, division,
+ print_function, with_statement)
import base64
from tornado import stack_context
from tornado import template
from tornado.escape import utf8, _unicode
-from tornado.util import import_object, ObjectDict, raise_exc_info, unicode_type, _websocket_mask
+from tornado.util import (import_object, ObjectDict, raise_exc_info,
+ unicode_type, _websocket_mask)
from tornado.httputil import split_host_and_port
.. versionadded:: 3.2
"""
- return self._get_argument(name, default, self.request.body_arguments, strip)
+ return self._get_argument(name, default, self.request.body_arguments,
+ strip)
def get_body_arguments(self, name, strip=True):
"""Returns a list of the body arguments with the given name.
.. versionadded:: 3.2
"""
- return self._get_argument(name, default, self.request.query_arguments, strip)
+ return self._get_argument(name, default,
+ self.request.query_arguments, strip)
def get_query_arguments(self, name, strip=True):
"""Returns a list of the query arguments with the given name.
@property
def cookies(self):
- """An alias for `self.request.cookies <.httputil.HTTPServerRequest.cookies>`."""
+ """An alias for
+ `self.request.cookies <.httputil.HTTPServerRequest.cookies>`."""
return self.request.cookies
def get_cookie(self, name, default=None):
"by using async operations without the "
"@asynchronous decorator.")
if not isinstance(chunk, (bytes, unicode_type, dict)):
- raise TypeError("write() only accepts bytes, unicode, and dict objects")
+ raise TypeError(
+ "write() only accepts bytes, unicode, and dict objects")
if isinstance(chunk, dict):
chunk = escape.json_encode(chunk)
self.set_header("Content-Type", "application/json; charset=UTF-8")
for transform in self._transforms:
self._status_code, self._headers, chunk = \
transform.transform_first_chunk(
- self._status_code, self._headers, chunk, include_footers)
+ self._status_code, self._headers,
+ chunk, include_footers)
# Ignore the chunk and only write the headers for HEAD requests
if self.request.method == "HEAD":
chunk = None
return (version, token, timestamp)
except Exception:
# Catch exceptions and return nothing instead of failing.
- gen_log.debug("Uncaught exception in _decode_xsrf_token", exc_info=True)
+ gen_log.debug("Uncaught exception in _decode_xsrf_token",
+ exc_info=True)
return None, None, None
def check_xsrf_cookie(self):
def headers_received(self, start_line, headers):
self.set_request(httputil.HTTPServerRequest(
- connection=self.connection, start_line=start_line, headers=headers))
+ connection=self.connection, start_line=start_line,
+ headers=headers))
if self.stream_request_body:
self.request.body = Future()
return self.execute()
handlers = app._get_host_handlers(self.request)
if not handlers:
self.handler_class = RedirectHandler
- self.handler_kwargs = dict(url="%s://%s/" % (self.request.protocol, app.default_host))
+ self.handler_kwargs = dict(url="%s://%s/"
+ % (self.request.protocol,
+ app.default_host))
return
for spec in handlers:
match = spec.regex.match(self.request.path)
# except handler, and we cannot easily access the IOLoop here to
# call add_future (because of the requirement to remain compatible
# with WSGI)
- f = self.handler._execute(transforms, *self.path_args, **self.path_kwargs)
+ f = self.handler._execute(transforms, *self.path_args,
+ **self.path_kwargs)
f.add_done_callback(lambda f: f.exception())
# If we are streaming the request body, then execute() is finished
# when the handler has prepared to receive the body. If not,
if content_type:
self.set_header("Content-Type", content_type)
- cache_time = self.get_cache_time(self.path, self.modified, content_type)
+ cache_time = self.get_cache_time(self.path, self.modified,
+ content_type)
if cache_time > 0:
self.set_header("Expires", datetime.datetime.utcnow() +
datetime.timedelta(seconds=cache_time))
.. versionadded:: 3.1
"""
stat_result = self._stat()
- modified = datetime.datetime.utcfromtimestamp(stat_result[stat.ST_MTIME])
+ modified = datetime.datetime.utcfromtimestamp(
+ stat_result[stat.ST_MTIME])
return modified
def get_content_type(self):
raise NotImplementedError()
def embedded_javascript(self):
- """Override to return a JavaScript string to be embedded in the page."""
+ """Override to return a JavaScript string
+ to be embedded in the page."""
return None
def javascript_files(self):
return None
def embedded_css(self):
- """Override to return a CSS string that will be embedded in the page."""
+ """Override to return a CSS string
+ that will be embedded in the page."""
return None
def css_files(self):
#
# The fields are:
# - format version (i.e. 2; no length prefix)
- # - key version (currently 0; reserved for future key rotation features)
+ # - key version (currently 0; reserved for future
+ # key rotation features)
# - timestamp (integer seconds since epoch)
# - name (not encoded; assumed to be ~alphanumeric)
# - value (base64-encoded)
else:
raise ValueError("Unsupported version %d" % version)
-# A leading version number in decimal with no leading zeros, followed by a pipe.
+# A leading version number in decimal
+# with no leading zeros, followed by a pipe.
_signed_value_version_re = re.compile(br"^([1-9][0-9]*)\|(.*)$")
-def decode_signed_value(secret, name, value, max_age_days=31, clock=None, min_version=None):
+def decode_signed_value(secret, name, value, max_age_days=31,
+ clock=None, min_version=None):
if clock is None:
clock = time.time
if min_version is None:
if version < min_version:
return None
if version == 1:
- return _decode_signed_value_v1(secret, name, value, max_age_days, clock)
+ return _decode_signed_value_v1(secret, name, value,
+ max_age_days, clock)
elif version == 2:
- return _decode_signed_value_v2(secret, name, value, max_age_days, clock)
+ return _decode_signed_value_v2(secret, name, value,
+ max_age_days, clock)
else:
return None
# digits from the payload to the timestamp without altering the
# signature. For backwards compatibility, sanity-check timestamp
# here instead of modifying _cookie_signature.
- gen_log.warning("Cookie timestamp in future; possible tampering %r", value)
+ gen_log.warning("Cookie timestamp in future; possible tampering %r",
+ value)
return None
if parts[1].startswith(b"0"):
gen_log.warning("Tampered cookie %r", value)