ezKit 1.7.7__py3-none-any.whl → 1.7.8__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.
ezKit/__init__.py CHANGED
@@ -1 +0,0 @@
1
- # from . import bottle, database, files, plots, utils, weixin, zabbix
ezKit/cipher.py CHANGED
@@ -1,9 +1,9 @@
1
- '''
1
+ """
2
2
  https://docs.python.org/3.10/library/hashlib.html
3
3
  https://www.pycrypto.org/
4
4
  https://stackoverflow.com/a/21928790
5
5
  pip install pycryptodome
6
- '''
6
+ """
7
7
  import base64
8
8
  import hashlib
9
9
 
@@ -12,7 +12,8 @@ from Crypto.Cipher import AES
12
12
  from loguru import logger
13
13
 
14
14
 
15
- class AESCipher(object):
15
+ class AESCipher:
16
+ """AESCipher"""
16
17
 
17
18
  def __init__(self, key: str = 'vB7DoRm9C2Kd', algorithm: str = 'sha256'):
18
19
 
@@ -40,10 +41,10 @@ class AESCipher(object):
40
41
  self.key = hashlib.sha3_384(key.encode()).digest()
41
42
  case True if algorithm == 'sha3_512':
42
43
  self.key = hashlib.sha3_512(key.encode()).digest()
43
- case True if algorithm == 'shake_128':
44
- self.key = hashlib.shake_128(key.encode()).digest()
45
- case True if algorithm == 'shake_256':
46
- self.key = hashlib.shake_256(key.encode()).digest()
44
+ # case True if algorithm == 'shake_128':
45
+ # self.key = hashlib.shake_128(key.encode()).digest()
46
+ # case True if algorithm == 'shake_256':
47
+ # self.key = hashlib.shake_256(key.encode()).digest()
47
48
  case _:
48
49
  self.key = hashlib.sha256(key.encode()).digest()
49
50
 
@@ -59,10 +60,10 @@ class AESCipher(object):
59
60
 
60
61
  def decrypt(self, enc: str) -> str | None:
61
62
  try:
62
- enc = base64.b64decode(enc)
63
- iv = enc[:AES.block_size]
63
+ enc_bytes = base64.b64decode(enc)
64
+ iv = enc_bytes[:AES.block_size]
64
65
  cipher = AES.new(self.key, AES.MODE_CBC, iv)
65
- return self._unpad(cipher.decrypt(enc[AES.block_size:])).decode('utf-8')
66
+ return self._unpad(cipher.decrypt(enc_bytes[AES.block_size:])).decode('utf-8')
66
67
  except Exception as e:
67
68
  logger.exception(e)
68
69
  return None
ezKit/database.py CHANGED
@@ -14,13 +14,14 @@ from sqlalchemy import Index, create_engine, text
14
14
  from . import utils
15
15
 
16
16
 
17
- class Database(object):
17
+ class Database():
18
+ """Database"""
18
19
 
19
20
  engine = create_engine('sqlite://')
20
21
 
21
- def __init__(self, engine_url=None, engine_options=None):
22
+ def __init__(self, engine_url, **engine_options):
22
23
  '''Initiation'''
23
- if engine_url != None:
24
+ if engine_url is not None:
24
25
  if utils.v_true(engine_options, dict):
25
26
  self.engine = create_engine(engine_url, **engine_options)
26
27
  else:
@@ -68,8 +69,8 @@ class Database(object):
68
69
  idx = Index(index_name, table_field)
69
70
  try:
70
71
  idx.drop(bind=self.engine)
71
- except:
72
- pass
72
+ except Exception as e:
73
+ logger.exception(e)
73
74
  idx.create(bind=self.engine)
74
75
  logger.success(f'{info}[成功]')
75
76
  return True
@@ -86,7 +87,8 @@ class Database(object):
86
87
  outcsv.writerows(data)
87
88
  return True
88
89
  except Exception as e:
89
- logger.exception(e) if echo == True else next
90
+ if echo is True:
91
+ logger.exception(e)
90
92
  return False
91
93
 
92
94
  def execute(self, sql=None, sql_file=None, sql_file_kwargs=None, csv_file=None, csv_file_kwargs=None, echo=True):
@@ -104,12 +106,13 @@ class Database(object):
104
106
  sql_object = None
105
107
  info = f'{info_prefix}提取SQL'
106
108
  try:
107
- logger.info(f'{info}......') if echo == True else next
109
+ if echo is True:
110
+ logger.info(f'{info}......')
108
111
  if utils.v_true(sql, str):
109
112
  sql_object = sql
110
113
  elif utils.v_true(sql_file, str):
111
114
  # 判断文件是否存在
112
- if utils.check_file_type(sql_file, 'file') == False:
115
+ if utils.check_file_type(sql_file, 'file') is False:
113
116
  logger.error(f'文件不存在: {sql_file}') if echo == True else next
114
117
  return False
115
118
  # 读取文件内容
ezKit/mongo.py CHANGED
@@ -1,6 +1,7 @@
1
1
  """MongoDB"""
2
2
  from loguru import logger
3
3
  from pymongo import MongoClient
4
+ from pymongo.collection import Collection
4
5
 
5
6
  from . import utils
6
7
 
@@ -10,39 +11,41 @@ class Mongo():
10
11
 
11
12
  client = MongoClient()
12
13
 
13
- def close(self):
14
+ def close(self) -> bool:
14
15
  """client close"""
15
16
  try:
16
17
  self.client.close()
18
+ return True
17
19
  except Exception as e:
18
20
  logger.exception(e)
21
+ return False
19
22
 
20
- def connect_test(self, debug: bool = False):
21
- """client connect test"""
22
- info = 'MongoDB连接测试'
23
+ def connect_test(self) -> bool:
24
+ info = "MongoDB connect test"
23
25
  try:
24
- logger.info(f'{info}[执行]')
26
+ logger.info(f"{info} ......")
25
27
  self.client.server_info()
26
- logger.success(f'{info}[成功]')
28
+ logger.success(f"{info} [success]")
27
29
  return True
28
30
  except Exception as e:
29
- logger.error(f'{info}[失败]')
30
- if utils.v_true(debug, bool):
31
- logger.exception(e)
31
+ logger.error(f"{info} [failed]")
32
+ logger.exception(e)
32
33
  return False
33
34
 
34
- def collection(self, database, name):
35
- """client collection"""
36
- return self.client[database][name]
35
+ def collection(self, database: str, name: str) -> Collection | None:
36
+ try:
37
+ return self.client[database][name]
38
+ except Exception as e:
39
+ logger.exception(e)
40
+ return None
37
41
 
38
- def collection_insert(self, database, collection, data, drop=None):
39
- """client collection insert"""
42
+ def collection_insert(self, database, collection, data, drop: bool = False):
40
43
  db_collection = self.client[database][collection]
41
- info = '插入数据'
44
+ info = "MongoDB collection insert"
42
45
  try:
43
- logger.info(f'{info}[执行]')
46
+ logger.info(f"{info} ......")
44
47
  # 是否删除 collection
45
- if drop is True:
48
+ if utils.v_true(drop, bool):
46
49
  # 删除 collection
47
50
  db_collection.drop()
48
51
  # 插入数据
@@ -53,12 +56,12 @@ class Mongo():
53
56
  # 插入多条数据
54
57
  result = db_collection.insert_many(data)
55
58
  else:
56
- logger.error(f'{info}[失败]')
57
- logger.error('数据类型错误')
59
+ logger.error(f"{info} [failed]")
60
+ logger.error("Data type error")
58
61
  return False
59
- logger.success(f'{info}[成功]')
62
+ logger.success(f"{info} [success]")
60
63
  return result
61
64
  except Exception as e:
62
- logger.error(f'{info}[失败]')
65
+ logger.error(f"{info} [failed]")
63
66
  logger.exception(e)
64
67
  return False
ezKit/qywx.py CHANGED
@@ -1,3 +1,14 @@
1
+ """
2
+ 企业微信开发者中心
3
+
4
+ https://developer.work.weixin.qq.com/
5
+ https://developer.work.weixin.qq.com/document/path/90313 (全局错误码)
6
+
7
+ 参考文档:
8
+
9
+ https://www.gaoyuanqi.cn/python-yingyong-qiyewx/
10
+ https://www.jianshu.com/p/020709b130d3
11
+ """
1
12
  import json
2
13
  import time
3
14
 
@@ -7,21 +18,9 @@ from loguru import logger
7
18
  from . import utils
8
19
 
9
20
 
10
- class QYWX(object):
21
+ class QYWX:
11
22
  """企业微信"""
12
23
 
13
- """
14
- 企业微信开发者中心
15
-
16
- https://developer.work.weixin.qq.com/
17
- https://developer.work.weixin.qq.com/document/path/90313 (全局错误码)
18
-
19
- 参考文档:
20
-
21
- https://www.gaoyuanqi.cn/python-yingyong-qiyewx/
22
- https://www.jianshu.com/p/020709b130d3
23
- """
24
-
25
24
  url_prefix = 'https://qyapi.weixin.qq.com'
26
25
  work_id: str | None = None
27
26
  agent_id: str | None = None
ezKit/redis.py CHANGED
@@ -1,10 +1,12 @@
1
+ """Redis"""
1
2
  import redis as RedisClient
2
3
  from loguru import logger
3
4
 
4
5
  from . import utils
5
6
 
6
7
 
7
- class Redis(object):
8
+ class Redis:
9
+ """Redis"""
8
10
 
9
11
  # https://redis.readthedocs.io/en/stable/_modules/redis/client.html#Redis
10
12
  # https://github.com/redis/redis-py#client-classes-redis-and-strictredis
@@ -14,38 +16,38 @@ class Redis(object):
14
16
  # 这里修改以下参数: host, port, socket_timeout, socket_connect_timeout, charset
15
17
  redis = RedisClient.Redis()
16
18
 
17
- def __init__(self, arguments=None):
18
- '''Initiation'''
19
- if utils.v_true(arguments, str):
19
+ def __init__(self, arguments: str | dict):
20
+ """Initiation"""
21
+ if isinstance(arguments, str) and utils.v_true(arguments, str):
20
22
  self.redis = RedisClient.from_url(arguments)
21
- elif utils.v_true(arguments, dict):
23
+
24
+ if isinstance(arguments, dict) and utils.v_true(arguments, dict):
22
25
  self.redis = RedisClient.Redis(**arguments)
23
- else:
24
- pass
25
26
 
26
- def connect_test(self):
27
- info = 'Redis连接测试'
27
+ def connect_test(self) -> bool:
28
+ info = "Redis connect test"
28
29
  try:
29
- logger.info(f'{info}......')
30
+ logger.info(f"{info} ......")
30
31
  self.redis.ping()
31
- logger.success(f'{info}[成功]')
32
+ logger.success(f"{info} [success]")
32
33
  return True
33
34
  except Exception as e:
34
- logger.error(f'{info}[失败]')
35
+ logger.error(f"{info} [failed]")
35
36
  logger.exception(e)
36
37
  return False
37
38
 
38
- def flush(self, all=None):
39
- info = 'Redis数据清理'
39
+ def flush(self, flushall: bool = False) -> bool:
40
+ info = "Redis flush"
40
41
  try:
41
- logger.info(f'{info}......')
42
- if all == True:
42
+ if utils.v_true(flushall, bool):
43
+ logger.info(f"{info} all ......")
43
44
  self.redis.flushall()
44
45
  else:
46
+ logger.info(f"{info} db ......")
45
47
  self.redis.flushdb()
46
- logger.success(f'{info}[成功]')
48
+ logger.success(f"{info} [success]")
47
49
  return True
48
50
  except Exception as e:
49
- logger.error(f'{info}[失败]')
51
+ logger.error(f"{info} [failed]")
50
52
  logger.exception(e)
51
53
  return False
ezKit/sendemail.py CHANGED
@@ -1,6 +1,4 @@
1
- """
2
- 发送邮件
3
- """
1
+ """发送邮件"""
4
2
  # https://stackoverflow.com/questions/882712/sending-html-email-using-python
5
3
  # pylint: disable=E0611
6
4
  # pylint: disable=R0911
ezKit/token.py CHANGED
@@ -4,33 +4,32 @@ from typing import Any
4
4
 
5
5
  from loguru import logger
6
6
 
7
- from .cipher import AESCipher
8
- from .utils import datetime_now, datetime_offset, datetime_string_to_datetime, datetime_to_string, v_true
7
+ from . import cipher, utils
9
8
 
10
9
 
11
10
  def generate_token(key: str = 'Fc0zXCmGKd7tPu6W', timeout: int = 3600, data: Any = None) -> (str | None):
12
11
  try:
13
- now = datetime_now()
12
+ now = utils.datetime_now()
14
13
 
15
14
  if now is None:
16
15
  return None
17
16
 
18
- offset = datetime_offset(now, seconds=+timeout)
17
+ offset = utils.datetime_offset(now, seconds=+timeout)
19
18
 
20
19
  if offset is None:
21
20
  return None
22
21
 
23
22
  source = json.dumps(
24
23
  obj={
25
- "datetime": datetime_to_string(offset),
24
+ "datetime": utils.datetime_to_string(offset),
26
25
  "data": data
27
26
  },
28
27
  default=str
29
28
  )
30
29
 
31
- cipher = AESCipher(key=key, algorithm='sha256')
30
+ aes_cipher = cipher.AESCipher(key=key, algorithm='sha256')
32
31
 
33
- return cipher.encrypt(source)
32
+ return aes_cipher.encrypt(source)
34
33
 
35
34
  except Exception as e:
36
35
  logger.exception(e)
@@ -39,19 +38,19 @@ def generate_token(key: str = 'Fc0zXCmGKd7tPu6W', timeout: int = 3600, data: Any
39
38
 
40
39
  def parsing_token(token_string: str, key: str = 'Fc0zXCmGKd7tPu6W') -> (dict | None):
41
40
  try:
42
- if v_true(token_string, str) is False:
41
+ if utils.v_true(token_string, str) is False:
43
42
  return None
44
43
 
45
- cipher = AESCipher(key=key, algorithm='sha256')
44
+ aes_cipher = cipher.AESCipher(key=key, algorithm='sha256')
46
45
 
47
- target = cipher.decrypt(token_string)
46
+ target = aes_cipher.decrypt(token_string)
48
47
 
49
48
  if target is None:
50
49
  return None
51
50
 
52
51
  source: dict = json.loads(target)
53
52
 
54
- source['datetime'] = datetime_string_to_datetime(source['datetime'])
53
+ source['datetime'] = utils.datetime_string_to_datetime(source['datetime'])
55
54
 
56
55
  return source
57
56
 
@@ -68,7 +67,7 @@ def certify_token(token_string: str, key: str = 'Fc0zXCmGKd7tPu6W') -> bool:
68
67
  if result is None:
69
68
  return False
70
69
 
71
- if result.get('datetime') < datetime_now(): # type: ignore
70
+ if result.get('datetime') < utils.datetime_now(): # type: ignore
72
71
  return False
73
72
 
74
73
  return True
ezKit/utils.py CHANGED
@@ -1,6 +1,4 @@
1
- """
2
- Python Utils
3
- """
1
+ """Utils"""
4
2
  import csv
5
3
  import datetime
6
4
  import hashlib
@@ -49,6 +47,10 @@ def v_true(
49
47
  List list/tuple/set []/()/{}
50
48
  Dictionary dict {}
51
49
 
50
+ 查看变量类型: type(x)
51
+
52
+ 判断变量类型: isinstance(x, str)
53
+
52
54
  函数使用 callable(func) 判断
53
55
  """
