gomyck-tools 1.2.0__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.
ctools/api_result.py CHANGED
@@ -2,8 +2,6 @@ from ctools import cjson
2
2
 
3
3
  cjson.str_value_keys = [
4
4
  "obj_id",
5
- "script_id",
6
- "template_id"
7
5
  ]
8
6
 
9
7
 
ctools/cjson.py CHANGED
@@ -6,7 +6,7 @@ jsonpickle.set_preferred_backend('json')
6
6
  jsonpickle.set_encoder_options('json', ensure_ascii=False)
7
7
  jsonpickle.set_decoder_options('json')
8
8
 
9
- def dumps(obj) -> str:
9
+ def dumps(obj, **kwargs) -> str:
10
10
  """
11
11
  将对象转换为json字符串
12
12
  :param obj: 对象
@@ -14,18 +14,18 @@ def dumps(obj) -> str:
14
14
  """
15
15
  if obj is None: return None
16
16
  if type(obj) == str: return obj
17
- return f'{jsonpickle.encode(obj, unpicklable=False)}'
17
+ return f'{jsonpickle.encode(obj, unpicklable=False, make_refs=False, **kwargs)}'
18
18
 
19
- def loads(json_str: str) -> dict:
19
+ def loads(json_str: str, **kwargs) -> dict:
20
20
  """
21
21
  将json字符串转换为对象
22
22
  :param json_str: json 字符串
23
23
  :return: 对象
24
24
  """
25
- return jsonpickle.decode(json_str)
25
+ return jsonpickle.decode(json_str, **kwargs)
26
26
 
27
27
  def unify_to_str(json_str: str) -> str:
28
- if not str_value_keys: return json_str
28
+ if not str_value_keys and len(str_value_keys) == 0: return json_str
29
29
  obj = loads(json_str)
30
30
  if isinstance(obj, list):
31
31
  _handle_list(obj)
ctools/ckafka.py CHANGED
@@ -28,7 +28,7 @@ def send_msg():
28
28
  while True:
29
29
  command = input('发送消息: Y/n \n')
30
30
  if command.strip() not in ['N', 'n']:
31
- producer.send_msg('jqxx-lib', '{{"jqid": "{}", "xxxx": "{}=={}"}}'.format(string_tools.get_snowflake_id(), command.strip(), datetime.strftime(datetime.now(), '%Y-%m-%d %H:%M:%S')))
31
+ producer.send_msg('jqxx', '{{"jqid": "{}", "xxxx": "{}"}}'.format(string_tools.get_snowflake_id(), datetime.strftime(datetime.now(), '%Y-%m-%d %H:%M:%S')))
32
32
  else:
33
33
  break
34
34
 
@@ -38,9 +38,9 @@ def consumer_callback(msg):
38
38
  print(msg)
39
39
  return True
40
40
 
41
- consumer.receive_msg('jqxx-lib', callBack=consumer_callback)
41
+ consumer.receive_msg('jqxx', callBack=consumer_callback)
42
42
 
43
- time.sleep(10000)
43
+ while True: time.sleep(1)
44
44
  """
45
45
  class KafkaInstance:
46
46
  def __init__(self, producer: KafkaProducer, consumer: KafkaConsumer):
ctools/date_utils.py CHANGED
@@ -30,7 +30,7 @@ def get_file_time():
30
30
  获取 %Y-%m-%d %H:%M:%S 文件格式时间
31
31
  :return:
32
32
  """
33
- return time.strftime('%Y-%m-%d_%H-%M-%S', time.localtime(time.time()))
33
+ return time.strftime('%Y-%m-%d_%H-%M-%S-%s', time.localtime(time.time()))
34
34
 
35
35
  def get_timestamp(offset=0):
36
36
  return int(time.time() + offset)
ctools/dict_wrapper.py CHANGED
@@ -6,7 +6,9 @@ __date__ = '2024/10/25 09:42'
6
6
  class DictWrapper(dict):
