Skip to content

Commit 3c8f140

Browse files
committed
Merge remote-tracking branch 'origin/master' into pk/events_uri
Conflicts: testing/test_integration.py
2 parents 7aaebeb + 3f6b617 commit 3c8f140

25 files changed

+131
-63
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+
pass

ldclient/client.py

Lines changed: 17 additions & 8 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
events_uri='https://events.launchdarkly.com',
@@ -79,6 +80,7 @@ def default(cls):
7980

8081

8182
class InMemoryFeatureStore(FeatureStore):
83+
8284
def __init__(self):
8385
self._lock = ReadWriteLock()
8486
self._initialized = False
@@ -142,6 +144,7 @@ def initialized(self):
142144

143145

144146
class LDClient(object):
147+
145148
def __init__(self, api_key, config=None):
146149
check_uwsgi()
147150
self._api_key = api_key
@@ -152,15 +155,17 @@ def __init__(self, api_key, config=None):
152155
self._offline = False
153156
self._lock = Lock()
154157

155-
self._store = config.feature_store_class()
158+
self._store = self._config.feature_store_class()
156159
""" :type: FeatureStore """
157160

158-
self._feature_requester = config.feature_requester_class(api_key, config)
161+
self._feature_requester = self._config.feature_requester_class(
162+
api_key, self._config)
159163
""" :type: FeatureRequester """
160164

161165
self._stream_processor = None
162166
if self._config.stream:
163-
self._stream_processor = config.stream_processor_class(api_key, config, self._store)
167+
self._stream_processor = self._config.stream_processor_class(
168+
api_key, self._config, self._store)
164169
self._stream_processor.start()
165170

166171
@property
@@ -170,7 +175,8 @@ def api_key(self):
170175
def _check_consumer(self):
171176
with self._lock:
172177
if not self._consumer or not self._consumer.is_alive():
173-
self._consumer = self._config.consumer_class(self._queue, self._api_key, self._config)
178+
self._consumer = self._config.consumer_class(
179+
self._queue, self._api_key, self._config)
174180
self._consumer.start()
175181

176182
def _stop_consumers(self):
@@ -190,7 +196,8 @@ def _send(self, event):
190196
self._queue.put(event)
191197

192198
def track(self, event_name, user, data=None):
193-
self._send({'kind': 'custom', 'key': event_name, 'user': user, 'data': data})
199+
self._send({'kind': 'custom', 'key': event_name,
200+
'user': user, 'data': data})
194201

195202
def identify(self, user):
196203
self._send({'kind': 'identify', 'key': user['key'], 'user': user})
@@ -229,7 +236,8 @@ def cb(feature):
229236
val = _evaluate(feature, user)
230237
if val is None:
231238
val = default
232-
self._send({'kind': 'feature', 'key': key, 'user': user, 'value': val})
239+
self._send({'kind': 'feature', 'key': key,
240+
'user': user, 'value': val})
233241
return val
234242

235243
if self._config.stream and self._store.initialized:
@@ -239,7 +247,8 @@ def cb(feature):
239247
try:
240248
return self._feature_requester.get(key, cb)
241249
except Exception:
242-
log.exception('Unhandled exception. Returning default value for flag.')
250+
log.exception(
251+
'Unhandled exception. Returning default value for flag.')
243252
return cb(None)
244253

245-
__all__ = ['LDClient', 'Config']
254+
__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)