54
56
 
@@ -623,7 +625,7 @@ def dict_remove_key(
623
625
  data: dict,
624
626
  key: str,
625
627
  debug: bool = False
626
- ) -> None | dict:
628
+ ) -> dict | None:
627
629
  """dict remove key"""
628
630
  try:
629
631
  data_copy: dict = deepcopy(data)
ezKit/xftp.py CHANGED
@@ -54,7 +54,7 @@ class XFTP:
54
54
  logger.success("FTP connect closed")
55
55
  return True
56
56
 
57
- def get_file_list(self, target='/') -> (list[str] | None):
57
+ def get_file_list(self, target='/') -> list[str] | None:
58
58
  """Get file list"""
59
59
  try:
60
60
  self.chdir_to_remote(target)
@@ -63,7 +63,7 @@ class XFTP:
63
63
  logger.exception(e)
64
64
  return None
65
65
 
66
- def get_file_size(self, file, target="/") -> (int | None):
66
+ def get_file_size(self, file, target="/") -> int | None:
67
67
  """Get file size"""
68
68
  try:
69
69
  self.chdir_to_remote(target)
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: ezKit
3
- Version: 1.7.7
3
+ Version: 1.7.8
4
4
  Summary: Easy Kit
5
5
  Author: septvean
6
6
  Author-email: septvean@gmail.com