7
7
  def __getattr__(self, key):
8
8
  res = self.get(key)
9
- if type(res) == dict:
9
+ if res is None:
10
+ raise AttributeError(f"'{key}' not found in this Entity")
11
+ if isinstance(res, dict):
10
12
  return DictWrapper(res)
11
13
  return res
12
14
 
ctools/rsa.py ADDED
@@ -0,0 +1,70 @@
1
+ import base64
2
+
3
+ from Crypto.Cipher import PKCS1_OAEP
4
+ from Crypto.PublicKey import RSA
5
+ from Crypto.Signature import pkcs1_15
6
+ from Crypto.Hash import SHA256
7
+
8
+ from ctools import work_path, cjson
9
+
10
+ ENCRYPT_CHUNK_SIZE = 245
11
+ decrypt_CHUNK_SIZE = 512
12
+
13
+ def generate_rsa_keypair(bits=2048):
14
+ key = RSA.generate(bits)
15
+ private_key = key.export_key() # 导出私钥
16
+ public_key = key.publickey().export_key() # 导出公钥
17
+ with open("private_key.pem", "wb") as f:
18
+ f.write(private_key)
19
+ with open("public_key.pem", "wb") as f:
20
+ f.write(public_key)
21
+
22
+ def loadLicenseInfo(auth_code):
23
+ with open(work_path.get_app_path() + '/keys/license.key', 'r') as pri:
24
+ decrypt_message = decrypt(auth_code.strip(), pri.read())
25
+ return cjson.loads(decrypt_message)
26
+
27
+ # 加密函数
28
+ def encrypt(msg, public_key):
29
+ parts = b''
30
+ public_key = RSA.import_key(public_key)
31
+ cipher = PKCS1_OAEP.new(public_key)
32
+ for i in range(0, len(msg), ENCRYPT_CHUNK_SIZE):
33
+ parts += cipher.encrypt(msg[i:i + ENCRYPT_CHUNK_SIZE].encode())
34
+ encrypted_base64 = base64.b64encode(parts)
35
+ return encrypted_base64.decode()
36
+
37
+ # 解密函数
38
+ def decrypt(msg, private_key):
39
+ parts = b''
40
+ public_key = RSA.import_key(private_key)
41
+ cipher = PKCS1_OAEP.new(public_key)
42
+ encrypted_bytes = base64.b64decode(msg)
43
+ for i in range(0, len(encrypted_bytes), decrypt_CHUNK_SIZE):
44
+ parts += cipher.decrypt(encrypted_bytes[i:i + decrypt_CHUNK_SIZE])
45
+ return parts.decode()
46
+
47
+ # 验签
48
+ def verify_sign(msg, public_key, sign):
49
+ public_key = RSA.import_key(public_key)
50
+ hash_message = SHA256.new(msg.encode())
51
+ try:
52
+ pkcs1_15.new(public_key).verify(hash_message, base64.b64decode(sign.encode()))
53
+ return True
54
+ except Exception as e:
55
+ print('签名验证失败: {}'.format(e))
56
+ return False
57
+
58
+ # 签名
59
+ def sign_msg(msg, private_key):
60
+ private_key = RSA.import_key(private_key)
61
+ hash_message = SHA256.new(msg.encode())
62
+ signature = pkcs1_15.new(private_key).sign(hash_message)
63
+ return base64.b64encode(signature).decode()
64
+
65
+
66
+ # with open(work_path.get_current_path() + '/private_key.pem', 'r') as key:
67
+ # key = key.read()
68
+ # sign = sign_msg(key, key)
69
+ # with open(work_path.get_current_path() + '/public_key.pem', 'r') as pub:
70
+ # print(verify_sign(key, pub.read(), sign+'123'))
ctools/sm_tools.py CHANGED
@@ -3,22 +3,35 @@ import base64
3
3
  from gmssl import sm2, func
