gomyck-tools 1.1.4__py3-none-any.whl → 1.1.6__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.
- ctools/ckafka.py +8 -8
- ctools/http_utils.py +4 -2
- ctools/id_worker_tools.py +2 -14
- {gomyck_tools-1.1.4.dist-info → gomyck_tools-1.1.6.dist-info}/METADATA +1 -1
- {gomyck_tools-1.1.4.dist-info → gomyck_tools-1.1.6.dist-info}/RECORD +7 -7
- {gomyck_tools-1.1.4.dist-info → gomyck_tools-1.1.6.dist-info}/WHEEL +0 -0
- {gomyck_tools-1.1.4.dist-info → gomyck_tools-1.1.6.dist-info}/top_level.txt +0 -0
ctools/ckafka.py
CHANGED
@@ -101,7 +101,7 @@ class CKafka:
|
|
101
101
|
self.password = password
|
102
102
|
|
103
103
|
def init_producer(self, acks=1) -> KafkaInstance:
|
104
|
-
print("[ Producer ] Connecting to Kafka
|
104
|
+
print("[ Producer ] Connecting to Kafka [{}]".format(self.kafka_url))
|
105
105
|
for i in range(0, 6):
|
106
106
|
try:
|
107
107
|
if self.secure:
|
@@ -120,15 +120,15 @@ class CKafka:
|
|
120
120
|
bootstrap_servers=self.kafka_url,
|
121
121
|
value_serializer=lambda x: dumps(x).encode('utf-8')
|
122
122
|
)
|
123
|
-
print("[ Producer ] Connected to Kafka
|
123
|
+
print("[ Producer ] Success Connected to Kafka [{}]".format(self.kafka_url))
|
124
124
|
return KafkaInstance(producer=producer, consumer=None)
|
125
125
|
except errors.NoBrokersAvailable:
|
126
|
-
print("[ Producer ] Waiting for
|
126
|
+
print("[ Producer ] Waiting for Kafka [{}] to become available...".format(self.kafka_url))
|
127
127
|
time.sleep(3)
|
128
|
-
raise RuntimeError("[ Producer ] Failed to connect to
|
128
|
+
raise RuntimeError("[ Producer ] Failed to connect to Kafka [{}] within 60 seconds".format(self.kafka_url))
|
129
129
|
|
130
130
|
def init_consumer(self, client_id: str = 'ck-py-kafka-consumer', consumer_group: str = 'ck-py-kafka-consumer', enable_auto_commit: bool = True) -> KafkaInstance:
|
131
|
-
print("[ Consumer ] Connecting to Kafka
|
131
|
+
print("[ Consumer ] Connecting to Kafka [{}]".format(self.kafka_url))
|
132
132
|
for i in range(0, 6):
|
133
133
|
try:
|
134
134
|
if self.secure:
|
@@ -151,9 +151,9 @@ class CKafka:
|
|
151
151
|
bootstrap_servers=self.kafka_url,
|
152
152
|
value_deserializer=lambda x: x.decode('utf-8')
|
153
153
|
)
|
154
|
-
print("[ Consumer ] Connected to Kafka
|
154
|
+
print("[ Consumer ] Success Connected to Kafka [{}]".format(self.kafka_url))
|
155
155
|
return KafkaInstance(producer=None, consumer=consumer)
|
156
156
|
except errors.NoBrokersAvailable:
|
157
|
-
print("[ Consumer ] Waiting for
|
157
|
+
print("[ Consumer ] Waiting for Kafka [{}] to become available...".format(self.kafka_url))
|
158
158
|
time.sleep(3)
|
159
|
-
raise RuntimeError("[ Consumer ] Failed to connect to
|
159
|
+
raise RuntimeError("[ Consumer ] Failed to connect to Kafka [{}] within 60 seconds".format(self.kafka_url))
|
ctools/http_utils.py
CHANGED
@@ -10,7 +10,8 @@ def get(url, params=None, headers=None):
|
|
10
10
|
result = response.content
|
11
11
|
except Exception as e:
|
12
12
|
print("GET请求异常:", e)
|
13
|
-
return result.decode('utf-8')
|
13
|
+
if isinstance(result, bytes): return result.decode('utf-8')
|
14
|
+
return result
|
14
15
|
|
15
16
|
|
16
17
|
def post(url, data=None, json=None, headers=None, files=None):
|
@@ -19,4 +20,5 @@ def post(url, data=None, json=None, headers=None, files=None):
|
|
19
20
|
response.raise_for_status()
|
20
21
|
if response.status_code == 200:
|
21
22
|
result = response.content
|
22
|
-
return result.decode('utf-8')
|
23
|
+
if isinstance(result, bytes): return result.decode('utf-8')
|
24
|
+
return result
|
ctools/id_worker_tools.py
CHANGED
@@ -4,28 +4,22 @@ import time
|
|
4
4
|
WORKER_ID_BITS = 5
|
5
5
|
DATACENTER_ID_BITS = 5
|
6
6
|
SEQUENCE_BITS = 12
|
7
|
-
|
8
7
|
# 最大取值计算
|
9
8
|
MAX_WORKER_ID = -1 ^ (-1 << WORKER_ID_BITS) # 2**5-1 0b11111
|
10
9
|
MAX_DATACENTER_ID = -1 ^ (-1 << DATACENTER_ID_BITS)
|
11
|
-
|
12
10
|
# 移位偏移计算
|
13
11
|
WOKER_ID_SHIFT = SEQUENCE_BITS
|
14
12
|
DATACENTER_ID_SHIFT = SEQUENCE_BITS + WORKER_ID_BITS
|
15
13
|
TIMESTAMP_LEFT_SHIFT = SEQUENCE_BITS + WORKER_ID_BITS + DATACENTER_ID_BITS
|
16
|
-
|
17
14
|
# 序号循环掩码
|
18
15
|
SEQUENCE_MASK = -1 ^ (-1 << SEQUENCE_BITS)
|
19
|
-
|
20
16
|
# Twitter元年时间戳
|
21
17
|
TWEPOCH = 1288834974657
|
22
18
|
|
23
|
-
|
24
19
|
class IdWorker(object):
|
25
20
|
"""
|
26
21
|
用于生成IDs
|
27
22
|
"""
|
28
|
-
|
29
23
|
def __init__(self, datacenter_id, worker_id, sequence=0):
|
30
24
|
"""
|
31
25
|
初始化
|
@@ -36,17 +30,15 @@ class IdWorker(object):
|
|
36
30
|
# sanity check
|
37
31
|
if worker_id > MAX_WORKER_ID or worker_id < 0:
|
38
32
|
raise ValueError('worker_id值越界')
|
39
|
-
|
40
33
|
if datacenter_id > MAX_DATACENTER_ID or datacenter_id < 0:
|
41
34
|
raise ValueError('datacenter_id值越界')
|
42
|
-
|
43
35
|
self.worker_id = worker_id
|
44
36
|
self.datacenter_id = datacenter_id
|
45
37
|
self.sequence = sequence
|
46
|
-
|
47
38
|
self.last_timestamp = -1 # 上次计算的时间戳
|
48
39
|
|
49
|
-
|
40
|
+
@staticmethod
|
41
|
+
def _gen_timestamp():
|
50
42
|
"""
|
51
43
|
生成整数时间戳
|
52
44
|
:return:int timestamp
|
@@ -59,21 +51,17 @@ class IdWorker(object):
|
|
59
51
|
:return:
|
60
52
|
"""
|
61
53
|
timestamp = self._gen_timestamp()
|
62
|
-
|
63
54
|
# 时钟回拨
|
64
55
|
if timestamp < self.last_timestamp:
|
65
56
|
print('clock is moving backwards. Rejecting requests until {}'.format(self.last_timestamp))
|
66
57
|
raise
|
67
|
-
|
68
58
|
if timestamp == self.last_timestamp:
|
69
59
|
self.sequence = (self.sequence + 1) & SEQUENCE_MASK
|
70
60
|
if self.sequence == 0:
|
71
61
|
timestamp = self._til_next_millis(self.last_timestamp)
|
72
62
|
else:
|
73
63
|
self.sequence = 0
|
74
|
-
|
75
64
|
self.last_timestamp = timestamp
|
76
|
-
|
77
65
|
new_id = ((timestamp - TWEPOCH) << TIMESTAMP_LEFT_SHIFT) | (self.datacenter_id << DATACENTER_ID_SHIFT) | \
|
78
66
|
(self.worker_id << WOKER_ID_SHIFT) | self.sequence
|
79
67
|
return new_id
|
@@ -10,7 +10,7 @@ ctools/bottle_websocket.py,sha256=IRY17SpDFjihLeU8c_aUIMAfUNZzurqfrOyNFojOQHQ,18
|
|
10
10
|
ctools/browser_element_tools.py,sha256=IFR_tWu5on0LxhuC_4yT6EOjwCsC-juIoU8KQRDqR7E,9952
|
11
11
|
ctools/call.py,sha256=BCr8wzt5qd70okv8IZn-9-EpjywleZgvA3u1vfZ_Kt8,1581
|
12
12
|
ctools/cjson.py,sha256=M2XrXnFXTJyKsXP2JRos2Bse4b6WXjr6TrA6y-EF_Ig,1245
|
13
|
-
ctools/ckafka.py,sha256=
|
13
|
+
ctools/ckafka.py,sha256=jD9n9sscKrU5spDlPGco681jhqVGRIXqwPiJUas3gpo,5965
|
14
14
|
ctools/compile_tools.py,sha256=Nybh3vnkurIKnPnubdYzigjnzFu4GaTMKPvqFdibxmE,510
|
15
15
|
ctools/console.py,sha256=EZumuyynwteKUhUxB_XoulHswDxHd75OQB34RiZ-OBM,1807
|
16
16
|
ctools/cron_lite.py,sha256=f9g7-64GsCxcAW-HUAvT6S-kooScl8zaJyqwHY-X_rE,8308
|
@@ -23,8 +23,8 @@ ctools/enums.py,sha256=QbHa3j7j4-BDdwaga5Y0nYfA2uNSVJDHumYdIZdKVkM,118
|
|
23
23
|
ctools/ex.py,sha256=_UtbmDLrC7uZsoBtTdecuCZAlf2DA7fvojUf5fGZDVo,795
|
24
24
|
ctools/excelOpt.py,sha256=q3HLAb1JScTrMCvx_x-4WWnqKhyTEzQ-m5vtqFy8NZU,1138
|
25
25
|
ctools/html_soup.py,sha256=LabCo4yWI58fbFBPhunk3THWBf0BbHEWLgwyvSpTGR4,1903
|
26
|
-
ctools/http_utils.py,sha256=
|
27
|
-
ctools/id_worker_tools.py,sha256=
|
26
|
+
ctools/http_utils.py,sha256=dG26aci1_YxAyKwYqMKFw4wZAryLkDyvnQ3hURjB6Lk,768
|
27
|
+
ctools/id_worker_tools.py,sha256=M4ehNKbVIrBhPs-GlVKEZ43WQArNb9s4UoVGgRit4YM,2356
|
28
28
|
ctools/images_tools.py,sha256=TapXYCPqC7GesgrALecxxa_ApuT_dxUG5fqQIJF2bNY,670
|
29
29
|
ctools/imgDialog.py,sha256=zFeyPmpnEn9Ih7-yuJJrePqW8Myj3jC9UYMTDk-umTs,1385
|
30
30
|
ctools/license.py,sha256=0Kh7lXL7LD1PQqyijHajFL0GbmZGNB88PA2WskbQn_s,1066
|
@@ -51,7 +51,7 @@ ctools/wordFill.py,sha256=dB1OLt6GLmWdkDV8H20VWbJmY4ggNNI8iHD1ocae2iM,875
|
|
51
51
|
ctools/word_fill.py,sha256=aIkzjAF2soSW6w2dO2CRZlveDcuIdr6v9DtyyyB8uxM,18216
|
52
52
|
ctools/word_fill_entity.py,sha256=eX3G0Gy16hfGpavQSEkCIoKDdTnNgRRJrFvKliETZK8,985
|
53
53
|
ctools/work_path.py,sha256=i4MTUobqNW2WMrT3mwEC_XYQ0_IhFmKoNpTX2W6A8Tc,1680
|
54
|
-
gomyck_tools-1.1.
|
55
|
-
gomyck_tools-1.1.
|
56
|
-
gomyck_tools-1.1.
|
57
|
-
gomyck_tools-1.1.
|
54
|
+
gomyck_tools-1.1.6.dist-info/METADATA,sha256=FtquWWxsN-ePwUGQcR7qMBA4dBwKIbF_rCNFqKgzFNM,940
|
55
|
+
gomyck_tools-1.1.6.dist-info/WHEEL,sha256=yQN5g4mg4AybRjkgi-9yy4iQEFibGQmlz78Pik5Or-A,92
|
56
|
+
gomyck_tools-1.1.6.dist-info/top_level.txt,sha256=-MiIH9FYRVKp1i5_SVRkaI-71WmF1sZSRrNWFU9ls3s,7
|
57
|
+
gomyck_tools-1.1.6.dist-info/RECORD,,
|
File without changes
|
File without changes
|