Skip to content

Commit b3987a4

Browse files
committed
Merge pull request #31 from launchdarkly/autopep8
Make all files follow PEP8 styling
2 parents 72b770f + 475003c commit b3987a4

25 files changed

+127
-61
lines changed

demo/demo.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,4 +4,4 @@
44
if __name__ == '__main__':
55
apiKey = 'feefifofum'
66
client = LDClient(apiKey)
7-
print(client.api_key)
7+
print(client.api_key)

demo/demo_twisted.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,4 +18,4 @@ def main(_):
1818
print("Value: {}".format(val))
1919

2020
if __name__ == '__main__':
21-
task.react(main)
21+
task.react(main)

ldclient/__init__.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,11 +7,13 @@
77

88
__LONG_SCALE__ = float(0xFFFFFFFFFFFFFFF)
99

10-
__BUILTINS__ = ["key", "ip", "country", "email", "firstName", "lastName", "avatar", "name", "anonymous"]
10+
__BUILTINS__ = ["key", "ip", "country", "email",
11+
"firstName", "lastName", "avatar", "name", "anonymous"]
1112

1213

1314
# Add a NullHandler for Python < 2.7 compatibility
1415
class NullHandler(logging.Handler):
16+
1517
def emit(self, record):
1618
pass
1719

@@ -32,4 +34,4 @@ def emit(self, record):
3234
try:
3335
from .twisted_impls import *
3436
except ImportError:
35-
print("Twisted support not available")
37+
print("Twisted support not available")

ldclient/client.py

Lines changed: 16 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222

2323