4
4
  from gmssl.sm4 import CryptSM4, SM4_ENCRYPT, SM4_DECRYPT
5
5
 
6
- sm2_crypt: sm2.CryptSM2
6
+ sm2_crypt: sm2.CryptSM2 = None
7
7
 
8
+ def init(private_key: str, public_key: str):
9
+ global sm2_crypt
10
+ if sm2_crypt is not None:
11
+ print('sm2 is already init!!!')
12
+ return
13
+ sm2_crypt = sm2.CryptSM2(private_key=private_key, public_key=public_key, asn1=True, mode=1)
8
14
 
9
15
  def sign_with_sm2(sign_data: str) -> str:
10
- return sm2_crypt.sign(sign_data.encode('UTF-8'), func.random_hex(sm2_crypt.para_len))
16
+ if sm2_crypt is None: raise Exception('sm2 is not init!!!')
17
+ return sm2_crypt.sign_with_sm3(sign_data.encode('UTF-8'))
11
18
 
12
19
 
13
20
  def verify_with_sm2(sign_val: str, sign_data: str) -> bool:
14
- return sm2_crypt.verify(sign_val, sign_data.encode('UTF-8'))
15
-
21
+ if sm2_crypt is None: raise Exception('sm2 is not init!!!')
22
+ try:
23
+ return sm2_crypt.verify_with_sm3(sign_val, sign_data.encode('UTF-8'))
24
+ except Exception as e:
25
+ print('签名验证失败: {}'.format(e))
26
+ return False
16
27
 
17
28
  def encrypt_with_sm2(encrypt_data: str) -> str:
29
+ if sm2_crypt is None: raise Exception('sm2 is not init!!!')
18
30
  return base64.b64encode(sm2_crypt.encrypt(encrypt_data.encode('UTF-8'))).decode('UTF-8')
19
31
 
20
32
 
21
33
  def decrypt_with_sm2(encrypt_data: str) -> str:
34
+ if sm2_crypt is None: raise Exception('sm2 is not init!!!')
22
35
  return sm2_crypt.decrypt(base64.b64decode(encrypt_data.encode('UTF-8'))).decode('UTF-8')
23
36
 
24
37
 
@@ -0,0 +1,31 @@
1
+ Metadata-Version: 2.1
2
+ Name: gomyck-tools
3
+ Version: 1.2.2
4
+ Summary: A ctools for python development by hao474798383
5
+ Home-page: https://blog.gomyck.com
6
+ Author: gomyck
7
+ Author-email: hao474798383@163.com
8
+ Classifier: Programming Language :: Python :: 3
9
+ Classifier: License :: OSI Approved :: MIT License
10
+ Classifier: Operating System :: OS Independent
11
+ Requires-Python: >=3.8
12
+ Description-Content-Type: text/markdown
13
+ Requires-Dist: jsonpickle ~=3.4.2
14
+ Requires-Dist: SQLAlchemy ~=2.0.36
15
+ Requires-Dist: chardet ~=5.2.0
16
+ Requires-Dist: psycopg2-binary ~=2.9.10
17
+ Requires-Dist: croniter ~=5.0.1
18
+ Requires-Dist: gmssl ~=3.2.2
19
+ Requires-Dist: psutil ~=6.1.0
20
+ Requires-Dist: jsonpath-ng ~=1.7.0
21
+ Requires-Dist: bottle ~=0.13.2
22
+ Requires-Dist: requests ~=2.32.3
23
+ Requires-Dist: urllib3 ~=1.26.20
24
+ Requires-Dist: kafka-python ~=2.0.2
25
+ Requires-Dist: bs4 ~=0.0.2
26
+ Requires-Dist: paho-mqtt ~=2.1.0
27
+ Requires-Dist: fuzzywuzzy ~=0.18.0
28
+ Requires-Dist: pymysql ~=1.1.1
29
+ Requires-Dist: pyzipper ==0.3.6
30
+
31
+ this package is for python development
@@ -1,6 +1,6 @@
1
1
  ctools/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
