Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit e0b65c4

Browse files
committed
ran black on entire project
1 parent 31420ae commit e0b65c4

19 files changed

+443
-317
lines changed

stream/__init__.py

+34-18
Original file line numberDiff line numberDiff line change
@@ -1,37 +1,53 @@
11
import re
22
import os
33

4-
__author__ = 'Thierry Schellenbach'
5-
__copyright__ = 'Copyright 2014, Stream.io, Inc'
6-
__credits__ = ['Thierry Schellenbach, mellowmorning.com, @tschellenbach']
7-
__license__ = 'BSD-3-Clause'
8-
__version__ = '2.12.0'
9-
__maintainer__ = 'Thierry Schellenbach'
10-
__email__ = '[email protected]'
11-
__status__ = 'Production'
4+
__author__ = "Thierry Schellenbach"
5+
__copyright__ = "Copyright 2014, Stream.io, Inc"
6+
__credits__ = ["Thierry Schellenbach, mellowmorning.com, @tschellenbach"]
7+
__license__ = "BSD-3-Clause"
8+
__version__ = "2.12.0"
9+
__maintainer__ = "Thierry Schellenbach"
10+
__email__ = "[email protected]"
11+
__status__ = "Production"
1212

1313

14-
def connect(api_key=None, api_secret=None, app_id=None, version='v1.0',
15-
timeout=3.0, location=None, base_url=None):
16-
'''
14+
def connect(
15+
api_key=None,
16+
api_secret=None,
17+
app_id=None,
18+
version="v1.0",
19+
timeout=3.0,
20+
location=None,
21+
base_url=None,
22+
):
23+
"""
1724
Returns a Client object
1825
1926
:param api_key: your api key or heroku url
2027
:param api_secret: the api secret
2128
:param app_id: the app id (used for listening to feed changes)
22-
'''
29+
"""
2330
from stream.client import StreamClient
24-
stream_url = os.environ.get('STREAM_URL')
31+
32+
stream_url = os.environ.get("STREAM_URL")
2533
# support for the heroku STREAM_URL syntax
2634
if stream_url and not api_key:
2735
pattern = re.compile(
28-
'https\:\/\/(\w+)\:(\w+)\@([\w-]*).*\?app_id=(\d+)', re.IGNORECASE)
36+
"https\:\/\/(\w+)\:(\w+)\@([\w-]*).*\?app_id=(\d+)", re.IGNORECASE
37+
)
2938
result = pattern.match(stream_url)
3039
if result and len(result.groups()) == 4:
3140
api_key, api_secret, location, app_id = result.groups()
32-
location = None if location in ('getstream', 'stream-io-api') else location
41+
location = None if location in ("getstream", "stream-io-api") else location
3342
else:
34-
raise ValueError('Invalid api key or heroku url')
43+
raise ValueError("Invalid api key or heroku url")
3544

36-
return StreamClient(api_key, api_secret, app_id, version, timeout,
37-
location=location, base_url=base_url)
45+
return StreamClient(
46+
api_key,
47+
api_secret,
48+
app_id,
49+
version,
50+
timeout,
51+
location=location,
52+
base_url=base_url,
53+
)

stream/collections.py

+26-16
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
class Collections(object):
2-
32
def __init__(self, client, token):
43
"""
54
Used to manipulate data at the 'meta' endpoint
@@ -15,7 +14,7 @@ def create_reference(self, collection_name, id):
1514
if isinstance(id, (dict,)) and id.get("id") is not None:
1615
_id = id.get("id")
1716
return "SO:%s:%s" % (collection_name, _id)
18-
17+
1918
def upsert(self, collection_name, data):
2019
"""
2120
"Insert new or update existing data.
@@ -33,8 +32,12 @@ def upsert(self, collection_name, data):
3332

3433
data_json = {collection_name: data}
3534

36-
response = self.client.post('collections/', service_name='api',
37-
signature=self.token, data={'data': data_json})
35+
response = self.client.post(
36+
"collections/",
37+
service_name="api",
38+
signature=self.token,
39+
data={"data": data_json},
40+
)
3841
return response
3942

4043
def select(self, collection_name, ids):
@@ -56,11 +59,15 @@ def select(self, collection_name, ids):
5659

5760
foreign_ids = []
5861
for i in range(len(ids)):
59-
foreign_ids.append('%s:%s' % (collection_name, ids[i]))
60-
foreign_ids = ','.join(foreign_ids)
62+
foreign_ids.append("%s:%s" % (collection_name, ids[i]))
63+
foreign_ids = ",".join(foreign_ids)
6164

62-
response = self.client.get('collections/', service_name='api', params={'foreign_ids': foreign_ids},
63-
signature=self.token)
65+
response = self.client.get(
66+
"collections/",
67+
service_name="api",
68+
params={"foreign_ids": foreign_ids},
69+
signature=self.token,
70+
)
6471

6572
return response
6673

@@ -80,17 +87,16 @@ def delete_many(self, collection_name, ids):
8087
ids = [ids]
8188
ids = [str(i) for i in ids]
8289

83-
params = {'collection_name': collection_name, 'ids': ids}
90+
params = {"collection_name": collection_name, "ids": ids}
8491

85-
response = self.client.delete('collections/', service_name='api', params=params,
86-
signature=self.token)
92+
response = self.client.delete(
93+
"collections/", service_name="api", params=params, signature=self.token
94+
)
8795

8896
return response
8997

9098
def add(self, collection_name, data, id=None, user_id=None):
91-
payload = dict(
92-
id=id, data=data, user_id=user_id,
93-
)
99+
payload = dict(id=id, data=data, user_id=user_id)
94100
return self.client.post(
95101
"collections/%s" % collection_name,
96102
service_name="api",
@@ -100,7 +106,9 @@ def add(self, collection_name, data, id=None, user_id=None):
100106

101107
def get(self, collection_name, id):
102108
return self.client.get(
103-
"collections/%s/%s" % (collection_name, id), service_name="api", signature=self.token
109+
"collections/%s/%s" % (collection_name, id),
110+
service_name="api",
111+
signature=self.token,
104112
)
105113

106114
def update(self, collection_name, id, data=None):
@@ -114,5 +122,7 @@ def update(self, collection_name, id, data=None):
114122

115123
def delete(self, collection_name, id):
116124
return self.client.delete(
117-
"collections/%s/%s" % (collection_name, id), service_name="api", signature=self.token
125+
"collections/%s/%s" % (collection_name, id),
126+
service_name="api",
127+
signature=self.token,
118128
)

stream/exceptions.py

+46-33
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,4 @@
1-
2-
31
class StreamApiException(Exception):
4-
52
def __init__(self, error_message, status_code=None):
63
Exception.__init__(self, error_message)
74
self.detail = error_message
@@ -11,78 +8,87 @@ def __init__(self, error_message, status_code=None):
118
code = 1
129

1310
def __repr__(self):
14-
return '%s (%s)' % (self.__class__.__name__, self.detail)
11+
return "%s (%s)" % (self.__class__.__name__, self.detail)
1512

1613
def __unicode__(self):
17-
return '%s (%s)' % (self.__class__.__name__, self.detail)
14+
return "%s (%s)" % (self.__class__.__name__, self.detail)
1815

1916

2017
class ApiKeyException(StreamApiException):
2118

22-
'''
19+
"""
2320
Raised when there is an issue with your Access Key
24-
'''
21+
"""
22+
2523
status_code = 401
2624
code = 2
2725

2826

2927
class SignatureException(StreamApiException):
3028

31-
'''
29+
"""
3230
Raised when there is an issue with the signature you provided
33-
'''
31+
"""
32+
3433
status_code = 401
3534
code = 3
3635

