chore: Standardize on single-quotes

This commit is contained in:
Kurt Griffiths
2016-03-03 11:11:13 -06:00
parent 9b268e2434
commit 481b97f78b
17 changed files with 192 additions and 191 deletions

View File

@@ -199,7 +199,7 @@ def main():
'werkzeug'
]
parser = argparse.ArgumentParser(description="Falcon benchmark runner")
parser = argparse.ArgumentParser(description='Falcon benchmark runner')
parser.add_argument('-b', '--benchmark', type=str, action='append',
choices=frameworks, dest='frameworks', nargs='+')
parser.add_argument('-i', '--iterations', type=int, default=50000)

View File

@@ -563,7 +563,7 @@ class Request(object):
# NOTE(tbug): We might want to look into parsing
# cookies ourselves. The SimpleCookie is doing a
# lot if stuff only required to SEND cookies.
parser = SimpleCookie(self.get_header("Cookie"))
parser = SimpleCookie(self.get_header('Cookie'))
cookies = {}
for morsel in parser.values():
cookies[morsel.key] = morsel.value
@@ -1032,7 +1032,7 @@ class Request(object):
try:
date = strptime(param_value, format_string).date()
except ValueError:
msg = "The date value does not match the required format"
msg = 'The date value does not match the required format'
raise HTTPInvalidParam(msg, name)
if store is not None:

View File

@@ -208,29 +208,29 @@ class Response(object):
# NOTE(tbug): we never actually need to
# know that GMT is named GMT when formatting cookies.
# It is a function call less to just write "GMT" in the fmt string:
fmt = "%a, %d %b %Y %H:%M:%S GMT"
fmt = '%a, %d %b %Y %H:%M:%S GMT'
if expires.tzinfo is None:
# naive
self._cookies[name]["expires"] = expires.strftime(fmt)
self._cookies[name]['expires'] = expires.strftime(fmt)
else:
# aware
gmt_expires = expires.astimezone(GMT_TIMEZONE)
self._cookies[name]["expires"] = gmt_expires.strftime(fmt)
self._cookies[name]['expires'] = gmt_expires.strftime(fmt)
if max_age:
self._cookies[name]["max-age"] = max_age
self._cookies[name]['max-age'] = max_age
if domain:
self._cookies[name]["domain"] = domain
self._cookies[name]['domain'] = domain
if path:
self._cookies[name]["path"] = path
self._cookies[name]['path'] = path
if secure:
self._cookies[name]["secure"] = secure
self._cookies[name]['secure'] = secure
if http_only:
self._cookies[name]["httponly"] = http_only
self._cookies[name]['httponly'] = http_only
def unset_cookie(self, name):
"""Unset a cookie in the response
@@ -243,14 +243,14 @@ class Response(object):
if self._cookies is None:
self._cookies = SimpleCookie()
self._cookies[name] = ""
self._cookies[name] = ''
# NOTE(Freezerburn): SimpleCookie apparently special cases the
# expires attribute to automatically use strftime and set the
# time as a delta from the current time. We use -1 here to
# basically tell the browser to immediately expire the cookie,
# thus removing it from future request objects.
self._cookies[name]["expires"] = -1
self._cookies[name]['expires'] = -1
def get_header(self, name):
"""Retrieve the raw string value for the given header.
@@ -592,6 +592,6 @@ class Response(object):
#
# Even without the .split("\\r\\n"), the below
# is still ~17% faster, so don't use .output()
items += [("set-cookie", c.OutputString())
items += [('set-cookie', c.OutputString())
for c in self._cookies.values()]
return items

View File

@@ -65,7 +65,7 @@ def format_range(value):
def is_ascii_encodable(s):
"""Check if argument encodes to ascii without error."""
try:
s.encode("ascii")
s.encode('ascii')
except UnicodeEncodeError:
# NOTE(tbug): Py2 and Py3 will raise this if string contained
# chars that could not be ascii encoded

View File

@@ -90,7 +90,7 @@ HTTP_417 = '417 Expectation Failed'
HTTP_EXPECTATION_FAILED = HTTP_417
HTTP_418 = "418 I'm a teapot"
HTTP_IM_A_TEAPOT = HTTP_418
HTTP_422 = "422 Unprocessable Entity"
HTTP_422 = '422 Unprocessable Entity'
HTTP_UNPROCESSABLE_ENTITY = HTTP_422
HTTP_426 = '426 Upgrade Required'
HTTP_UPGRADE_REQUIRED = HTTP_426
@@ -146,7 +146,7 @@ HTTP_742 = '742 A kitten dies'
HTTP_743 = '743 I thought I knew regular expressions'
HTTP_744 = '744 Y U NO write integration tests?'
HTTP_745 = ("745 I don't always test my code, but when I do"
"I do it in production")
'I do it in production')
HTTP_748 = '748 Confounded by Ponies'
HTTP_749 = '749 Reserved for Chuck Norris'