2
2
  ctools/aes_tools.py,sha256=ylUgyhlx7bNCTGrbWEZVwCObzYdJTQtwEc4ZMidL2Fo,563
3
- ctools/api_result.py,sha256=NiM-R9K42G3m16B27sG_mqKrlexZzC5-LKoY8D5tO4s,1239
3
+ ctools/api_result.py,sha256=BLoJiTHFAIFRPCc4zer7NHTsRQFMY1TH-qmxSMk8iLU,1208
4
4
  ctools/application.py,sha256=DcuSt2m8cDuSftx6eKfJ5gA6_F9dDlzkj0K86EG4F7s,15884
5
5
  ctools/b64.py,sha256=_BdhX3p3-MaSSlU2wivN5qPxQfacR3VRBr1WC456tU0,194
6
6
  ctools/bashPath.py,sha256=BCN_EhYzqvwsxYso81omMNd3SbEociwSOyb9kLvu8V4,337
@@ -9,14 +9,14 @@ ctools/bottle_webserver.py,sha256=8w1oj6_P09an6Pdnr5dH9ClBiD-A6k27IBCSvqVfcTs,25
9
9
  ctools/bottle_websocket.py,sha256=wjsjKVE_tlon0hYfnzBT0Sis6yNPe318vKgTfzWYbfQ,1903
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
- ctools/cjson.py,sha256=M2XrXnFXTJyKsXP2JRos2Bse4b6WXjr6TrA6y-EF_Ig,1245
13
- ctools/ckafka.py,sha256=jD9n9sscKrU5spDlPGco681jhqVGRIXqwPiJUas3gpo,5965
12
+ ctools/cjson.py,sha256=g5OldDeD7bmdw_4NNNPfAREGXNplQxY_l9vtTz-UBTs,1331
13
+ ctools/ckafka.py,sha256=EiiGCFkSbq8yRjQKVjc2_V114hKb8fJAVIOks_XbQ3w,5944
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
17
17
  ctools/database.py,sha256=7YzkO2tzV1KUQLHND8g9PkQwTyGd3clhgPiZ5SbC-HA,5447
18
- ctools/date_utils.py,sha256=-xI2anEzAonOvYwVmM1hCnkuLKodZ8pb33dS3dRxEIc,865
19
- ctools/dict_wrapper.py,sha256=A6EOcI-aeYpK3yi6KmCkzShWG0gQcMmQV2lIWPzvn2U,310
18
+ ctools/date_utils.py,sha256=qkIvn2TGQ97vUw2ppBfHE7IyCUqg0s1FzrB0BJAsaBo,868
19
+ ctools/dict_wrapper.py,sha256=6lZUyHomdn5QdjQTg7EL1sC_I6tOlh8ofMRQT3XGQjM,398
20
20
  ctools/douglas_rarefy.py,sha256=43WRjGGsQ_o1yPEXypA1Xv_yuo90RVo7qaYGRslx5gQ,4890
21
21
  ctools/download_tools.py,sha256=oJbG12Hojd0J17sAlvMU480P3abi4_AB9oZkEBGFPuo,1930
22
22
  ctools/enums.py,sha256=QbHa3j7j4-BDdwaga5Y0nYfA2uNSVJDHumYdIZdKVkM,118
@@ -26,7 +26,6 @@ ctools/html_soup.py,sha256=rnr8M3gn3gQGo-wNaNFXDjdzp8AAkv9o4yqfIIfO-zw,1567
26
26
  ctools/http_utils.py,sha256=dG26aci1_YxAyKwYqMKFw4wZAryLkDyvnQ3hURjB6Lk,768
27
27
  ctools/images_tools.py,sha256=TapXYCPqC7GesgrALecxxa_ApuT_dxUG5fqQIJF2bNY,670
