mirror of
https://github.com/sprockets/sprockets.mixins.http.git
synced 2024-11-14 19:29:31 +00:00
flake8 cleanup
This commit is contained in:
parent
bd4ed28fe1
commit
2d17d2fe2e
3 changed files with 26 additions and 24 deletions
|
@ -2,8 +2,9 @@
|
|||
universal = 1
|
||||
|
||||
[flake8]
|
||||
application-import-names=sprockets.mixins
|
||||
application-import-names=sprockets.mixins.http
|
||||
exclude=build,docs,env
|
||||
ignore=RST304
|
||||
import-order-style=google
|
||||
|
||||
[nosetests]
|
||||
|
|
|
@ -53,9 +53,10 @@ slightly higher level of functionality than Tornado's
|
|||
|
||||
|
||||
class HTTPClientMixin:
|
||||
"""Mixin for making http requests. Requests using the asynchronous
|
||||
:meth:`HTTPClientMixin.http_fetch` method """
|
||||
"""Mixin for making http requests using the asynchronous
|
||||
:py:meth:`~sprockets.mixins.http.HTTPClientMixin.http_fetch` method.
|
||||
|
||||
"""
|
||||
AVAILABLE_CONTENT_TYPES = [CONTENT_TYPE_JSON, CONTENT_TYPE_MSGPACK]
|
||||
|
||||
DEFAULT_CONNECT_TIMEOUT = 10
|
||||
|
@ -94,8 +95,8 @@ class HTTPClientMixin:
|
|||
:param mixed body: The HTTP request body to send with the request
|
||||
:param content_type: The mime type to use for requests & responses.
|
||||
Defaults to ``application/msgpack``
|
||||
:type content_type: :class:`~ietfparse.datastructures.ContentType` or
|
||||
str
|
||||
:type content_type: :py:class:`~ietfparse.datastructures.ContentType`
|
||||
or str
|
||||
:param bool follow_redirects: Follow HTTP redirects when received
|
||||
:param int max_redirects: Maximum number of redirects to follow,
|
||||
default is 5
|
||||
|
@ -172,10 +173,10 @@ class HTTPClientMixin:
|
|||
|
||||
if 200 <= response.code < 400:
|
||||
return HTTPResponse(
|
||||
True, response.code, dict(response.headers),
|
||||
self._http_resp_deserialize(response),
|
||||
response, attempt + 1, time.time() - start_time,
|
||||
links, history)
|
||||
True, response.code, dict(response.headers),
|
||||
self._http_resp_deserialize(response),
|
||||
response, attempt + 1, time.time() - start_time,
|
||||
links, history)
|
||||
elif response.code in {423, 429}:
|
||||
await self._http_resp_rate_limited(response)
|
||||
elif 400 <= response.code < 500:
|
||||
|
@ -185,9 +186,9 @@ class HTTPClientMixin:
|
|||
method, url, response.code, attempt + 1,
|
||||
max_http_attempts, error)
|
||||
return HTTPResponse(
|
||||
False, response.code, dict(response.headers),
|
||||
error, response, attempt + 1,
|
||||
time.time() - start_time, links, history)
|
||||
False, response.code, dict(response.headers),
|
||||
error, response, attempt + 1,
|
||||
time.time() - start_time, links, history)
|
||||
else:
|
||||
LOGGER.warning(
|
||||
'HTTP Response Error for %s to %s, '
|
||||
|
@ -199,13 +200,13 @@ class HTTPClientMixin:
|
|||
max_http_attempts)
|
||||
if response:
|
||||
return HTTPResponse(
|
||||
False, response.code, dict(response.headers),
|
||||
self._http_resp_error_message(response) or response.body,
|
||||
response, max_http_attempts,
|
||||
time.time() - start_time, links, history)
|
||||
return HTTPResponse(
|
||||
False, 599, None, None, None, max_http_attempts,
|
||||
False, response.code, dict(response.headers),
|
||||
self._http_resp_error_message(response) or response.body,
|
||||
response, max_http_attempts,
|
||||
time.time() - start_time, links, history)
|
||||
return HTTPResponse(
|
||||
False, 599, None, None, None, max_http_attempts,
|
||||
time.time() - start_time, links, history)
|
||||
|
||||
def _http_req_apply_default_headers(self, request_headers,
|
||||
content_type, body):
|
||||
|
|
12
tests.py
12
tests.py
|
@ -22,7 +22,7 @@ def decode(value):
|
|||
if isinstance(value, list):
|
||||
return [decode(v) for v in value]
|
||||
elif isinstance(value, dict):
|
||||
return dict([(decode(k), decode(v)) for k, v in value.items()])
|
||||
return {decode(k): decode(v) for k, v in value.items()}
|
||||
elif isinstance(value, bytes):
|
||||
return value.decode('utf-8')
|
||||
return value
|
||||
|
@ -434,11 +434,11 @@ class MixinTestCase(testing.AsyncHTTPTestCase):
|
|||
def test_unsupported_accept(self):
|
||||
expectation = '<html>foo</html>'
|
||||
response = yield self.mixin.http_fetch(
|
||||
self.get_url('/test?content_type=text/html'),
|
||||
method='POST',
|
||||
body={'response': expectation},
|
||||
request_headers={'Accept': 'text/html',
|
||||
'Content-Type': 'application/json'})
|
||||
self.get_url('/test?content_type=text/html'),
|
||||
method='POST',
|
||||
body={'response': expectation},
|
||||
request_headers={'Accept': 'text/html',
|
||||
'Content-Type': 'application/json'})
|
||||
self.assertTrue(response.ok)
|
||||
self.assertEqual(response.headers['Content-Type'], 'text/html')
|
||||
self.assertEqual(response.body.decode('utf-8'), expectation)
|
||||
|
|
Loading…
Reference in a new issue