@@ -0,0 +1,22 @@
1
+ ezKit/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
2
+ ezKit/bottle.py,sha256=0lLLrzgAWhPj47KOdyITIsPRNUFGuwovA3vRW47SpUs,180117
3
+ ezKit/bottle_extensions.py,sha256=OQUwHNg4cbZ0UZXwT6FJjwl4uAg00_Q-Zpogt_xHElk,1088
4
+ ezKit/cipher.py,sha256=uVUzeoYg5ZPJLpqg2wLst-7vfdDGmqWKka9Oyi0WrCA,2883
5
+ ezKit/database.py,sha256=DNwjWzaJ3kLWVnwe3-zU0fJa-_IsKk6jeyGWdiyF94Q,6794
6
+ ezKit/files.py,sha256=GoNdai3Ul0lg4wTkJAQm5kys1Sv3NCTNLIZlzHQKuZQ,12714
7
+ ezKit/http.py,sha256=LTeyPVBm8deL_m-YRVW2O5w83-k3b1I1hU4cqkxS_B0,1845
8
+ ezKit/mongo.py,sha256=ueTFKJuorvtkchoItmH7dbwzJ-V0YUxfHdeqHPv6DGc,2045
9
+ ezKit/plots.py,sha256=QUtoVfZ49ZSNcY8gcQ2TYVkMjDDzoW-myMtqTi5WN2U,5322
10
+ ezKit/qywx.py,sha256=AQaJUIthnB1nHrtnjn2YEW-cBdlR_5xMaHDweiiUsK0,6490
11
+ ezKit/redis.py,sha256=KdvoSyFiAZSzsV_GowSUsL-TI0o6GXK8yw4YgyO4Rm0,1938
12
+ ezKit/reports.py,sha256=dBBggggCCLuk5YD6SjdUPuxTr3wiJojP3lA7dQfg6Pk,8898
13
+ ezKit/sendemail.py,sha256=Hypoy9zEIcq28BH-5ydiYq2ysoajTSWhtz8yVMpyOAU,8411
14
+ ezKit/token.py,sha256=9CAZhPdXiRiWoOIeWmP0q6L3j1zQAv4YcVWH95Tjefs,1755
15
+ ezKit/utils.py,sha256=fBGRdrX23JN9zJ_gj7CIgcf9-S0wq961O_pKyLYU9Ds,48917
16
+ ezKit/xftp.py,sha256=7BABr-gjxZxK2UXoW9XxN76i1HdubeaomYlYMqRurHE,7770
17
+ ezKit/zabbix.py,sha256=soM5UEeYMfm7NczbPOVLirmHm3G20dECQ0aCBttZfhQ,28350
18
+ ezKit-1.7.8.dist-info/LICENSE,sha256=OXLcl0T2SZ8Pmy2_dmlvKuetivmyPd5m1q-Gyd-zaYY,35149
19
+ ezKit-1.7.8.dist-info/METADATA,sha256=UywFjIMYxcbNAldtcIVgkoT4Zf6oF0KgR3oEHxTgMhQ,192
20
+ ezKit-1.7.8.dist-info/WHEEL,sha256=PZUExdf71Ui_so67QXpySuHtCi3-J3wvF4ORK6k_S8U,91
21
+ ezKit-1.7.8.dist-info/top_level.txt,sha256=aYLB_1WODsqNTsTFWcKP-BN0KCTKcV-HZJ4zlHkCFw8,6
22
+ ezKit-1.7.8.dist-info/RECORD,,
@@ -1,22 +0,0 @@
1
- ezKit/__init__.py,sha256=v6kh1vyXewSi_0PE0CMXrGz0aME4tISx_7BPXIKtZ9E,70
2
- ezKit/bottle.py,sha256=0lLLrzgAWhPj47KOdyITIsPRNUFGuwovA3vRW47SpUs,180117
3
- ezKit/bottle_extensions.py,sha256=OQUwHNg4cbZ0UZXwT6FJjwl4uAg00_Q-Zpogt_xHElk,1088
4
- ezKit/cipher.py,sha256=SIQ1xDHMHudXSg_5vJ06_wDc6kFldLryezO8t_eaFqg,2845
5
- ezKit/database.py,sha256=imOeBSU6kCIrVHei485HEROnmsr5UZtCcqwHk0vDzwY,6741
6
- ezKit/files.py,sha256=GoNdai3Ul0lg4wTkJAQm5kys1Sv3NCTNLIZlzHQKuZQ,12714
7
- ezKit/http.py,sha256=LTeyPVBm8deL_m-YRVW2O5w83-k3b1I1hU4cqkxS_B0,1845
8
- ezKit/mongo.py,sha256=FkxD7P7fUI9gPFR8D9t-TzthuxHyscMVJxNRK5gAd_A,1938
9
- ezKit/plots.py,sha256=QUtoVfZ49ZSNcY8gcQ2TYVkMjDDzoW-myMtqTi5WN2U,5322
10
- ezKit/qywx.py,sha256=7eWrlTLrUj6U6cViEGbT6_LQxFGVqkhGAefBSS6T_-0,6531
11
- ezKit/redis.py,sha256=pY4SPlcgQ7S8IeY2xoDpxy-xCZxzZQrQJNAoWRsC1dI,1773
12
- ezKit/reports.py,sha256=dBBggggCCLuk5YD6SjdUPuxTr3wiJojP3lA7dQfg6Pk,8898
13
- ezKit/sendemail.py,sha256=AAdxBvEYN_AJVvBkSAvXzhXC5jkbRsD_8P51h2SdTRw,8413
14
- ezKit/token.py,sha256=Q7z2ImQWs6NRxMtpsgNo9mhBeSs8nRCHCaWPf4031qg,1797
15
- ezKit/utils.py,sha256=UBAeybjLAB0tBLPD2M2QXfpI_smtkmPP4t7dX-Pcsu4,48849
16
- ezKit/xftp.py,sha256=BlxDctgJaCNeQNsVMwW6BcP3sL21SMVs-nPMjU_6rVg,7774
17
- ezKit/zabbix.py,sha256=soM5UEeYMfm7NczbPOVLirmHm3G20dECQ0aCBttZfhQ,28350
18
- ezKit-1.7.7.dist-info/LICENSE,sha256=OXLcl0T2SZ8Pmy2_dmlvKuetivmyPd5m1q-Gyd-zaYY,35149
19
- ezKit-1.7.7.dist-info/METADATA,sha256=7DiaRRyo1lystQf8VPWxpqkKHUK60DeKXgT2wmGSXbw,192
20
- ezKit-1.7.7.dist-info/WHEEL,sha256=PZUExdf71Ui_so67QXpySuHtCi3-J3wvF4ORK6k_S8U,91
21
- ezKit-1.7.7.dist-info/top_level.txt,sha256=aYLB_1WODsqNTsTFWcKP-BN0KCTKcV-HZJ4zlHkCFw8,6
22
- ezKit-1.7.7.dist-info/RECORD,,
File without changes
File without changes