2424
class Config(object):
25+
2526
def __init__(self,
2627
base_uri='https://app.launchdarkly.com',
2728
connect_timeout=2,
@@ -77,6 +78,7 @@ def default(cls):
7778

7879

7980
class InMemoryFeatureStore(FeatureStore):
81+
8082
def __init__(self):
8183
self._lock = ReadWriteLock()
8284
self._initialized = False
@@ -140,6 +142,7 @@ def initialized(self):
140142

141143

142144
class LDClient(object):
145+
143146
def __init__(self, api_key, config=None):
144147
check_uwsgi()
145148
self._api_key = api_key
@@ -153,12 +156,14 @@ def __init__(self, api_key, config=None):
153156
self._store = config.feature_store_class()
154157
""" :type: FeatureStore """
155158

156-
self._feature_requester = config.feature_requester_class(api_key, config)
159+
self._feature_requester = config.feature_requester_class(
160+
api_key, config)
157161
""" :type: FeatureRequester """
158162

159163
self._stream_processor = None
160164
if self._config.stream:
161-
self._stream_processor = config.stream_processor_class(api_key, config, self._store)
165+
self._stream_processor = config.stream_processor_class(
166+
api_key, config, self._store)
162167
self._stream_processor.start()
163168

164169
@property
@@ -168,7 +173,8 @@ def api_key(self):
168173
def _check_consumer(self):
169174
with self._lock:
170175
if not self._consumer or not self._consumer.is_alive():
171-
self._consumer = self._config.consumer_class(self._queue, self._api_key, self._config)
176+
self._consumer = self._config.consumer_class(
177+
self._queue, self._api_key, self._config)
172178
self._consumer.start()
173179

174180
def _stop_consumers(self):
@@ -188,7 +194,8 @@ def _send(self, event):
188194
self._queue.put(event)
189195

190196
def track(self, event_name, user, data=None):
191-
self._send({'kind': 'custom', 'key': event_name, 'user': user, 'data': data})
197+
self._send({'kind': 'custom', 'key': event_name,
198+
'user': user, 'data': data})
192199

193200
def identify(self, user):
194201
self._send({'kind': 'identify', 'key': user['key'], 'user': user})
@@ -227,7 +234,8 @@ def cb(feature):
227234
val = _evaluate(feature, user)
228235
if val is None:
229236
val = default
230-
self._send({'kind': 'feature', 'key': key, 'user': user, 'value': val})
237+
self._send({'kind': 'feature', 'key': key,
238+
'user': user, 'value': val})
231239
return val
232240

233241
if self._config.stream and self._store.initialized:
@@ -237,7 +245,8 @@ def cb(feature):
237245
try:
238246
return self._feature_requester.get(key, cb)
239247
except Exception:
240-
log.exception('Unhandled exception. Returning default value for flag.')
248+
log.exception(
249+
'Unhandled exception. Returning default value for flag.')
241250
return cb(None)
242251

243-
__all__ = ['LDClient', 'Config']
252+
__all__ = ['LDClient', 'Config']

ldclient/expiringdict.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@
3131

3232

3333
class ExpiringDict(OrderedDict):
34+
3435
def __init__(self, max_len, max_age_seconds):
3536
assert max_age_seconds >= 0
3637
assert max_len >= 1

ldclient/interfaces.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -129,4 +129,4 @@ def get(self, key, callback):
129129
:param callback: The function that accepts the feature data and returns the feature value
130130
:type callback: function
131131
:return: The feature value. None if not found
132-
"""
132+
"""

ldclient/noop.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,4 +7,4 @@ def __init__(self, *_):
77
pass
88

99
def get(self, key, callback):
10-
return None
10+
return None

ldclient/redis_requester.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ def create_redis_ldd_requester(api_key, config, **kwargs):
1010

1111

1212
class ForgetfulDict(dict):
13+
1314
def __setitem__(self, key, value):
1415
pass
1516

@@ -19,6 +20,7 @@ class RedisLDDRequester(FeatureRequester):
1920
Requests features from redis, usually stored via the LaunchDarkly Daemon (LDD). Recommended to be combined
2021
with the ExpiringInMemoryFeatureStore
2122
"""
23+
2224
def __init__(self, config,
2325
expiration=15,
2426
redis_host='localhost',
@@ -36,7 +38,8 @@ def __init__(self, config,
3638

3739
def _get_connection(self):
3840
if self._pool is None:
39-
self._pool = redis.ConnectionPool(host=self._redis_host, port=self._redis_port)
41+
self._pool = redis.ConnectionPool(
42+
host=self._redis_host, port=self._redis_port)
4043
return redis.Redis(connection_pool=self._pool)
4144

4245
def get(self, key, callback):

ldclient/requests.py

Lines changed: 17 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -29,27 +29,32 @@ def do_toggle(should_retry):
2929
except ProtocolError as e:
3030
inner = e.args[1]
3131
if inner.errno == errno.ECONNRESET and should_retry:
32-
log.warning('ProtocolError exception caught while getting flag. Retrying.')
32+
log.warning(
33+
'ProtocolError exception caught while getting flag. Retrying.')
3334
return do_toggle(False)
3435
else:
35-
log.exception('Unhandled exception. Returning default value for flag.')
36+
log.exception(
37+
'Unhandled exception. Returning default value for flag.')
3638
return None
3739
except Exception:
38-
log.exception('Unhandled exception. Returning default value for flag.')
40+
log.exception(
41+
'Unhandled exception. Returning default value for flag.')
3942
return None
4043

4144
return callback(do_toggle(True))
4245

4346
def _toggle(self, key):
4447
hdrs = _headers(self._api_key)
4548
uri = self._config.base_uri + '/api/eval/features/' + key
46-
r = self._session.get(uri, headers=hdrs, timeout=(self._config.connect, self._config.read))
49+
r = self._session.get(uri, headers=hdrs, timeout=(
50+
self._config.connect, self._config.read))
4751
r.raise_for_status()
4852
feature = r.json()
4953
return feature
5054

5155

5256
class RequestsStreamProcessor(Thread, StreamProcessor):
57+
5358
def __init__(self, api_key, config, store):
5459
Thread.__init__(self)
5560
self.daemon = True
@@ -91,6 +96,7 @@ def process_message(store, msg):
9196

9297

9398
class RequestsEventConsumer(Thread, EventConsumer):
99+
94100
def __init__(self, event_queue, api_key, config):
95101
Thread.__init__(self)
96102
self._session = requests.Session()
@@ -128,12 +134,15 @@ def do_send(should_retry):
128134
except ProtocolError as e:
129135
inner = e.args[1]
130136
if inner.errno == errno.ECONNRESET and should_retry:
131-
log.warning('ProtocolError exception caught while sending events. Retrying.')
137+
log.warning(
138+
'ProtocolError exception caught while sending events. Retrying.')
132139
do_send(False)
133140
else:
134-
log.exception('Unhandled exception in event consumer. Analytics events were not processed.')
141+
log.exception(
142+
'Unhandled exception in event consumer. Analytics events were not processed.')
135143
except:
136-
log.exception('Unhandled exception in event consumer. Analytics events were not processed.')
144+
log.exception(
145+
'Unhandled exception in event consumer. Analytics events were not processed.')
137146

138147
try:
139148
do_send(True)
@@ -172,4 +181,4 @@ def next_item(self):
172181
item = q.get(block=True, timeout=5)
173182
return item
174183
except Exception:
175-
return None
184+
return None

ldclient/rwlock.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,4 +37,4 @@ def lock(self):
3737

3838
def unlock(self):
3939
""" Release a write lock. """
40-
self._read_ready.release()
40+
self._read_ready.release()

0 commit comments

Comments
 (0)