3736

3837
class InputException(StreamApiException):
3938

40-
'''
39+
"""
4140
Raised when you send the wrong data to the API
42-
'''
41+
"""
42+
4343
status_code = 400
4444
code = 4
4545

4646

4747
class CustomFieldException(StreamApiException):
4848

49-
'''
49+
"""
5050
Raised when there are missing or misconfigured custom fields
51-
'''
51+
"""
52+
5253
status_code = 400
5354
code = 5
5455

5556

5657
class FeedConfigException(StreamApiException):
5758

58-
'''
59+
"""
5960
Raised when there are missing or misconfigured custom fields
60-
'''
61+
"""
62+
6163
status_code = 400
6264
code = 6
6365

6466

6567
class SiteSuspendedException(StreamApiException):
6668

67-
'''
69+
"""
6870
Raised when the site requesting the data is suspended
69-
'''
71+
"""
72+
7073
status_code = 401
7174
code = 7
7275

76+
7377
class InvalidPaginationException(StreamApiException):
7478

75-
'''
79+
"""
7680
Raised when there is an issue with your Access Key
77-
'''
81+
"""
82+
7883
status_code = 401
7984
code = 8
8085

8186

8287
class MissingRankingException(FeedConfigException):
83-
'''
88+
"""
8489
Raised when you didn't configure the ranking for the given feed
85-
'''
90+
"""
91+
8692
status_code = 400
8793
code = 12
8894

