fb-python-sdk 1.2.1__py3-none-any.whl → 1.2.2__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- {fb_python_sdk-1.2.1.dist-info → fb_python_sdk-1.2.2.dist-info}/METADATA +51 -34
- fb_python_sdk-1.2.2.dist-info/RECORD +26 -0
- {fb_python_sdk-1.2.1.dist-info → fb_python_sdk-1.2.2.dist-info}/WHEEL +1 -2
- fbclient/__init__.py +2 -2
- fbclient/category.py +4 -4
- fbclient/client.py +137 -62
- fbclient/common_types.py +107 -73
- fbclient/config.py +115 -76
- fbclient/data_storage.py +21 -12
- fbclient/evaluator.py +161 -125
- fbclient/event_processor.py +64 -33
- fbclient/event_types.py +29 -23
- fbclient/flag_change_notification.py +55 -33
- fbclient/interfaces.py +18 -11
- fbclient/notice_broadcaster.py +18 -12
- fbclient/status.py +26 -11
- fbclient/status_types.py +18 -12
- fbclient/streaming.py +166 -93
- fbclient/update_processor.py +7 -2
- fbclient/utils/__init__.py +47 -26
- fbclient/utils/exponential_backoff_jitter_strategy.py +14 -8
- fbclient/utils/http_client.py +48 -34
- fbclient/utils/repeatable_task.py +13 -5
- fbclient/utils/rwlock.py +7 -7
- fbclient/utils/variation_splitting_algorithm.py +6 -4
- fb_python_sdk-1.2.1.dist-info/RECORD +0 -27
- fb_python_sdk-1.2.1.dist-info/top_level.txt +0 -1
- {fb_python_sdk-1.2.1.dist-info → fb_python_sdk-1.2.2.dist-info}/licenses/LICENSE +0 -0
fbclient/utils/http_client.py
CHANGED
|
@@ -6,26 +6,29 @@ from typing import List, Mapping, Optional, Union
|
|
|
6
6
|
|
|
7
7
|
import certifi
|
|
8
8
|
import urllib3
|
|
9
|
+
|
|
9
10
|
from fbclient.config import Config, HTTPConfig
|
|
10
11
|
from fbclient.interfaces import Sender
|
|
11
12
|
from fbclient.utils import build_headers, log
|
|
12
13
|
|
|
13
14
|
|
|
14
15
|
def build_http_factory(config: Config, headers=None):
|
|
15
|
-
return HTTPFactory(
|
|
16
|
-
|
|
17
|
-
|
|
16
|
+
return HTTPFactory(
|
|
17
|
+
build_headers(config.env_secret, headers if headers is not None else {}),
|
|
18
|
+
config.http,
|
|
19
|
+
)
|
|
18
20
|
|
|
19
21
|
|
|
20
22
|
class HTTPFactory:
|
|
21
|
-
|
|
22
23
|
def __init__(self, headers, http_config: HTTPConfig):
|
|
23
24
|
"""
|
|
24
25
|
:param override_read_timeout override default read timeout at streaming update
|
|
25
26
|
"""
|
|
26
27
|
self.__headers = headers
|
|
27
28
|
self.__http_config = http_config
|
|
28
|
-
self.__timeout = urllib3.Timeout(
|
|
29
|
+
self.__timeout = urllib3.Timeout(
|
|
30
|
+
connect=http_config.connect_timeout, read=http_config.read_timeout
|
|
31
|
+
)
|
|
29
32
|
|
|
30
33
|
@property
|
|
31
34
|
def headers(self) -> Mapping[str, str]:
|
|
@@ -39,69 +42,78 @@ class HTTPFactory:
|
|
|
39
42
|
def timeout(self) -> urllib3.Timeout:
|
|
40
43
|
return self.__timeout
|
|
41
44
|
|
|
42
|
-
def create_http_client(
|
|
45
|
+
def create_http_client(
|
|
46
|
+
self, num_pools=1, max_size=10
|
|
47
|
+
) -> Union[urllib3.PoolManager, urllib3.ProxyManager]:
|
|
43
48
|
proxy_url = self.__http_config.http_proxy
|
|
44
49
|
|
|
45
50
|
if self.__http_config.disable_ssl_verification:
|
|
46
|
-
cert_reqs =
|
|
51
|
+
cert_reqs = "CERT_NONE"
|
|
47
52
|
ca_certs = None
|
|
48
53
|
else:
|
|
49
|
-
cert_reqs =
|
|
54
|
+
cert_reqs = "CERT_REQUIRED"
|
|
50
55
|
ca_certs = self.__http_config.ca_certs or certifi.where()
|
|
51
56
|
|
|
52
57
|
if not proxy_url:
|
|
53
|
-
return urllib3.PoolManager(
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
58
|
+
return urllib3.PoolManager(
|
|
59
|
+
num_pools=num_pools,
|
|
60
|
+
maxsize=max_size,
|
|
61
|
+
headers=self.__headers,
|
|
62
|
+
timeout=self.__timeout,
|
|
63
|
+
cert_reqs=cert_reqs,
|
|
64
|
+
ca_certs=ca_certs,
|
|
65
|
+
cert_file=self.__http_config.cert_file,
|
|
66
|
+
)
|
|
60
67
|
else:
|
|
61
68
|
url = urllib3.util.parse_url(proxy_url)
|
|
62
69
|
if url.auth:
|
|
63
70
|
proxy_headers = urllib3.util.make_headers(proxy_basic_auth=url.auth)
|
|
64
71
|
elif self.__http_config.http_proxy_auth:
|
|
65
72
|
auth = self.__http_config.http_proxy_auth
|
|
66
|
-
proxy_headers = urllib3.util.make_headers(
|
|
73
|
+
proxy_headers = urllib3.util.make_headers(
|
|
74
|
+
proxy_basic_auth=f"{auth[0]}:{auth[1]}"
|
|
75
|
+
)
|
|
67
76
|
else:
|
|
68
77
|
proxy_headers = None
|
|
69
78
|
|
|
70
|
-
return urllib3.ProxyManager(
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
+
return urllib3.ProxyManager(
|
|
80
|
+
proxy_url,
|
|
81
|
+
num_pools=num_pools,
|
|
82
|
+
maxsize=max_size,
|
|
83
|
+
headers=self.__headers,
|
|
84
|
+
proxy_headers=proxy_headers,
|
|
85
|
+
timeout=self.__timeout,
|
|
86
|
+
cert_reqs=cert_reqs,
|
|
87
|
+
ca_certs=ca_certs,
|
|
88
|
+
cert_file=self.__http_config.cert_file,
|
|
89
|
+
)
|
|
79
90
|
|
|
80
91
|
|
|
81
92
|
class DefaultSender(Sender):
|
|
82
|
-
|
|
83
93
|
def __init__(self, name: str, config: Config, num_pools=1, max_size=10):
|
|
84
94
|
self.__http = build_http_factory(config).create_http_client(num_pools, max_size)
|
|
85
95
|
self.__retry_interval = config.events_retry_interval
|
|
86
96
|
self.__max_retries = config.events_max_retries
|
|
87
97
|
self.__name = name
|
|
88
98
|
|
|
89
|
-
def postJson(
|
|
99
|
+
def postJson(
|
|
100
|
+
self, url: str, json_str: str, fetch_response: bool = True
|
|
101
|
+
) -> Optional[str]:
|
|
90
102
|
for i in range(self.__max_retries + 1):
|
|
91
103
|
try:
|
|
92
104
|
if i > 0:
|
|
93
105
|
sleep(self.__retry_interval)
|
|
94
|
-
response = self.__http.request(
|
|
106
|
+
response = self.__http.request("POST", url, body=json_str)
|
|
95
107
|
if response.status == 200:
|
|
96
|
-
log.debug(
|
|
97
|
-
resp = response.data.decode(
|
|
108
|
+
log.debug("sending ok")
|
|
109
|
+
resp = response.data.decode("utf-8")
|
|
98
110
|
return resp if fetch_response else None
|
|
99
111
|
except Exception as e:
|
|
100
|
-
log.exception(
|
|
112
|
+
log.exception("FB Python SDK: sending error: %s" % str(e))
|
|
101
113
|
return None
|
|
102
114
|
|
|
103
115
|
def stop(self):
|
|
104
|
-
log.debug(
|
|
116
|
+
log.debug("%s sender is stopping..." % self.__name)
|
|
105
117
|
self.__http.clear()
|
|
106
118
|
|
|
107
119
|
|
|
@@ -111,7 +123,7 @@ class SendingJsonInfo:
|
|
|
111
123
|
self.size = len(payloads)
|
|
112
124
|
|
|
113
125
|
def is_contain_user(self, key: str) -> bool:
|
|
114
|
-
return any(payload[
|
|
126
|
+
return any(payload["user"]["keyId"] == key for payload in self.__payloads)
|
|
115
127
|
|
|
116
128
|
|
|
117
129
|
class MockSender(Sender):
|
|
@@ -124,7 +136,9 @@ class MockSender(Sender):
|
|
|
124
136
|
self.fake_error_on_close = None
|
|
125
137
|
self.closed = False
|
|
126
138
|
|
|
127
|
-
def postJson(
|
|
139
|
+
def postJson(
|
|
140
|
+
self, url: str, json_str: str, fetch_response: bool = True
|
|
141
|
+
) -> Optional[str]:
|
|
128
142
|
payloads = json.loads(json_str)
|
|
129
143
|
self.__buffer.put(SendingJsonInfo(payloads))
|
|
130
144
|
if self.thread_num > 0 and not self.__ready.is_set():
|
|
@@ -11,8 +11,9 @@ from fbclient.utils import log
|
|
|
11
11
|
|
|
12
12
|
|
|
13
13
|
class RepeatableTask(Thread):
|
|
14
|
-
|
|
15
|
-
|
|
14
|
+
def __init__(
|
|
15
|
+
self, name: str, interval: float, callable: Callable, args=(), kwargs=None
|
|
16
|
+
):
|
|
16
17
|
super().__init__(name=name, daemon=True)
|
|
17
18
|
self._interval = interval
|
|
18
19
|
self._callable = callable
|
|
@@ -29,7 +30,9 @@ class RepeatableTask(Thread):
|
|
|
29
30
|
if current_thread() is not self and self.is_alive():
|
|
30
31
|
self.join(timeout)
|
|
31
32
|
if self.is_alive():
|
|
32
|
-
log.warning(
|
|
33
|
+
log.warning(
|
|
34
|
+
"FB Python SDK: %s repeatable task did not stop in time" % self.name
|
|
35
|
+
)
|
|
33
36
|
|
|
34
37
|
def run(self):
|
|
35
38
|
log.debug("%s repeatable task is starting..." % self.name)
|
|
@@ -39,6 +42,11 @@ class RepeatableTask(Thread):
|
|
|
39
42
|
try:
|
|
40
43
|
self._callable(*self._args, **self._kwargs)
|
|
41
44
|
except Exception as e:
|
|
42
|
-
log.exception(
|
|
45
|
+
log.exception(
|
|
46
|
+
"FB Python SDK: unexpected exception on %s repeatable task: %s"
|
|
47
|
+
% (self.name, str(e))
|
|
48
|
+
)
|
|
43
49
|
delay = next_time - time()
|
|
44
|
-
stopped =
|
|
50
|
+
stopped = (
|
|
51
|
+
self._stop_event.wait(delay) if delay > 0 else self._stop_event.is_set()
|
|
52
|
+
)
|
fbclient/utils/rwlock.py
CHANGED
|
@@ -7,7 +7,7 @@ import threading
|
|
|
7
7
|
|
|
8
8
|
|
|
9
9
|
class ReadWriteLock:
|
|
10
|
-
"""
|
|
10
|
+
"""A lock object that allows many simultaneous "read locks", but
|
|
11
11
|
only one "write lock." """
|
|
12
12
|
|
|
13
13
|
def __init__(self):
|
|
@@ -15,25 +15,25 @@ class ReadWriteLock:
|
|
|
15
15
|
self._readers = 0
|
|
16
16
|
|
|
17
17
|
def read_lock(self):
|
|
18
|
-
"""
|
|
19
|
-
acquired the write lock.
|
|
18
|
+
"""Acquire a read lock. Blocks only if a thread has
|
|
19
|
+
acquired the write lock."""
|
|
20
20
|
with self._read_ready:
|
|
21
21
|
self._readers += 1
|
|
22
22
|
|
|
23
23
|
def release_read_lock(self):
|
|
24
|
-
"""
|
|
24
|
+
"""Release a read lock."""
|
|
25
25
|
with self._read_ready:
|
|
26
26
|
self._readers = self._readers - 1 if self._readers > 0 else 0
|
|
27
27
|
if self._readers == 0:
|
|
28
28
|
self._read_ready.notify_all()
|
|
29
29
|
|
|
30
30
|
def write_lock(self):
|
|
31
|
-
"""
|
|
32
|
-
acquired read or write locks.
|
|
31
|
+
"""Acquire a write lock. Blocks until there are no
|
|
32
|
+
acquired read or write locks."""
|
|
33
33
|
self._read_ready.acquire()
|
|
34
34
|
while self._readers > 0:
|
|
35
35
|
self._read_ready.wait()
|
|
36
36
|
|
|
37
37
|
def release_write_lock(self):
|
|
38
|
-
"""
|
|
38
|
+
"""Release a write lock."""
|
|
39
39
|
self._read_ready.release()
|
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
|
|
2
1
|
import hashlib
|
|
3
2
|
from typing import List
|
|
4
3
|
|
|
@@ -15,11 +14,14 @@ class VariationSplittingAlgorithm:
|
|
|
15
14
|
if self.__percentage_range[0] == 0 and self.__percentage_range[1] == 1:
|
|
16
15
|
return True
|
|
17
16
|
percentage = self.__percentage_of_key()
|
|
18
|
-
return
|
|
17
|
+
return (
|
|
18
|
+
percentage >= self.__percentage_range[0]
|
|
19
|
+
and percentage < self.__percentage_range[1]
|
|
20
|
+
)
|
|
19
21
|
except:
|
|
20
22
|
return False
|
|
21
23
|
|
|
22
24
|
def __percentage_of_key(self) -> float:
|
|
23
|
-
digest = hashlib.md5(self.__key.encode(encoding=
|
|
24
|
-
magic_num = int.from_bytes(digest[:4], byteorder=
|
|
25
|
+
digest = hashlib.md5(self.__key.encode(encoding="utf-8")).digest()
|
|
26
|
+
magic_num = int.from_bytes(digest[:4], byteorder="little", signed=True)
|
|
25
27
|
return abs(magic_num / __MIN_INT__)
|
|
@@ -1,27 +0,0 @@
|
|
|
1
|
-
fb_python_sdk-1.2.1.dist-info/licenses/LICENSE,sha256=Pp1Gaxzlu2F3GAFJ314grnBHifZdIK7_ZvCFV_khanM,1064
|
|
2
|
-
fbclient/__init__.py,sha256=ApEOR6dqgunNQ1mCeazg28z69DNRzVpQS39ApQ8Mf2M,2193
|
|
3
|
-
fbclient/category.py,sha256=DzblPnzVwsPKK_FSnLkK3HyWXStbNdPiRfdgSoEODVY,1058
|
|
4
|
-
fbclient/client.py,sha256=xs0umr11WXNp3XwLFaEgr5clQUMIO7_gLqUu1QmseSs,21356
|
|
5
|
-
fbclient/common_types.py,sha256=XucV9zKLIEN7KLlMOcvgY02nzslq98W0TGQiA0pAslk,11686
|
|
6
|
-
fbclient/config.py,sha256=jP0QEoSKpUdvKdm2mjFpd_Vz0y2v5njFCQotasykbSs,9482
|
|
7
|
-
fbclient/data_storage.py,sha256=FEOeoPLUZ2G1xJCa59XYtIgzIFsuqZHLKs2nP_NO8QQ,4632
|
|
8
|
-
fbclient/evaluator.py,sha256=oz0hItG5AXChezCJYMK4Z_oagSNKQKcZzNeiDKtbgYw,11271
|
|
9
|
-
fbclient/event_processor.py,sha256=DW2J2VhTxEv1EdWrUfWWot6q6VFNSzeCw9qANPZESDU,11681
|
|
10
|
-
fbclient/event_types.py,sha256=MMp-d7NJ67gHjFXYoKp1I-Azv6Kh7__tnesW5vUgWEE,4510
|
|
11
|
-
fbclient/flag_change_notification.py,sha256=0JTd2w7nkgJtawKlnqmdB6JFQ_mcpLU2L3y_FNvdUQM,8664
|
|
12
|
-
fbclient/interfaces.py,sha256=YJ454VaIfOdGIgaNjZn6DxnW_-VkITwR3FYblTrXiZs,10461
|
|
13
|
-
fbclient/notice_broadcaster.py,sha256=5LGfY-D_TVU29qJqj8lJ5cskL3c7EWFcewZoNX6_Bpk,3231
|
|
14
|
-
fbclient/status.py,sha256=gn5rl8yowdyze8IbvgZThI50Xic_xKpPqtgrJswdaKA,5992
|
|
15
|
-
fbclient/status_types.py,sha256=-xB4zf2qHPNE1GHOSkO1h3SJ_5vQZqrvOymBVvvh5ts,3160
|
|
16
|
-
fbclient/streaming.py,sha256=f7xlXmbmryQ8olJDSEb2fvM36bACWG9WCIj1Lp2jRwU,16825
|
|
17
|
-
fbclient/update_processor.py,sha256=GCri2RzYSXuE-3nMtRJZRKrj0b1vtd4-rW1RpjG6bro,937
|
|
18
|
-
fbclient/utils/__init__.py,sha256=oMDgzVDtPbbtiFNur7Q8ui1EEw825b7aQro45R8tATM,4372
|
|
19
|
-
fbclient/utils/exponential_backoff_jitter_strategy.py,sha256=xZk7Y0yi3__U8c3DaX3PRb55vZAsRX__Rna3b2Wj9JA,1950
|
|
20
|
-
fbclient/utils/http_client.py,sha256=1G9mGVvU4X166VFoQyL43ORvpzTVPGZCuoDve_R75j4,5754
|
|
21
|
-
fbclient/utils/repeatable_task.py,sha256=mLkxlUkfHHmT5OOKlbh3vE1QrAH9JPecErvrwqsNgtc,1835
|
|
22
|
-
fbclient/utils/rwlock.py,sha256=BfgKYNwZ8y63yk-CphlFTCZ1-0Txh4XQ8Pzh2pohh5A,1159
|
|
23
|
-
fbclient/utils/variation_splitting_algorithm.py,sha256=4_qBeVANWIFPacifmV1zl_JZXywOd-wv1fQmnb8qyAE,864
|
|
24
|
-
fb_python_sdk-1.2.1.dist-info/METADATA,sha256=Rejf71BqyRbHNKxEnArvfnUMcKib0A1A0NmBXNSiCsE,15600
|
|
25
|
-
fb_python_sdk-1.2.1.dist-info/WHEEL,sha256=mOdXR9C3wMVov7cSY8PY-XCzo3SmmWCHvGQr5csJoao,91
|
|
26
|
-
fb_python_sdk-1.2.1.dist-info/top_level.txt,sha256=m0lqkwRY4CCAR7ABfB47YE1I62JGd4v0yixam1hlTZk,9
|
|
27
|
-
fb_python_sdk-1.2.1.dist-info/RECORD,,
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
fbclient
|
|
File without changes
|