28
28
  ctools/imgDialog.py,sha256=zFeyPmpnEn9Ih7-yuJJrePqW8Myj3jC9UYMTDk-umTs,1385
29
- ctools/license.py,sha256=0Kh7lXL7LD1PQqyijHajFL0GbmZGNB88PA2WskbQn_s,1066
30
29
  ctools/metrics.py,sha256=vq9Fnq2fhmhS4yoHS4gO7ArKS033Eou8vpA779Uue0I,4414
31
30
  ctools/mqtt_utils.py,sha256=ZWSZiiNJLLlkHF95S6LmRmkYt-iIL4K73VdN3b1HaHw,10702
32
31
  ctools/obj.py,sha256=GYS1B8NyjtUIh0HlK9r8avC2eGbK2SJac4C1CGnfGhI,479
@@ -35,9 +34,10 @@ ctools/plan_area_tools.py,sha256=pySri43bVfkHjzlKujML-Nk8B3QLxuYv5KJMha-MLmU,331
35
34
  ctools/process_pool.py,sha256=1TuZySUbQjgYYcuwis54DIwQTimWvTLNahSra7Ia8Ps,951
36
35
  ctools/pty_tools.py,sha256=KI3dOyv2JLZmU1VfD1aLMq9r9d5VCu3TdtcezZayBEI,1622
37
36
  ctools/resource_bundle_tools.py,sha256=wA4fmD_ZEcrpcvUZKa60uDDX-nNQSVz1nBh0A2GVuTI,3796
37
+ ctools/rsa.py,sha256=c0q7oStlpSfTxmn900XMDjyOGS1A7tVsUIocr0nL2UI,2259
38
38
  ctools/screenshot_tools.py,sha256=KoljfgqW5x9aLwKdIfz0vR6v-fX4XjE92HudkDxC2hE,4539
39
39
  ctools/sign.py,sha256=JOkgpgsMbk7T3c3MOj1U6eiEndUG9XQ-uIX9e615A_Y,566
40
- ctools/sm_tools.py,sha256=RwhTjuKw_TjaAJAui39wctzFFpbt79MQ3hjF0fhL638,1113
40
+ ctools/sm_tools.py,sha256=CDfgupqs_nrZs-135ZvDu6QIx4aamJVdg7vuLs9_0yw,1678
41
41
  ctools/snow_id.py,sha256=hYinnRN-aOule4_9vfgXB7XnsU-56cIS3PhzAwWBc5E,2270
42
42
  ctools/strDiff.py,sha256=QUtXOfsRLTFozH_zByqsC39JeuG3eZtrwGVeLyaHYUI,429
43
43
  ctools/string_tools.py,sha256=p_O3HiqlHCgzJVXHUeeDYZK2_WrqetD0eYijQFXWkGg,1938
