Skip to content

Commit 38a8ae8

Browse files
committed
pep8, test and docs changes
1 parent a59e7b0 commit 38a8ae8

9 files changed

Lines changed: 42 additions & 49 deletions

File tree

‎docs/conf.py‎

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -194,22 +194,22 @@
194194
# -- Options for LaTeX output ---------------------------------------------
195195

196196
latex_elements = {
197-
# The paper size ('letterpaper' or 'a4paper').
198-
#'papersize': 'letterpaper',
197+
# The paper size ('letterpaper' or 'a4paper').
198+
#'papersize': 'letterpaper',
199199

200-
# The font size ('10pt', '11pt' or '12pt').
201-
#'pointsize': '10pt',
200+
# The font size ('10pt', '11pt' or '12pt').
201+
#'pointsize': '10pt',
202202

203-
# Additional stuff for the LaTeX preamble.
204-
#'preamble': '',
203+
# Additional stuff for the LaTeX preamble.
204+
#'preamble': '',
205205
}
206206

207207
# Grouping the document tree into LaTeX files. List of tuples
208208
# (source start file, target name, title,
209209
# author, documentclass [howto, manual, or own class]).
210210
latex_documents = [
211-
('index', 'stream-python.tex', u'stream-python Documentation',
212-
u'Thierry Schellenbach', 'manual'),
211+
('index', 'stream-python.tex', u'stream-python Documentation',
212+
u'Thierry Schellenbach', 'manual'),
213213
]
214214

215215
# The name of an image file (relative to this directory) to place at the top of
@@ -252,9 +252,9 @@
252252
# (source start file, target name, title, author,
253253
# dir menu entry, description, category)
254254
texinfo_documents = [
255-
('index', 'stream-python', u'stream-python Documentation',
256-
u'Thierry Schellenbach', 'stream-python', 'One line description of project.',
257-
'Miscellaneous'),
255+
('index', 'stream-python', u'stream-python Documentation',
256+
u'Thierry Schellenbach', 'stream-python', 'One line description of project.',
257+
'Miscellaneous'),
258258
]
259259

260260
# Documents to append as an appendix to all manuals.

‎fabfile.py‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,7 @@ def validate():
6868
'pep8 --exclude=migrations --ignore=E501,E225 .')
6969
local('%s test' % manage_py)
7070

71+
7172
def clean():
7273
# all dirs which contain python code
7374
python_dirs = []
@@ -80,6 +81,5 @@ def clean():
8081
local('bash -c "autopep8 -i %s/*.py"' % d)
8182

8283

83-
8484
def docs():
8585
local('sphinx-build -Eav docs html')

‎stream/__init__.py‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,4 +33,4 @@ def connect(api_key, api_secret):
3333
Github
3434
Read the docs
3535
Travis setup
36-
'''
36+
'''

‎stream/client.py‎

Lines changed: 8 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@
33
import logging
44
from stream.signing import StreamSigner
55
from stream.utils import validate_feed
6-
from simplejson.scanner import JSONDecodeError
76

87
logger = logging.getLogger(__name__)
98

@@ -60,10 +59,9 @@ def get_headers(self, feed):
6059
'''
6160
Returns the headers with the signed authorization key
6261
'''
63-
feed = feed.replace(':','')
62+
feed = feed.replace(':', '')
6463
signature = StreamSigner(secret=self.api_secret).signature(feed)
6564
headers = {'Authorization': '%s %s' % (feed, signature)}
66-
print headers
6765
return headers
6866

6967
def _make_request(self, method, relative_url, feed, params=None, data=None):
@@ -76,14 +74,11 @@ def _make_request(self, method, relative_url, feed, params=None, data=None):
7674
headers = self.get_headers(feed)
7775
url = self.base_url + relative_url
7876

79-
logger.debug('stream api call %s, headers %s params %s data %s', url, headers, default_params, data)
80-
print default_params
81-
response = method(url, data=data, headers=headers, params=default_params)
82-
try:
83-
result = response.json()
84-
except JSONDecodeError, e:
85-
print 'couldnt not parse json "%s"' % response.text
86-
1/0
77+
logger.debug('stream api call %s, headers %s params %s data %s',
78+
url, headers, default_params, data)
79+
response = method(url, data=data, headers=headers,
80+
params=default_params)
81+
result = response.json()
8782
if result.get('exception'):
8883
self.raise_exception(result)
8984
return result
@@ -96,7 +91,8 @@ def raise_exception(self, result):
9691
error_message = result['detail']
9792
error_code = result.get('code')
9893
exception_dict = get_exception_dict()
99-
exception_class = exception_dict.get(error_code, exceptions.StreamApiException)
94+
exception_class = exception_dict.get(
95+
error_code, exceptions.StreamApiException)
10096
exception = exception_class(error_message)
10197
raise exception
10298

