Skip to content

Commit

Permalink
Merge pull request tornadoweb#1336 from grafuls/master
Browse files Browse the repository at this point in the history
flake8 cleanup
  • Loading branch information
bdarnell committed Feb 12, 2015
2 parents 1188c01 + a8687da commit 3506191
Showing 1 changed file with 43 additions and 21 deletions.
64 changes: 43 additions & 21 deletions tornado/web.py
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,8 @@ def get(self):
"""

from __future__ import absolute_import, division, print_function, with_statement
from __future__ import (absolute_import, division,
print_function, with_statement)


import base64
Expand Down Expand Up @@ -90,7 +91,8 @@ def get(self):
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


Expand Down Expand Up @@ -406,7 +408,8 @@ def get_body_argument(self, name, default=_ARG_DEFAULT, strip=True):
.. 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.
Expand All @@ -433,7 +436,8 @@ def get_query_argument(self, name, default=_ARG_DEFAULT, strip=True):
.. 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.
Expand Down Expand Up @@ -488,7 +492,8 @@ def decode_argument(self, value, name=None):

@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):
Expand Down Expand Up @@ -664,7 +669,8 @@ def write(self, chunk):
"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")
Expand Down Expand Up @@ -841,7 +847,8 @@ def flush(self, include_footers=False, callback=None):
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
Expand Down Expand Up @@ -1161,7 +1168,8 @@ def _decode_xsrf_token(self, cookie):
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):
Expand Down Expand Up @@ -1856,7 +1864,8 @@ def __init__(self, application, connection):

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()
Expand All @@ -1873,7 +1882,9 @@ def _find_handler(self):
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)
Expand Down Expand Up @@ -1944,7 +1955,8 @@ def execute(self):
# 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,
Expand Down Expand Up @@ -2239,7 +2251,8 @@ def set_headers(self):
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))
Expand Down Expand Up @@ -2408,7 +2421,8 @@ def get_modified_time(self):
.. 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):
Expand Down Expand Up @@ -2669,7 +2683,8 @@ def render(self, *args, **kwargs):
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):
Expand All @@ -2681,7 +2696,8 @@ 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):
Expand Down Expand Up @@ -2924,7 +2940,8 @@ def create_signed_value(secret, name, value, version=None, clock=None):
#
# 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)
Expand All @@ -2942,11 +2959,13 @@ def format_field(s):
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:
Expand Down Expand Up @@ -2980,9 +2999,11 @@ def decode_signed_value(secret, name, value, max_age_days=31, clock=None, min_ve
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

Expand All @@ -3005,7 +3026,8 @@ def _decode_signed_value_v1(secret, name, value, max_age_days, clock):
# 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)
Expand Down

0 comments on commit 3506191

Please sign in to comment.