@@ -51,7 +51,7 @@ ctools/wordFill.py,sha256=dB1OLt6GLmWdkDV8H20VWbJmY4ggNNI8iHD1ocae2iM,875
51
51
  ctools/word_fill.py,sha256=xeo-P4DOjQUqd-o9XL3g66wQrE2diUPGwFywm8TdVyw,18210
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.2.0.dist-info/METADATA,sha256=fGkZEdcTWWnI6Nj3aEcuhexNSQaLlP9Wbte5bGEOIZc,972
55
- gomyck_tools-1.2.0.dist-info/WHEEL,sha256=yQN5g4mg4AybRjkgi-9yy4iQEFibGQmlz78Pik5Or-A,92
56
- gomyck_tools-1.2.0.dist-info/top_level.txt,sha256=-MiIH9FYRVKp1i5_SVRkaI-71WmF1sZSRrNWFU9ls3s,7
57
- gomyck_tools-1.2.0.dist-info/RECORD,,
54
+ gomyck_tools-1.2.2.dist-info/METADATA,sha256=CzDE6NMxpgyVbq_51yDC0b4mEE0IBkcuNI85aat7t7M,1004
55
+ gomyck_tools-1.2.2.dist-info/WHEEL,sha256=yQN5g4mg4AybRjkgi-9yy4iQEFibGQmlz78Pik5Or-A,92
56
+ gomyck_tools-1.2.2.dist-info/top_level.txt,sha256=-MiIH9FYRVKp1i5_SVRkaI-71WmF1sZSRrNWFU9ls3s,7
57
+ gomyck_tools-1.2.2.dist-info/RECORD,,
ctools/license.py DELETED
@@ -1,37 +0,0 @@
1
- import base64
2
-
3
- from Crypto.Cipher import PKCS1_OAEP
4
- from Crypto.PublicKey import RSA
5
-
6
- from ctools import work_path, cjson
7
-
8
- ENCRYPT_CHUNK_SIZE = 245
9
- decrypt_CHUNK_SIZE = 512
10
-
11
-
12
- # 加密函数
13
- def encrypt(msg, public_key):
14
- parts = b''
15
- private_key = RSA.import_key(public_key)
16
- cipher = PKCS1_OAEP.new(private_key)
17
- for i in range(0, len(msg), ENCRYPT_CHUNK_SIZE):
18
- parts += cipher.encrypt(msg[i:i + ENCRYPT_CHUNK_SIZE].encode())
19
- encrypted_base64 = base64.b64encode(parts)
20
- return encrypted_base64.decode()
21
-
22
-
23
- # 解密函数
24
- def decrypt(msg, private_key):
25
- parts = b''
26
- public_key = RSA.import_key(private_key)
27
- cipher = PKCS1_OAEP.new(public_key)
28
- encrypted_bytes = base64.b64decode(msg)
29
- for i in range(0, len(encrypted_bytes), decrypt_CHUNK_SIZE):
30
- parts += cipher.decrypt(encrypted_bytes[i:i + decrypt_CHUNK_SIZE])
31
- return parts.decode()
32
-
33
-
34
- def loadLicenseInfo(auth_code):
35
- with open(work_path.get_app_path() + '/keys/license.key', 'r') as pri:
36
- decrypt_message = decrypt(auth_code.strip(), pri.read())
37
- return cjson.loads(decrypt_message)
@@ -1,30 +0,0 @@
1
- Metadata-Version: 2.1
2
- Name: gomyck-tools
3
- Version: 1.2.0
4
- Summary: A ctools for python development by hao474798383
5
- Home-page: https://blog.gomyck.com
6
- Author: gomyck
7
- Author-email: hao474798383@163.com
8
- Classifier: Programming Language :: Python :: 3
9
- Classifier: License :: OSI Approved :: MIT License
10
- Classifier: Operating System :: OS Independent
11
- Requires-Python: >=3.8
12
- Description-Content-Type: text/markdown
13
- Requires-Dist: jsonpickle ==3.4.2
14
- Requires-Dist: SQLAlchemy >=2.0.36
15
- Requires-Dist: chardet >=5.2.0
16
- Requires-Dist: psycopg2-binary >=2.9.10
17
- Requires-Dist: croniter >=5.0.1
18
- Requires-Dist: gmssl >=3.2.2
19
- Requires-Dist: psutil >=6.1.0
20
- Requires-Dist: jsonpath-ng >=1.7.0
21
- Requires-Dist: bottle ==0.13.2
22
- Requires-Dist: requests ==2.32.3
23
- Requires-Dist: urllib3 ==1.26.20
24
- Requires-Dist: kafka-python ==2.0.2
25
- Requires-Dist: bs4 ==0.0.2
26
- Requires-Dist: paho-mqtt ==2.1.0
27
- Requires-Dist: fuzzywuzzy ==0.18.0
28
- Requires-Dist: pymysql ==1.1.1
29
-
30
- this package is for python development