from __future__ import absolute_import, division, print_function
-from tornado.auth import OpenIdMixin, OAuthMixin, OAuth2Mixin, TwitterMixin, AuthError, GoogleOAuth2Mixin, FacebookGraphMixin
+
+from tornado.auth import (
+ AuthError, OpenIdMixin, OAuthMixin, OAuth2Mixin,
+ GoogleOAuth2Mixin, FacebookGraphMixin, TwitterMixin,
+)
from tornado.concurrent import Future
from tornado.escape import json_decode
from tornado import gen
('/facebook/client/login', FacebookClientLoginHandler, dict(test=self)),
('/twitter/client/login', TwitterClientLoginHandler, dict(test=self)),
- ('/twitter/client/login_gen_engine', TwitterClientLoginGenEngineHandler, dict(test=self)),
- ('/twitter/client/login_gen_coroutine', TwitterClientLoginGenCoroutineHandler, dict(test=self)),
- ('/twitter/client/show_user', TwitterClientShowUserHandler, dict(test=self)),
- ('/twitter/client/show_user_future', TwitterClientShowUserFutureHandler, dict(test=self)),
+ ('/twitter/client/login_gen_engine',
+ TwitterClientLoginGenEngineHandler, dict(test=self)),
+ ('/twitter/client/login_gen_coroutine',
+ TwitterClientLoginGenCoroutineHandler, dict(test=self)),
+ ('/twitter/client/show_user',
+ TwitterClientShowUserHandler, dict(test=self)),
+ ('/twitter/client/show_user_future',
+ TwitterClientShowUserFutureHandler, dict(test=self)),
# simulated servers
('/openid/server/authenticate', OpenIdServerAuthenticateHandler),
('/facebook/server/me', FacebookServerMeHandler),
('/twitter/server/access_token', TwitterServerAccessTokenHandler),
(r'/twitter/api/users/show/(.*)\.json', TwitterServerShowUserHandler),
- (r'/twitter/api/account/verify_credentials\.json', TwitterServerVerifyCredentialsHandler),
+ (r'/twitter/api/account/verify_credentials\.json',
+ TwitterServerVerifyCredentialsHandler),
],
http_client=self.http_client,
twitter_consumer_key='test_twitter_consumer_key',
'/openid/server/authenticate?' in response.headers['Location'])
def test_openid_get_user(self):
- response = self.fetch('/openid/client/login?openid.mode=blah&openid.ns.ax=http://openid.net/srv/ax/1.0&openid.ax.type.email=http://axschema.org/contact/email&openid.ax.value.email=foo@example.com')
+ response = self.fetch('/openid/client/login?openid.mode=blah'
+ '&openid.ns.ax=http://openid.net/srv/ax/1.0'
+ '&openid.ax.type.email=http://axschema.org/contact/email'
+ '&openid.ax.value.email=foo@example.com')
response.rethrow()
parsed = json_decode(response.body)
self.assertEqual(parsed["email"], "foo@example.com")
from __future__ import absolute_import, division, print_function
import tornado.escape
-from tornado.escape import utf8, xhtml_escape, xhtml_unescape, url_escape, url_unescape, to_unicode, json_decode, json_encode, squeeze, recursive_unicode
+from tornado.escape import (
+ utf8, xhtml_escape, xhtml_unescape, url_escape, url_unescape,
+ to_unicode, json_decode, json_encode, squeeze, recursive_unicode,
+)
from tornado.util import unicode_type
from tornado.test.util import unittest
u'hello <a href="http://world.com/">http://world.com/</a>!'),
("hello http://world.com/with?param=true&stuff=yes", {},
- u'hello <a href="http://world.com/with?param=true&stuff=yes">http://world.com/with?param=true&stuff=yes</a>'),
+ u'hello <a href="http://world.com/with?param=true&stuff=yes">http://world.com/with?param=true&stuff=yes</a>'), # noqa: E501
# an opened paren followed by many chars killed Gruber's regex
("http://url.com/w(aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa", {},
- u'<a href="http://url.com/w">http://url.com/w</a>(aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa'),
+ u'<a href="http://url.com/w">http://url.com/w</a>(aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa'), # noqa: E501
# as did too many dots at the end
("http://url.com/withmany.......................................", {},
- u'<a href="http://url.com/withmany">http://url.com/withmany</a>.......................................'),
+ u'<a href="http://url.com/withmany">http://url.com/withmany</a>.......................................'), # noqa: E501
("http://url.com/withmany((((((((((((((((((((((((((((((((((a)", {},
- u'<a href="http://url.com/withmany">http://url.com/withmany</a>((((((((((((((((((((((((((((((((((a)'),
+ u'<a href="http://url.com/withmany">http://url.com/withmany</a>((((((((((((((((((((((((((((((((((a)'), # noqa: E501
# some examples from http://daringfireball.net/2009/11/liberal_regex_for_matching_urls
# plus a fex extras (such as multiple parentheses).
u'<a href="http://foo.com/blah_blah_(wikipedia)">http://foo.com/blah_blah_(wikipedia)</a>'),
("http://foo.com/blah_(blah)_(wikipedia)_blah", {},
- u'<a href="http://foo.com/blah_(blah)_(wikipedia)_blah">http://foo.com/blah_(blah)_(wikipedia)_blah</a>'),
+ u'<a href="http://foo.com/blah_(blah)_(wikipedia)_blah">http://foo.com/blah_(blah)_(wikipedia)_blah</a>'), # noqa: E501
("(Something like http://foo.com/blah_blah_(wikipedia))", {},
- u'(Something like <a href="http://foo.com/blah_blah_(wikipedia)">http://foo.com/blah_blah_(wikipedia)</a>)'),
+ u'(Something like <a href="http://foo.com/blah_blah_(wikipedia)">http://foo.com/blah_blah_(wikipedia)</a>)'), # noqa: E501
("http://foo.com/blah_blah.", {},
u'<a href="http://foo.com/blah_blah">http://foo.com/blah_blah</a>.'),
u'<a href="rdar:/1234">rdar:/1234</a>'),
("http://userid:password@example.com:8080", {},
- u'<a href="http://userid:password@example.com:8080">http://userid:password@example.com:8080</a>'),
+ u'<a href="http://userid:password@example.com:8080">http://userid:password@example.com:8080</a>'), # noqa: E501
("http://userid@example.com", {},
u'<a href="http://userid@example.com">http://userid@example.com</a>'),
("message://%3c330e7f8409726r6a4ba78dkf1fd71420c1bf6ff@mail.gmail.com%3e",
{"permitted_protocols": ["http", "message"]},
- u'<a href="message://%3c330e7f8409726r6a4ba78dkf1fd71420c1bf6ff@mail.gmail.com%3e">message://%3c330e7f8409726r6a4ba78dkf1fd71420c1bf6ff@mail.gmail.com%3e</a>'),
+ u'<a href="message://%3c330e7f8409726r6a4ba78dkf1fd71420c1bf6ff@mail.gmail.com%3e">'
+ u'message://%3c330e7f8409726r6a4ba78dkf1fd71420c1bf6ff@mail.gmail.com%3e</a>'),
(u"http://\u27a1.ws/\u4a39", {},
u'<a href="http://\u27a1.ws/\u4a39">http://\u27a1.ws/\u4a39</a>'),
("A http://reallylong.com/link/that/exceedsthelenglimit.html",
{"require_protocol": True, "shorten": True},
- u'A <a href="http://reallylong.com/link/that/exceedsthelenglimit.html" title="http://reallylong.com/link/that/exceedsthelenglimit.html">http://reallylong.com/link...</a>'),
+ u'A <a href="http://reallylong.com/link/that/exceedsthelenglimit.html"'
+ u' title="http://reallylong.com/link/that/exceedsthelenglimit.html">http://reallylong.com/link...</a>'), # noqa: E501
("A http://reallylongdomainnamethatwillbetoolong.com/hi!",
{"shorten": True},
- u'A <a href="http://reallylongdomainnamethatwillbetoolong.com/hi" title="http://reallylongdomainnamethatwillbetoolong.com/hi">http://reallylongdomainnametha...</a>!'),
+ u'A <a href="http://reallylongdomainnamethatwillbetoolong.com/hi"'
+ u' title="http://reallylongdomainnamethatwillbetoolong.com/hi">http://reallylongdomainnametha...</a>!'), # noqa: E501
("A file:///passwords.txt and http://web.com link", {},
u'A file:///passwords.txt and <a href="http://web.com">http://web.com</a> link'),
("www.external-link.com",
{"extra_params": 'rel="nofollow" class="external"'},
- u'<a href="http://www.external-link.com" rel="nofollow" class="external">www.external-link.com</a>'),
+ u'<a href="http://www.external-link.com" rel="nofollow" class="external">www.external-link.com</a>'), # noqa: E501
("www.external-link.com and www.internal-link.com/blogs extra",
- {"extra_params": lambda href: 'class="internal"' if href.startswith("http://www.internal-link.com") else 'rel="nofollow" class="external"'},
- u'<a href="http://www.external-link.com" rel="nofollow" class="external">www.external-link.com</a> and <a href="http://www.internal-link.com/blogs" class="internal">www.internal-link.com/blogs</a> extra'),
+ {"extra_params": lambda href: 'class="internal"' if href.startswith("http://www.internal-link.com") else 'rel="nofollow" class="external"'}, # noqa: E501
+ u'<a href="http://www.external-link.com" rel="nofollow" class="external">www.external-link.com</a>' # noqa: E501
+ u' and <a href="http://www.internal-link.com/blogs" class="internal">www.internal-link.com/blogs</a> extra'), # noqa: E501
("www.external-link.com",
{"extra_params": lambda href: ' rel="nofollow" class="external" '},
- u'<a href="http://www.external-link.com" rel="nofollow" class="external">www.external-link.com</a>'),
+ u'<a href="http://www.external-link.com" rel="nofollow" class="external">www.external-link.com</a>'), # noqa: E501
]
self.assertRaises(UnicodeDecodeError, json_encode, b"\xe9")
def test_squeeze(self):
- self.assertEqual(squeeze(u'sequences of whitespace chars'), u'sequences of whitespace chars')
+ self.assertEqual(squeeze(u'sequences of whitespace chars'),
+ u'sequences of whitespace chars')
def test_recursive_unicode(self):
tests = {
from tornado.log import app_log
from tornado import stack_context
from tornado.testing import AsyncHTTPTestCase, AsyncTestCase, ExpectLog, gen_test
-from tornado.test.util import unittest, skipOnTravis, skipBefore33, skipBefore35, skipNotCPython, exec_test
+from tornado.test.util import unittest, skipOnTravis, skipBefore33, skipBefore35, skipNotCPython, exec_test # noqa: E501
from tornado.web import Application, RequestHandler, asynchronous, HTTPError
from tornado import gen
from __future__ import absolute_import, division, print_function
+
from tornado import netutil
from tornado.escape import json_decode, json_encode, utf8, _unicode, recursive_unicode, native_str
from tornado import gen
from tornado.http1connection import HTTP1Connection
from tornado.httpserver import HTTPServer
-from tornado.httputil import HTTPHeaders, HTTPMessageDelegate, HTTPServerConnectionDelegate, ResponseStartLine
+from tornado.httputil import HTTPHeaders, HTTPMessageDelegate, HTTPServerConnectionDelegate, ResponseStartLine # noqa: E501
from tornado.iostream import IOStream
from tornado.log import gen_log
from tornado.netutil import ssl_options_to_context
from tornado.simple_httpclient import SimpleAsyncHTTPClient
-from tornado.testing import AsyncHTTPTestCase, AsyncHTTPSTestCase, AsyncTestCase, ExpectLog, gen_test
+from tornado.testing import AsyncHTTPTestCase, AsyncHTTPSTestCase, AsyncTestCase, ExpectLog, gen_test # noqa: E501
from tornado.test.util import unittest, skipOnTravis
from tornado.web import Application, RequestHandler, asynchronous, stream_request_body
+
from contextlib import closing
import datetime
import gzip
from __future__ import absolute_import, division, print_function
-from tornado.httputil import url_concat, parse_multipart_form_data, HTTPHeaders, format_timestamp, HTTPServerRequest, parse_request_start_line, parse_cookie, qs_to_qsl, PY3
+
+from tornado.httputil import (
+ url_concat, parse_multipart_form_data, HTTPHeaders, format_timestamp,
+ HTTPServerRequest, parse_request_start_line, parse_cookie, qs_to_qsl,
+)
from tornado.escape import utf8, native_str
+from tornado.util import PY3
from tornado.log import gen_log
from tornado.testing import ExpectLog
from tornado.test.util import unittest
"""
Test cases copied from Python's Lib/test/test_http_cookies.py
"""
- self.assertEqual(parse_cookie('chips=ahoy; vienna=finger'), {'chips': 'ahoy', 'vienna': 'finger'})
+ self.assertEqual(parse_cookie('chips=ahoy; vienna=finger'),
+ {'chips': 'ahoy', 'vienna': 'finger'})
# Here parse_cookie() differs from Python's cookie parsing in that it
# treats all semicolons as delimiters, even within quotes.
self.assertEqual(
# Cookies with ':' character in their name.
self.assertEqual(parse_cookie('key:term=value:term'), {'key:term': 'value:term'})
# Cookies with '[' and ']'.
- self.assertEqual(parse_cookie('a=b; c=[; d=r; f=h'), {'a': 'b', 'c': '[', 'd': 'r', 'f': 'h'})
+ self.assertEqual(parse_cookie('a=b; c=[; d=r; f=h'),
+ {'a': 'b', 'c': '[', 'd': 'r', 'f': 'h'})
def test_cookie_edgecases(self):
# Cookies that RFC6265 allows.
- self.assertEqual(parse_cookie('a=b; Domain=example.com'), {'a': 'b', 'Domain': 'example.com'})
+ self.assertEqual(parse_cookie('a=b; Domain=example.com'),
+ {'a': 'b', 'Domain': 'example.com'})
# parse_cookie() has historically kept only the last cookie with the
# same name.
self.assertEqual(parse_cookie('a=b; h=i; a=c'), {'a': 'c', 'h': 'i'})
"""
# Chunks without an equals sign appear as unnamed values per
# https://bugzilla.mozilla.org/show_bug.cgi?id=169091
- self.assertIn('django_language', parse_cookie('abc=def; unnamed; django_language=en').keys())
+ self.assertIn('django_language',
+ parse_cookie('abc=def; unnamed; django_language=en').keys())
# Even a double quote may be an unamed value.
self.assertEqual(parse_cookie('a=b; "; c=d'), {'a': 'b', '': '"', 'c': 'd'})
# Spaces in names and values, and an equals sign in values.
self.assertEqual(parse_cookie('a b c=d e = f; gh=i'), {'a b c': 'd e = f', 'gh': 'i'})
# More characters the spec forbids.
- self.assertEqual(parse_cookie('a b,c<>@:/[]?{}=d " =e,f g'), {'a b,c<>@:/[]?{}': 'd " =e,f g'})
+ self.assertEqual(parse_cookie('a b,c<>@:/[]?{}=d " =e,f g'),
+ {'a b,c<>@:/[]?{}': 'd " =e,f g'})
# Unicode characters. The spec only allows ASCII.
- self.assertEqual(parse_cookie('saint=André Bessette'), {'saint': native_str('André Bessette')})
+ self.assertEqual(parse_cookie('saint=André Bessette'),
+ {'saint': native_str('André Bessette')})
# Browsers don't send extra whitespace or semicolons in Cookie headers,
# but parse_cookie() should parse whitespace the same way
# document.cookie parses whitespace.
from tornado.netutil import ssl_wrap_socket
from tornado.stack_context import NullContext
from tornado.tcpserver import TCPServer
-from tornado.testing import AsyncHTTPTestCase, AsyncHTTPSTestCase, AsyncTestCase, bind_unused_port, ExpectLog, gen_test
+from tornado.testing import AsyncHTTPTestCase, AsyncHTTPSTestCase, AsyncTestCase, bind_unused_port, ExpectLog, gen_test # noqa: E501
from tornado.test.util import unittest, skipIfNonUnix, refusing_port, skipPypy3V58
from tornado.web import RequestHandler, Application
import errno
self.assertEqual(locale.format_date(date, full_format=True),
'April 28, 2013 at 6:35 pm')
- self.assertEqual(locale.format_date(datetime.datetime.utcnow() - datetime.timedelta(seconds=2), full_format=False),
+ now = datetime.datetime.utcnow()
+
+ self.assertEqual(locale.format_date(now - datetime.timedelta(seconds=2), full_format=False),
'2 seconds ago')
- self.assertEqual(locale.format_date(datetime.datetime.utcnow() - datetime.timedelta(minutes=2), full_format=False),
+ self.assertEqual(locale.format_date(now - datetime.timedelta(minutes=2), full_format=False),
'2 minutes ago')
- self.assertEqual(locale.format_date(datetime.datetime.utcnow() - datetime.timedelta(hours=2), full_format=False),
+ self.assertEqual(locale.format_date(now - datetime.timedelta(hours=2), full_format=False),
'2 hours ago')
- now = datetime.datetime.utcnow()
- self.assertEqual(locale.format_date(now - datetime.timedelta(days=1), full_format=False, shorter=True),
- 'yesterday')
+ self.assertEqual(locale.format_date(now - datetime.timedelta(days=1),
+ full_format=False, shorter=True), 'yesterday')
date = now - datetime.timedelta(days=2)
self.assertEqual(locale.format_date(date, full_format=False, shorter=True),
class LogFormatterTest(unittest.TestCase):
# Matches the output of a single logging call (which may be multiple lines
# if a traceback was included, so we use the DOTALL option)
- LINE_RE = re.compile(b"(?s)\x01\\[E [0-9]{6} [0-9]{2}:[0-9]{2}:[0-9]{2} log_test:[0-9]+\\]\x02 (.*)")
+ LINE_RE = re.compile(
+ b"(?s)\x01\\[E [0-9]{6} [0-9]{2}:[0-9]{2}:[0-9]{2} log_test:[0-9]+\\]\x02 (.*)")
def setUp(self):
self.formatter = LogFormatter(color=False)
import sys
import time
-from tornado.netutil import BlockingResolver, OverrideResolver, ThreadedResolver, is_valid_ip, bind_sockets
+from tornado.netutil import (
+ BlockingResolver, OverrideResolver, ThreadedResolver, is_valid_ip, bind_sockets
+)
from tornado.stack_context import ExceptionStackContext
from tornado.testing import AsyncTestCase, gen_test, bind_unused_port
from tornado.test.util import unittest, skipIfNoNetwork
from __future__ import absolute_import, division, print_function
-from tornado.httputil import HTTPHeaders, HTTPMessageDelegate, HTTPServerConnectionDelegate, ResponseStartLine
+from tornado.httputil import HTTPHeaders, HTTPMessageDelegate, HTTPServerConnectionDelegate, ResponseStartLine # noqa: E501
from tornado.routing import HostMatches, PathMatches, ReversibleRouter, Router, Rule, RuleRouter
from tornado.testing import AsyncHTTPTestCase
from tornado.web import Application, HTTPError, RequestHandler
def finish(self):
self.connection.write_headers(
- ResponseStartLine("HTTP/1.1", 200, "OK"), HTTPHeaders({"Content-Length": "2"}), b"OK"
+ ResponseStartLine("HTTP/1.1", 200, "OK"),
+ HTTPHeaders({"Content-Length": "2"}),
+ b"OK"
)
self.connection.finish()
app.add_handlers(".*", [
(HostMatches("www.example.com"), [
- (PathMatches("/first_handler"), "tornado.test.routing_test.SecondHandler", {}, "second_handler")
+ (PathMatches("/first_handler"),
+ "tornado.test.routing_test.SecondHandler", {}, "second_handler")
]),
Rule(PathMatches("/.*handler"), router),
Rule(PathMatches("/first_handler"), FirstHandler, name="first_handler"),