Permalink
Browse files

pyflakes and pep8 to the build, make the code pass pep8.

  • Loading branch information...
1 parent 5f50170 commit c26353913597874a513f73d2b3a9911fcd503182 @dreid dreid committed Nov 29, 2012
Showing with 17 additions and 31 deletions.
  1. +5 −1 .travis.yml
  2. +3 −0 requirements-dev.txt
  3. +9 −13 treq/client.py
  4. +0 −4 treq/response.py
  5. +0 −13 treq/test/test_treq_integration.py
View
@@ -11,4 +11,8 @@ env:
install:
- pip install Twisted==$TWISTED_VERSION
- pip install -r requirements-dev.txt --use-mirrors
-script: trial treq
+
+script:
+ - pep8 treq
+ - pyflakes treq
+ - trial treq
View
@@ -1,3 +1,6 @@
Twisted>=12.1.0
PyOpenSSL
requests
+
+pyflakes
+pep8
View
@@ -15,9 +15,11 @@
def _from_bytes(orig_bytes):
return FileBodyProducer(StringIO(orig_bytes))
+
def _from_file(orig_file):
return FileBodyProducer(orig_file)
+
registerAdapter(_from_bytes, str, IBodyProducer)
registerAdapter(_from_file, file, IBodyProducer)
registerAdapter(_from_file, StringIO, IBodyProducer)
@@ -27,51 +29,45 @@ class HTTPClient(Protocol):
def __init__(self, agent):
self._agent = agent
-
@classmethod
def with_config(cls, **kwargs):
reactor = kwargs.get('reactor')
if not reactor:
from twisted.internet import reactor
- agent = Agent(reactor,
- pool=HTTPConnectionPool(
- reactor,
- persistent=kwargs.get('persistent', True)))
+ agent = Agent(
+ reactor,
+ pool=HTTPConnectionPool(
+ reactor,
+ persistent=kwargs.get('persistent', True)))
if kwargs.get('allow_redirects', True):
agent = RedirectAgent(agent)
return cls(agent)
-
def get(self, url, **kwargs):
return self.request('GET', url, **kwargs)
-
def put(self, url, data=None, **kwargs):
return self.request('PUT', url, data=data, **kwargs)
-
def post(self, url, data=None, **kwargs):
return self.request('POST', url, data=data, **kwargs)
-
def head(self, url, **kwargs):
return self.request('HEAD', url, **kwargs)
-
def delete(self, url, **kwargs):
return self.request('DELETE', url, **kwargs)
-
def request(self, method, url, **kwargs):
method = method.upper()
data = kwargs.get('data')
- bodyProducer=None
+ bodyProducer = None
if data:
- bodyProducer=IBodyProducer(data)
+ bodyProducer = IBodyProducer(data)
headers = kwargs.get('headers')
if headers:
View
@@ -39,7 +39,6 @@ def __init__(self, response, method):
self.encoding = get_encoding_from_headers(self.headers) or 'ISO-8859-1'
self._waiting_for_content = []
-
def content(self):
def _add_content(data):
self._content = data
@@ -70,7 +69,6 @@ def _add_content(data):
self._response.deliverBody(_BodyCollector(d))
return d
-
def json(self):
def _json_decode(data):
self._json = json.loads(data)
@@ -86,7 +84,6 @@ def _json_decode(data):
return self.content().addCallback(_json_decode)
-
def text(self):
def _text_decode(data):
self._text = data.decode(self.encoding)
@@ -97,7 +94,6 @@ def _text_decode(data):
return self.content().addCallback(_text_decode)
-
def __conform__(self, interface):
if interface is IResponse:
return self._response
@@ -35,80 +35,69 @@ class TreqIntegrationTests(TestCase):
put = with_baseurl(treq.put)
delete = with_baseurl(treq.delete)
-
@inlineCallbacks
def assert_data(self, response, expected_data):
body = yield response.json()
self.assertIn('data', body)
self.assertEqual(body['data'], expected_data)
-
@inlineCallbacks
def assert_sent_header(self, response, header, expected_value):
body = yield response.json()
self.assertIn(header, body['headers'])
self.assertEqual(body['headers'][header], expected_value)
-
@inlineCallbacks
def test_get(self):
response = yield self.get('/get')
self.assertEqual(response.code, 200)
yield print_response(response)
-
@inlineCallbacks
def test_get_headers(self):
response = yield self.get('/get', {'X-Blah': ['Foo']})
self.assertEqual(response.code, 200)
yield self.assert_sent_header(response, 'X-Blah', 'Foo')
yield print_response(response)
-
@inlineCallbacks
def test_get_302_redirect_allowed(self):
response = yield self.get('/redirect/1')
self.assertEqual(response.code, 200)
yield print_response(response)
-
@inlineCallbacks
def test_get_302_redirect_disallowed(self):
response = yield self.get('/redirect/1', allow_redirects=False)
self.assertEqual(response.code, 302)
yield print_response(response)
-
@inlineCallbacks
def test_head(self):
response = yield self.head('/get')
body = yield response.content()
self.assertEqual('', body)
yield print_response(response)
-
@inlineCallbacks
def test_head_302_redirect_allowed(self):
response = yield self.head('/redirect/1')
self.assertEqual(response.code, 200)
yield print_response(response)
-
@inlineCallbacks
def test_head_302_redirect_disallowed(self):
response = yield self.head('/redirect/1', allow_redirects=False)
self.assertEqual(response.code, 302)
yield print_response(response)
-
@inlineCallbacks
def test_post(self):
response = yield self.post('/post', 'Hello!')
self.assertEqual(response.code, 200)
self.assert_data(response, 'Hello!')
yield print_response(response)
-
@inlineCallbacks
def test_post_headers(self):
response = yield self.post(
@@ -123,13 +112,11 @@ def test_post_headers(self):
yield print_response(response)
-
@inlineCallbacks
def test_put(self):
response = yield self.put('/put', data='Hello!')
yield print_response(response)
-
@inlineCallbacks
def test_delete(self):
response = yield self.delete('/delete')

0 comments on commit c263539

Please sign in to comment.