@@ -93,57 +99,64 @@ class MissingUserException(MissingRankingException):
9399

94100

95101
class RankingException(FeedConfigException):
96-
'''
102+
"""
97103
Raised when there is a runtime issue with ranking the feed
98-
'''
104+
"""
105+
99106
status_code = 400
100107
code = 11
101108

102109

103110
class RateLimitReached(StreamApiException):
104111

105-
'''
112+
"""
106113
Raised when too many requests are performed
107-
'''
114+
"""
115+
108116
status_code = 429
109117
code = 9
110118

111119

112120
class OldStorageBackend(StreamApiException):
113-
'''
121+
"""
114122
Raised if you try to perform an action which only works with the new storage
115-
'''
123+
"""
124+
116125
status_code = 400
117126
code = 13
118127

119128

120129
class BestPracticeException(StreamApiException):
121-
'''
130+
"""
122131
Raised if best practices are enforced and you do something that
123132
would break a high volume integration
124-
'''
133+
"""
134+
125135
status_code = 400
126136
code = 15
127137

128138

129139
class DoesNotExistException(StreamApiException):
130-
'''
140+
"""
131141
Raised when the requested resource could not be found.
132-
'''
142+
"""
143+
133144
status_code = 404
134145
code = 16
135146

136147

137148
class NotAllowedException(StreamApiException):
138-
'''
149+
"""
139150
Raised when the requested action is not allowed for some reason.
140-
'''
151+
"""
152+
141153
status_code = 403
142154
code = 17
143155

144156

145157
def get_exceptions():
146158
from stream import exceptions
159+
147160
classes = []
148161
for k in dir(exceptions):
149162
a = getattr(exceptions, k)

stream/feed.py

+7-7
Original file line numberDiff line numberDiff line change
@@ -132,16 +132,16 @@ def get(self, enrich=False, reactions=None, **params):
132132
else:
133133
feed_url = self.feed_url
134134

135-
if reactions is not None and not isinstance(reactions, (dict, )):
135+
if reactions is not None and not isinstance(reactions, (dict,)):
136136
raise TypeError("reactions argument should be a dictionary")
137137

138138
if reactions is not None:
139-
if reactions.get('own'):
140-
params['withOwnReactions'] = True
141-
if reactions.get('recent'):
142-
params['withRecentReactions'] = True
143-
if reactions.get('counts'):
144-
params['withReactionCounts'] = True
139+
if reactions.get("own"):
140+
params["withOwnReactions"] = True
141+
if reactions.get("recent"):
142+
params["withRecentReactions"] = True
143+
if reactions.get("counts"):
144+
params["withReactionCounts"] = True
145145

146146
response = self.client.get(feed_url, params=params, signature=token)
147147
return response

0 commit comments

Comments
 (0)