View File

@@ -131,7 +131,7 @@ class TestResource(object):
otherwise.
"""
sample_status = "200 OK"
sample_status = '200 OK'
sample_body = rand_string(0, 128 * 1024)
resp_headers = {
'Content-Type': 'text/plain; charset=UTF-8',

View File

@@ -29,7 +29,7 @@ class TimezoneGMT(datetime.tzinfo):
str: "GMT"
"""
return "GMT"
return 'GMT'
def dst(self, dt):
"""Return the daylight saving time (DST) adjustment.

View File

@@ -1,7 +1,7 @@
def application(environ, start_response):
# wsgi_errors = environ['wsgi.errors']
start_response("200 OK", [
start_response('200 OK', [
('Content-Type', 'text/plain')])
body = '\n{\n'

View File

@@ -11,7 +11,7 @@ import falcon.testing as testing
from falcon.util import TimezoneGMT, http_date_to_dt
UNICODE_TEST_STRING = u"Unicode_\xc3\xa6\xc3\xb8"
UNICODE_TEST_STRING = u'Unicode_\xc3\xa6\xc3\xb8'
class TimezoneGMTPlus1(tzinfo):
@@ -20,7 +20,7 @@ class TimezoneGMTPlus1(tzinfo):
return timedelta(hours=1)
def tzname(self, dt):
return "GMT+1"
return 'GMT+1'
def dst(self, dt):
return timedelta(hours=1)
@@ -31,23 +31,23 @@ GMT_PLUS_ONE = TimezoneGMTPlus1()
class CookieResource:
def on_get(self, req, resp):
resp.set_cookie("foo", "bar", domain="example.com", path="/")
resp.set_cookie('foo', 'bar', domain='example.com', path='/')
def on_head(self, req, resp):
resp.set_cookie("foo", "bar", max_age=300)
resp.set_cookie("bar", "baz", http_only=False)
resp.set_cookie("bad", "cookie")
resp.unset_cookie("bad")
resp.set_cookie('foo', 'bar', max_age=300)
resp.set_cookie('bar', 'baz', http_only=False)
resp.set_cookie('bad', 'cookie')
resp.unset_cookie('bad')
def on_post(self, req, resp):
e = datetime(year=2050, month=1, day=1) # naive
resp.set_cookie("foo", "bar", http_only=False, secure=False, expires=e)
resp.unset_cookie("bad")
resp.set_cookie('foo', 'bar', http_only=False, secure=False, expires=e)
resp.unset_cookie('bad')
def on_put(self, req, resp):
e = datetime(year=2050, month=1, day=1, tzinfo=GMT_PLUS_ONE) # aware
resp.set_cookie("foo", "bar", http_only=False, secure=False, expires=e)
resp.unset_cookie("bad")
resp.set_cookie('foo', 'bar', http_only=False, secure=False, expires=e)
resp.unset_cookie('bad')
@ddt.ddt
@@ -60,43 +60,43 @@ class TestCookies(testing.TestBase):
def test_response_base_case(self):
self.resource = CookieResource()
self.api.add_route(self.test_route, self.resource)
self.simulate_request(self.test_route, method="GET")
self.simulate_request(self.test_route, method='GET')
if sys.version_info >= (3, 4, 3):
value = "foo=bar; Domain=example.com; HttpOnly; Path=/; Secure"
value = 'foo=bar; Domain=example.com; HttpOnly; Path=/; Secure'
else:
value = "foo=bar; Domain=example.com; httponly; Path=/; secure"
self.assertIn(("set-cookie", value), self.srmock.headers)
value = 'foo=bar; Domain=example.com; httponly; Path=/; secure'
self.assertIn(('set-cookie', value), self.srmock.headers)
def test_response_complex_case(self):
self.resource = CookieResource()
self.api.add_route(self.test_route, self.resource)
self.simulate_request(self.test_route, method="HEAD")
self.simulate_request(self.test_route, method='HEAD')
if sys.version_info >= (3, 4, 3):
value = "foo=bar; HttpOnly; Max-Age=300; Secure"
value = 'foo=bar; HttpOnly; Max-Age=300; Secure'
else:
value = "foo=bar; httponly; Max-Age=300; secure"
self.assertIn(("set-cookie", value), self.srmock.headers)
value = 'foo=bar; httponly; Max-Age=300; secure'
self.assertIn(('set-cookie', value), self.srmock.headers)
if sys.version_info >= (3, 4, 3):
value = "bar=baz; Secure"
value = 'bar=baz; Secure'
else:
value = "bar=baz; secure"
self.assertIn(("set-cookie", value), self.srmock.headers)
self.assertNotIn(("set-cookie", "bad=cookie"), self.srmock.headers)
value = 'bar=baz; secure'
self.assertIn(('set-cookie', value), self.srmock.headers)
self.assertNotIn(('set-cookie', 'bad=cookie'), self.srmock.headers)
def test_cookie_expires_naive(self):
self.resource = CookieResource()
self.api.add_route(self.test_route, self.resource)
self.simulate_request(self.test_route, method="POST")
self.simulate_request(self.test_route, method='POST')
self.assertIn(
("set-cookie", "foo=bar; expires=Sat, 01 Jan 2050 00:00:00 GMT"),
('set-cookie', 'foo=bar; expires=Sat, 01 Jan 2050 00:00:00 GMT'),
self.srmock.headers)
def test_cookie_expires_aware(self):
self.resource = CookieResource()
self.api.add_route(self.test_route, self.resource)
self.simulate_request(self.test_route, method="PUT")
self.simulate_request(self.test_route, method='PUT')
self.assertIn(
("set-cookie", "foo=bar; expires=Fri, 31 Dec 2049 23:00:00 GMT"),
('set-cookie', 'foo=bar; expires=Fri, 31 Dec 2049 23:00:00 GMT'),
self.srmock.headers)
def test_cookies_setable(self):
@@ -104,20 +104,20 @@ class TestCookies(testing.TestBase):
self.assertIsNone(resp._cookies)
resp.set_cookie("foo", "wrong-cookie", max_age=301)
resp.set_cookie("foo", "bar", max_age=300)
morsel = resp._cookies["foo"]
resp.set_cookie('foo', 'wrong-cookie', max_age=301)
resp.set_cookie('foo', 'bar', max_age=300)
morsel = resp._cookies['foo']
self.assertIsInstance(morsel, Morsel)
self.assertEqual(morsel.key, "foo")
self.assertEqual(morsel.value, "bar")
self.assertEqual(morsel["max-age"], 300)
self.assertEqual(morsel.key, 'foo')
self.assertEqual(morsel.value, 'bar')
self.assertEqual(morsel['max-age'], 300)
def test_response_unset_cookie(self):
resp = falcon.Response()
resp.unset_cookie("bad")
resp.set_cookie("bad", "cookie", max_age=300)
resp.unset_cookie("bad")
resp.unset_cookie('bad')
resp.set_cookie('bad', 'cookie', max_age=300)
resp.unset_cookie('bad')
morsels = list(resp._cookies.values())
self.assertEqual(len(morsels), 1)
@@ -136,7 +136,7 @@ class TestCookies(testing.TestBase):
def test_cookie_timezone(self):
tz = TimezoneGMT()
self.assertEqual("GMT", tz.tzname(timedelta(0)))
self.assertEqual('GMT', tz.tzname(timedelta(0)))
#
# Request
@@ -155,25 +155,25 @@ class TestCookies(testing.TestBase):
environ = testing.create_environ(headers=headers)
req = falcon.Request(environ)
self.assertEqual("no", req.cookies["logged_in"])
self.assertEqual("Europe/Berlin", req.cookies["tz"])
self.assertEqual("GH1.1.201722077.1422308165", req.cookies["_octo"])
self.assertEqual('no', req.cookies['logged_in'])
self.assertEqual('Europe/Berlin', req.cookies['tz'])
self.assertEqual('GH1.1.201722077.1422308165', req.cookies['_octo'])
self.assertIn("logged_in", req.cookies)
self.assertIn("_gh_sess", req.cookies)
self.assertIn("tz", req.cookies)
self.assertIn("_ga", req.cookies)
self.assertIn("_gat", req.cookies)
self.assertIn("_octo", req.cookies)
self.assertIn('logged_in', req.cookies)
self.assertIn('_gh_sess', req.cookies)
self.assertIn('tz', req.cookies)
self.assertIn('_ga', req.cookies)
self.assertIn('_gat', req.cookies)
self.assertIn('_octo', req.cookies)
def test_unicode_inside_ascii_range(self):
resp = falcon.Response()
# should be ok
resp.set_cookie("non_unicode_ascii_name_1", "ascii_value")
resp.set_cookie(u"unicode_ascii_name_1", "ascii_value")
resp.set_cookie("non_unicode_ascii_name_2", u"unicode_ascii_value")
resp.set_cookie(u"unicode_ascii_name_2", u"unicode_ascii_value")
resp.set_cookie('non_unicode_ascii_name_1', 'ascii_value')
resp.set_cookie(u'unicode_ascii_name_1', 'ascii_value')
resp.set_cookie('non_unicode_ascii_name_2', u'unicode_ascii_value')
resp.set_cookie(u'unicode_ascii_name_2', u'unicode_ascii_value')
@ddt.data(
UNICODE_TEST_STRING,
@@ -183,7 +183,7 @@ class TestCookies(testing.TestBase):
def test_non_ascii_name(self, name):
resp = falcon.Response()
self.assertRaises(KeyError, resp.set_cookie,
name, "ok_value")
name, 'ok_value')
@ddt.data(
UNICODE_TEST_STRING,
@@ -197,9 +197,9 @@ class TestCookies(testing.TestBase):
# that it is not instance of UnicodeEncodeError, so
# we cannot simply use assertRaises
try:
resp.set_cookie("ok_name", value)
resp.set_cookie('ok_name', value)
except ValueError as e:
self.assertIsInstance(e, ValueError)
self.assertNotIsInstance(e, UnicodeEncodeError)
else:
self.fail("set_bad_cookie_value did not fail as expected")
self.fail('set_bad_cookie_value did not fail as expected')

View File

@@ -29,7 +29,7 @@ class HeaderHelpersResource(object):
resp.cache_control = ['no-store']
def on_get(self, req, resp):
resp.body = "{}"
resp.body = '{}'
resp.content_type = 'x-falcon/peregrine'
resp.cache_control = [
'public', 'private', 'no-cache', 'no-store', 'must-revalidate',

View File

@@ -7,14 +7,14 @@ from falcon.http_status import HTTPStatus
def before_hook(req, resp, params):
raise HTTPStatus(falcon.HTTP_200,
headers={"X-Failed": "False"},
body="Pass")
headers={'X-Failed': 'False'},
body='Pass')
def after_hook(req, resp, resource):
resp.status = falcon.HTTP_200
resp.set_header("X-Failed", "False")
resp.body = "Pass"
resp.set_header('X-Failed', 'False')
resp.body = 'Pass'
def noop_after_hook(req, resp, resource):
@@ -26,23 +26,23 @@ class TestStatusResource:
@falcon.before(before_hook)
def on_get(self, req, resp):
resp.status = falcon.HTTP_500
resp.set_header("X-Failed", "True")
resp.body = "Fail"
resp.set_header('X-Failed', 'True')
resp.body = 'Fail'
def on_post(self, req, resp):
resp.status = falcon.HTTP_500
resp.set_header("X-Failed", "True")
resp.body = "Fail"
resp.set_header('X-Failed', 'True')
resp.body = 'Fail'
raise HTTPStatus(falcon.HTTP_200,
headers={"X-Failed": "False"},
body="Pass")
headers={'X-Failed': 'False'},
body='Pass')
@falcon.after(after_hook)
def on_put(self, req, resp):
resp.status = falcon.HTTP_500
resp.set_header("X-Failed", "True")
resp.body = "Fail"
resp.set_header('X-Failed', 'True')
resp.body = 'Fail'
def on_patch(self, req, resp):
raise HTTPStatus(falcon.HTTP_200,
@@ -51,16 +51,16 @@ class TestStatusResource:
@falcon.after(noop_after_hook)
def on_delete(self, req, resp):
raise HTTPStatus(falcon.HTTP_200,
headers={"X-Failed": "False"},
body="Pass")
headers={'X-Failed': 'False'},
body='Pass')
class TestHookResource:
def on_get(self, req, resp):
resp.status = falcon.HTTP_500
resp.set_header("X-Failed", "True")
resp.body = "Fail"
resp.set_header('X-Failed', 'True')
resp.body = 'Fail'
def on_patch(self, req, resp):
raise HTTPStatus(falcon.HTTP_200,
@@ -68,8 +68,8 @@ class TestHookResource:
def on_delete(self, req, resp):
raise HTTPStatus(falcon.HTTP_200,
headers={"X-Failed": "False"},
body="Pass")
headers={'X-Failed': 'False'},
body='Pass')
class TestHTTPStatus(testing.TestBase):
@@ -152,8 +152,8 @@ class TestHTTPStatusWithGlobalHooks(testing.TestBase):
class TestMiddleware:
def process_request(self, req, resp):
raise HTTPStatus(falcon.HTTP_200,
headers={"X-Failed": "False"},
body="Pass")
headers={'X-Failed': 'False'},
body='Pass')
self.api = falcon.API(middleware=TestMiddleware())
self.api.add_route('/status', self.resource)
@@ -168,8 +168,8 @@ class TestHTTPStatusWithGlobalHooks(testing.TestBase):
class TestMiddleware:
def process_resource(self, req, resp, resource, params):
raise HTTPStatus(falcon.HTTP_200,
headers={"X-Failed": "False"},
body="Pass")
headers={'X-Failed': 'False'},
body='Pass')
self.api = falcon.API(middleware=TestMiddleware())
self.api.add_route('/status', self.resource)
@@ -184,8 +184,8 @@ class TestHTTPStatusWithGlobalHooks(testing.TestBase):
class TestMiddleware:
def process_response(self, req, resp, response):
resp.status = falcon.HTTP_200
resp.set_header("X-Failed", "False")
resp.body = "Pass"
resp.set_header('X-Failed', 'False')
resp.body = 'Pass'
self.api = falcon.API(middleware=TestMiddleware())
self.api.add_route('/status', self.resource)

View File

@@ -98,7 +98,7 @@ class TestRequestTimeMiddleware(TestMiddleware):
mw_list = [RequestTimeMiddleware(), InvalidMiddleware]
self.assertRaises(AttributeError, falcon.API, middleware=mw_list)
mw_list = [RequestTimeMiddleware(), "InvalidMiddleware"]
mw_list = [RequestTimeMiddleware(), 'InvalidMiddleware']
self.assertRaises(TypeError, falcon.API, middleware=mw_list)
mw_list = [{'process_request': 90}]
self.assertRaises(TypeError, falcon.API, middleware=mw_list)
@@ -108,7 +108,7 @@ class TestRequestTimeMiddleware(TestMiddleware):
class RaiseErrorMiddleware(object):
def process_response(self, req, resp, resource):
raise Exception("Always fail")
raise Exception('Always fail')
self.api = falcon.API(middleware=[RaiseErrorMiddleware()])
@@ -126,13 +126,13 @@ class TestRequestTimeMiddleware(TestMiddleware):
body = self.simulate_json_request(self.test_route)
self.assertEqual(_EXPECTED_BODY, body)
self.assertEqual(self.srmock.status, falcon.HTTP_200)
self.assertIn("start_time", context)
self.assertIn("mid_time", context)
self.assertIn("end_time", context)
self.assertIn('start_time', context)
self.assertIn('mid_time', context)
self.assertIn('end_time', context)
self.assertTrue(context['mid_time'] >= context['start_time'],
"process_resource not executed after request")
'process_resource not executed after request')
self.assertTrue(context['end_time'] >= context['start_time'],
"process_response not executed after request")
'process_response not executed after request')
class TestTransactionIdMiddleware(TestMiddleware):
@@ -147,8 +147,8 @@ class TestTransactionIdMiddleware(TestMiddleware):
body = self.simulate_json_request(self.test_route)
self.assertEqual(_EXPECTED_BODY, body)
self.assertEqual(self.srmock.status, falcon.HTTP_200)
self.assertIn("transaction_id", context)
self.assertEqual("unique-req-id", context['transaction_id'])
self.assertIn('transaction_id', context)
self.assertEqual('unique-req-id', context['transaction_id'])
class TestSeveralMiddlewares(TestMiddleware):
@@ -163,15 +163,15 @@ class TestSeveralMiddlewares(TestMiddleware):
body = self.simulate_json_request(self.test_route)
self.assertEqual(_EXPECTED_BODY, body)
self.assertEqual(self.srmock.status, falcon.HTTP_200)
self.assertIn("transaction_id", context)
self.assertEqual("unique-req-id", context['transaction_id'])
self.assertIn("start_time", context)
self.assertIn("mid_time", context)
self.assertIn("end_time", context)
self.assertIn('transaction_id', context)
self.assertEqual('unique-req-id', context['transaction_id'])
self.assertIn('start_time', context)
self.assertIn('mid_time', context)
self.assertIn('end_time', context)
self.assertTrue(context['mid_time'] >= context['start_time'],
"process_resource not executed after request")
'process_resource not executed after request')
self.assertTrue(context['end_time'] >= context['start_time'],
"process_response not executed after request")
'process_response not executed after request')
def test_middleware_execution_order(self):
global context
@@ -186,12 +186,12 @@ class TestSeveralMiddlewares(TestMiddleware):
# as the method registration is in a list, the order also is
# tested
expectedExecutedMethods = [
"ExecutedFirstMiddleware.process_request",
"ExecutedLastMiddleware.process_request",
"ExecutedFirstMiddleware.process_resource",
"ExecutedLastMiddleware.process_resource",
"ExecutedLastMiddleware.process_response",
"ExecutedFirstMiddleware.process_response"
'ExecutedFirstMiddleware.process_request',
'ExecutedLastMiddleware.process_request',
'ExecutedFirstMiddleware.process_resource',
'ExecutedLastMiddleware.process_resource',
'ExecutedLastMiddleware.process_response',
'ExecutedFirstMiddleware.process_response'
]
self.assertEqual(expectedExecutedMethods, context['executed_methods'])
@@ -202,7 +202,7 @@ class TestSeveralMiddlewares(TestMiddleware):
class RaiseErrorMiddleware(object):
def process_request(self, req, resp):
raise Exception("Always fail")
raise Exception('Always fail')
self.api = falcon.API(middleware=[TransactionIdMiddleware(),
RequestTimeMiddleware(),
@@ -213,10 +213,10 @@ class TestSeveralMiddlewares(TestMiddleware):
self.assertRaises(Exception, self.simulate_request, self.test_route)
# RequestTimeMiddleware process_response should be executed
self.assertIn("transaction_id", context)
self.assertIn("start_time", context)
self.assertNotIn("mid_time", context)
self.assertIn("end_time", context)
self.assertIn('transaction_id', context)
self.assertIn('start_time', context)
self.assertNotIn('mid_time', context)
self.assertIn('end_time', context)
def test_inner_mw_with_ex_handler_throw_exception(self):
"""Test that error in inner middleware leaves"""
@@ -225,7 +225,7 @@ class TestSeveralMiddlewares(TestMiddleware):
class RaiseErrorMiddleware(object):
def process_request(self, req, resp, resource):
raise Exception("Always fail")
raise Exception('Always fail')
self.api = falcon.API(middleware=[TransactionIdMiddleware(),
RequestTimeMiddleware(),
@@ -241,11 +241,11 @@ class TestSeveralMiddlewares(TestMiddleware):
self.simulate_request(self.test_route)
# RequestTimeMiddleware process_response should be executed
self.assertIn("transaction_id", context)
self.assertIn("start_time", context)
self.assertNotIn("mid_time", context)
self.assertIn("end_time", context)
self.assertIn("error_handler", context)
self.assertIn('transaction_id', context)
self.assertIn('start_time', context)
self.assertNotIn('mid_time', context)
self.assertIn('end_time', context)
self.assertIn('error_handler', context)
def test_outer_mw_with_ex_handler_throw_exception(self):
"""Test that error in inner middleware leaves"""
@@ -254,7 +254,7 @@ class TestSeveralMiddlewares(TestMiddleware):
class RaiseErrorMiddleware(object):
def process_request(self, req, resp):
raise Exception("Always fail")
raise Exception('Always fail')
self.api = falcon.API(middleware=[TransactionIdMiddleware(),
RaiseErrorMiddleware(),
@@ -270,11 +270,11 @@ class TestSeveralMiddlewares(TestMiddleware):
self.simulate_request(self.test_route)
# Any mw is executed now...
self.assertIn("transaction_id", context)
self.assertNotIn("start_time", context)
self.assertNotIn("mid_time", context)
self.assertNotIn("end_time", context)
self.assertIn("error_handler", context)
self.assertIn('transaction_id', context)
self.assertNotIn('start_time', context)
self.assertNotIn('mid_time', context)
self.assertNotIn('end_time', context)
self.assertIn('error_handler', context)
def test_order_mw_executed_when_exception_in_resp(self):
"""Test that error in inner middleware leaves"""
@@ -283,7 +283,7 @@ class TestSeveralMiddlewares(TestMiddleware):
class RaiseErrorMiddleware(object):
def process_response(self, req, resp, resource):
raise Exception("Always fail")
raise Exception('Always fail')
self.api = falcon.API(middleware=[ExecutedFirstMiddleware(),
RaiseErrorMiddleware(),
@@ -300,12 +300,12 @@ class TestSeveralMiddlewares(TestMiddleware):
# Any mw is executed now...
expectedExecutedMethods = [
"ExecutedFirstMiddleware.process_request",
"ExecutedLastMiddleware.process_request",
"ExecutedFirstMiddleware.process_resource",
"ExecutedLastMiddleware.process_resource",
"ExecutedLastMiddleware.process_response",
"ExecutedFirstMiddleware.process_response"
'ExecutedFirstMiddleware.process_request',
'ExecutedLastMiddleware.process_request',
'ExecutedFirstMiddleware.process_resource',
'ExecutedLastMiddleware.process_resource',
'ExecutedLastMiddleware.process_response',
'ExecutedFirstMiddleware.process_response'
]
self.assertEqual(expectedExecutedMethods, context['executed_methods'])
@@ -316,7 +316,7 @@ class TestSeveralMiddlewares(TestMiddleware):
class RaiseErrorMiddleware(object):
def process_request(self, req, resp):
raise Exception("Always fail")
raise Exception('Always fail')
self.api = falcon.API(middleware=[ExecutedFirstMiddleware(),
RaiseErrorMiddleware(),
@@ -333,8 +333,8 @@ class TestSeveralMiddlewares(TestMiddleware):
# Any mw is executed now...
expectedExecutedMethods = [
"ExecutedFirstMiddleware.process_request",
"ExecutedFirstMiddleware.process_response"
'ExecutedFirstMiddleware.process_request',
'ExecutedFirstMiddleware.process_response'
]
self.assertEqual(expectedExecutedMethods, context['executed_methods'])
@@ -345,7 +345,7 @@ class TestSeveralMiddlewares(TestMiddleware):
class RaiseErrorMiddleware(object):
def process_resource(self, req, resp, resource):
raise Exception("Always fail")
raise Exception('Always fail')
self.api = falcon.API(middleware=[ExecutedFirstMiddleware(),
RaiseErrorMiddleware(),
@@ -362,11 +362,11 @@ class TestSeveralMiddlewares(TestMiddleware):
# Any mw is executed now...
expectedExecutedMethods = [
"ExecutedFirstMiddleware.process_request",
"ExecutedLastMiddleware.process_request",
"ExecutedFirstMiddleware.process_resource",
"ExecutedLastMiddleware.process_response",
"ExecutedFirstMiddleware.process_response"
'ExecutedFirstMiddleware.process_request',
'ExecutedLastMiddleware.process_request',
'ExecutedFirstMiddleware.process_resource',
'ExecutedLastMiddleware.process_response',
'ExecutedFirstMiddleware.process_response'
]
self.assertEqual(expectedExecutedMethods, context['executed_methods'])
@@ -404,4 +404,4 @@ class TestResourceMiddleware(TestMiddleware):
self.assertIn('params', context)
self.assertTrue(context['params'])
self.assertEqual(context['params']['id'], '22')
self.assertEqual(body, {"added": True, "id": "22"})
self.assertEqual(body, {'added': True, 'id': '22'})

View File

@@ -429,47 +429,47 @@ class _TestQueryParams(testing.TestBase):
self.assertEqual(req.get_param_as_list('cat'), ['6', '5', '4'])
def test_get_date_valid(self):
date_value = "2015-04-20"
query_string = "thedate={0}".format(date_value)
self.simulate_request("/", query_string=query_string)
date_value = '2015-04-20'
query_string = 'thedate={0}'.format(date_value)
self.simulate_request('/', query_string=query_string)
req = self.resource.req
self.assertEqual(req.get_param_as_date("thedate"),
self.assertEqual(req.get_param_as_date('thedate'),
date(2015, 4, 20))
def test_get_date_missing_param(self):
query_string = "notthedate=2015-04-20"
self.simulate_request("/", query_string=query_string)
query_string = 'notthedate=2015-04-20'
self.simulate_request('/', query_string=query_string)
req = self.resource.req
self.assertEqual(req.get_param_as_date("thedate"),
self.assertEqual(req.get_param_as_date('thedate'),
None)
def test_get_date_valid_with_format(self):
date_value = "20150420"
query_string = "thedate={0}".format(date_value)
format_string = "%Y%m%d"
self.simulate_request("/", query_string=query_string)
date_value = '20150420'
query_string = 'thedate={0}'.format(date_value)
format_string = '%Y%m%d'
self.simulate_request('/', query_string=query_string)
req = self.resource.req
self.assertEqual(req.get_param_as_date("thedate",
self.assertEqual(req.get_param_as_date('thedate',
format_string=format_string),
date(2015, 4, 20))
def test_get_date_store(self):
date_value = "2015-04-20"
query_string = "thedate={0}".format(date_value)
self.simulate_request("/", query_string=query_string)
date_value = '2015-04-20'
query_string = 'thedate={0}'.format(date_value)
self.simulate_request('/', query_string=query_string)
req = self.resource.req
store = {}
req.get_param_as_date("thedate", store=store)
req.get_param_as_date('thedate', store=store)
self.assertNotEqual(len(store), 0)
def test_get_date_invalid(self):
date_value = "notarealvalue"
query_string = "thedate={0}".format(date_value)
format_string = "%Y%m%d"
self.simulate_request("/", query_string=query_string)
date_value = 'notarealvalue'
query_string = 'thedate={0}'.format(date_value)
format_string = '%Y%m%d'
self.simulate_request('/', query_string=query_string)
req = self.resource.req
self.assertRaises(HTTPInvalidParam, req.get_param_as_date,
"thedate", format_string=format_string)
'thedate', format_string=format_string)
class PostQueryParams(_TestQueryParams):
@@ -478,7 +478,7 @@ class PostQueryParams(_TestQueryParams):
self.api.req_options.auto_parse_form_urlencoded = True
def simulate_request(self, path, query_string, **kwargs):
headers = {"Content-Type": "application/x-www-form-urlencoded"}
headers = {'Content-Type': 'application/x-www-form-urlencoded'}
super(PostQueryParams, self).simulate_request(
path, body=query_string, headers=headers, **kwargs)
@@ -509,7 +509,7 @@ class PostQueryParamsDefaultBehavior(testing.TestBase):
self.resource = testing.TestResource()
self.api.add_route('/', self.resource)
headers = {"Content-Type": "application/x-www-form-urlencoded"}
headers = {'Content-Type': 'application/x-www-form-urlencoded'}
self.simulate_request('/', body='q=42', headers=headers)
req = self.resource.req

View File

@@ -501,8 +501,8 @@ class TestReqVars(testing.TestBase):
'Invalid header value', expected_desc)
headers = {'Range': '10-'}
expected_desc = ("The value provided for the Range "
"header is invalid. The value must be "
expected_desc = ('The value provided for the Range '
'header is invalid. The value must be '
"prefixed with a range unit, e.g. 'bytes='")
self._test_error_details(headers, 'range',
falcon.HTTPInvalidHeader,

View File

@@ -6,12 +6,12 @@ import falcon.testing as testing
class TestResponseBody(testing.TestBase):
def test_append_body(self):
text = "Hello beautiful world! "
text = 'Hello beautiful world! '
resp = falcon.Response()
resp.body = ""
resp.body = ''
for token in text.split():
resp.body += token
resp.body += " "
resp.body += ' '
self.assertEqual(resp.body, text)

View File

@@ -205,7 +205,7 @@ class TestFalconUtils(testtools.TestCase):
def test_prop_uri_encode_value_models_stdlib_quote_safe_tilde(self):
equiv_quote = functools.partial(
six.moves.urllib.parse.quote, safe="~"
six.moves.urllib.parse.quote, safe='~'
)
for case in self.uris:
expect = equiv_quote(case)
@@ -223,14 +223,14 @@ class TestFalconUtils(testtools.TestCase):
def test_parse_query_string(self):
query_strinq = (
"a=http%3A%2F%2Ffalconframework.org%3Ftest%3D1"
"&b=%7B%22test1%22%3A%20%22data1%22%"
"2C%20%22test2%22%3A%20%22data2%22%7D"
"&c=1,2,3"
"&d=test"
"&e=a,,%26%3D%2C"
"&f=a&f=a%3Db"
"&%C3%A9=a%3Db"
'a=http%3A%2F%2Ffalconframework.org%3Ftest%3D1'
'&b=%7B%22test1%22%3A%20%22data1%22%'
'2C%20%22test2%22%3A%20%22data2%22%7D'
'&c=1,2,3'
'&d=test'
'&e=a,,%26%3D%2C'
'&f=a&f=a%3Db'
'&%C3%A9=a%3Db'
)
decoded_url = 'http://falconframework.org?test=1'
decoded_json = '{"test1": "data1", "test2": "data2"}'

View File

@@ -118,6 +118,7 @@ commands = py3kwarn falcon
[testenv:pep8]
deps = flake8
flake8-quotes
# NOTE(kgriffs): Run with py27 since some code branches assume the
# unicode type is defined, and pep8 complains in those cases when