‎stream/exceptions.py‎

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,17 @@
11

22

3-
43
class StreamApiException(Exception):
54

65
def __init__(self, error_message, status_code=None):
76
self.detail = error_message
87
if status_code is not None:
98
self.status_code = status_code
10-
9+
1110
code = 1
12-
11+
1312
def __repr__(self):
1413
return '%s (%s)' % (self.__class__.__name__, self.detail)
15-
14+
1615
def __unicode__(self):
1716
return '%s (%s)' % (self.__class__.__name__, self.detail)
1817

@@ -70,7 +69,8 @@ class SiteSuspendedException(StreamApiException):
7069
'''
7170
status_code = 401
7271
code = 7
73-
72+
73+
7474
def get_exceptions():
7575
from stream import exceptions
7676
classes = []
@@ -83,9 +83,8 @@ def get_exceptions():
8383
pass
8484
return classes
8585

86+
8687
def get_exception_dict():
8788
classes = get_exceptions()
8889
exception_dict = {c.code: c for c in classes}
8990
return exception_dict
90-
91-

‎stream/feed.py‎

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33

44
class Feed(object):
5+
56
def __init__(self, client, feed_id):
67
'''
78
Initializes the Feed class
@@ -15,7 +16,7 @@ def __init__(self, client, feed_id):
1516
self.feed_id = feed_id
1617
self.feed_url = 'feed/%s/' % feed_id.replace(':', '/')
1718
self.feed_together = feed_id.replace(':', '')
18-
19+
1920
def add_activity(self, activity_data):
2021
'''
2122
Adds an activity to the feed, this will also trigger an update
@@ -28,9 +29,10 @@ def add_activity(self, activity_data):
2829
activity_data = {'actor': 1, 'verb': 'tweet', 'object': 1}
2930
activity_id = feed.add_activity(activity_data)
3031
'''
31-
result = self.client.post(self.feed_url, data=activity_data, feed=self.feed_id)
32+
result = self.client.post(
33+
self.feed_url, data=activity_data, feed=self.feed_id)
3234
return result
33-
35+
3436
def remove_activity(self, activity_id):
3537
'''
3638
Removes an activity from the feed
@@ -41,7 +43,7 @@ def remove_activity(self, activity_id):
4143
url = self.feed_url + '%s/' % activity_id
4244
result = self.client.delete(url, feed=self.feed_id)
4345
return result
44-
46+
4547
def follow(self, target_feed):
4648
'''
4749
Follows the given feed
@@ -50,9 +52,10 @@ def follow(self, target_feed):
5052
'''
5153
validate_feed(target_feed)
5254
url = self.feed_url + 'follows/'
53-
response = self.client.post(url, data=dict(target=target_feed), feed=self.feed_id)
55+
response = self.client.post(
56+
url, data=dict(target=target_feed), feed=self.feed_id)
5457
return response
55-
58+
5659
def unfollow(self, target_feed):
5760
'''
5861
Unfollow the given feed
@@ -74,7 +77,6 @@ def get(self, **params):
7477
# slow pagination using offset
7578
feed.get(limit=10, offset=10)
7679
'''
77-
response = self.client.get(self.feed_url, params=params, feed=self.feed_id)
80+
response = self.client.get(
81+
self.feed_url, params=params, feed=self.feed_id)
7882
return response
79-
80-

‎stream/signing.py‎

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,5 +28,3 @@ def signature(self, value):
2828
signed = hmac.new(key, msg=str(value), digestmod=hashlib.sha1)
2929
signature = b64_encode(signed.digest())
3030
return str(signature)
31-
32-

‎stream/tests.py‎

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,8 @@
33
import time
44

55

6-
7-
86
class ClientTest(TestCase):
7+
98
def setUp(self):
109
# DEBUG account details
1110
self.c = stream.connect(
@@ -51,18 +50,17 @@ def test_flat_follow(self):
5150
self.assertEqual(activity_id_found, activity_id)
5251

5352
def _get_first_aggregated_activity(self, activities):
54-
print 'activities', activities[0]['activities']
5553
try:
5654
return activities[0]['activities'][0]
5755
except IndexError, e:
5856
pass
59-
57+
6058
def _get_first_activity(self, activities):
6159
try:
6260
return activities[0]
6361
except IndexError, e:
6462
pass
65-
63+
6664
def test_unfollow(self):
6765
activity_data = {'actor': 1, 'verb': 'tweet', 'object': 1}
6866
activity_id = self.user1.add_activity(activity_data)['id']

‎stream/utils.py‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,4 +3,4 @@
33
def validate_feed(feed):
44
if len(feed.split(':')) != 2:
55
msg = 'Invalid feed spec %s, please specify the feed as feed_slug:feed_id'
6-
raise ValueError(msg % feed)
6+
raise ValueError(msg % feed)

0 commit comments

Comments
 (0)