gomyck-tools 1.2.8__py3-none-any.whl → 1.2.9__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/bottle_web_base.py CHANGED
@@ -123,18 +123,30 @@ def params_resolve(func):
123
123
  queryStr.page_info = page_info
124
124
  return func(params=queryStr, *args, **kwargs)
125
125
  elif request.method == 'POST':
126
+ query_params = request.query.decode('utf-8')
126
127
  content_type = request.get_header('content-type')
127
128
  if content_type == 'application/json':
128
129
  params = request.json or {}
129
- return func(params=DictWrapper(params), *args, **kwargs)
130
- elif content_type and 'multipart/form-data' in content_type:
130
+ dict_wrapper = DictWrapper(params)
131
+ dict_wrapper.query_params = query_params
132
+ return func(params=dict_wrapper, *args, **kwargs)
133
+ elif 'multipart/form-data' in content_type:
131
134
  form_data = request.forms.decode()
132
135
  form_files = request.files.decode()
133
- params = FormDataParams(data=DictWrapper(form_data), files=form_files)
134
- return func(params=params, *args, **kwargs)
135
- else:
136
- params = request.query.decode('utf-8')
137
- return func(params=params, *args, **kwargs)
136
+ dict_wrapper = DictWrapper(form_data)
137
+ dict_wrapper.query_params = query_params
138
+ dict_wrapper.files = form_files
139
+ return func(params=dict_wrapper, *args, **kwargs)
140
+ elif 'application/x-www-form-urlencoded' in content_type:
141
+ params = request.forms.decode()
142
+ dict_wrapper = DictWrapper(params.dict)
143
+ dict_wrapper.query_params = query_params
144
+ return func(params=dict_wrapper, *args, **kwargs)
145
+ elif 'text/plain' in content_type:
146
+ params = request.body.read().decode('utf-8')
147
+ dict_wrapper = DictWrapper({'body': params})
148
+ dict_wrapper.query_params = query_params
149
+ return func(params=dict_wrapper, *args, **kwargs)
138
150
  else:
139
151
  return func(*args, **kwargs)
140
152
  return decorated
@@ -144,17 +156,6 @@ class PageInfo:
144
156
  self.page_size = page_size
145
157
  self.page_index = page_index
146
158
 
147
- class FormDataParams:
148
- def __init__(self, data, files):
149
- self.data = data
150
- self.files = files
151
-
152
- def __getattr__(self, key):
153
- try:
154
- return self.data[key]
155
- except Exception:
156
- return self.files[key]
157
-
158
159
  # 通用的鉴权方法
159
160
  def common_auth_verify(aes_key):
160
161
  if request.path.startswith('/static') or request.path in GlobalState.withOutLoginURI:
@@ -2,7 +2,7 @@ import sys
2
2
  from socketserver import ThreadingMixIn
3
3
  from wsgiref.simple_server import WSGIServer, WSGIRequestHandler, make_server
4
4
 
5
- from bottle import ServerAdapter, Bottle, template, static_file, abort, redirect
5
+ from bottle import ServerAdapter, Bottle, template, static_file, abort, redirect, response
6
6
 
7
7
  from ctools import sys_info
8
8
 
@@ -56,34 +56,63 @@ class CBottle:
56
56
  self.port = port
57
57
  self.quiet = quiet
58
58
  self.bottle = bottle
59
+ self.index_root = './'
60
+ self.index_filename = 'index.html'
61
+ self.is_tpl = False
62
+ self.tmp_args = {}
63
+ self.redirect_url = None
64
+ self.static_root = './static'
65
+ self.download_root = './download'
59
66
 
60
- def run(self):
61
- http_server = WSGIRefServer(port=self.port)
62
- print('Click the link below to open the service homepage %s' % '\n \t\t http://localhost:%s \n \t\t http://%s:%s' % (self.port, sys_info.get_local_ipv4(), self.port), file=sys.stderr)
63
- self.bottle.run(server=http_server, quiet=self.quiet)
64
-
65
- def set_index(self, root='./', filename='index.html', is_tpl=False, redirect_url=None, **kwargs):
66
67
  @self.bottle.route(['/', '/index'])
67
68
  def index():
68
69
  try:
69
- if redirect_url: return redirect(redirect_url)
70
- if is_tpl: return template(f"{root}/{filename}", **kwargs)
71
- return static_file(filename=filename, root=root, **kwargs)
70
+ if self.redirect_url: return redirect(self.redirect_url)
71
+ if self.is_tpl: return template(f"{self.index_root}/{self.index_filename}", self.tmp_args)
72
+ return static_file(filename=self.index_filename, root=self.index_root)
72
73
  except FileNotFoundError:
73
74
  abort(404, "File not found...")
74
75
 
75
- def set_static(self, root):
76
76
  @self.bottle.route('/static/<filepath:path>')
77
77
  def static(filepath):
78
78
  try:
79
- return static_file(filepath, root=root)
79
+ return static_file(filepath, root=self.static_root)
80
80
  except FileNotFoundError:
81
81
  abort(404, "File not found...")
82
82
 
83
- def set_download(self, root):
84
83
  @self.bottle.route('/download/<filepath:path>')
85
84
  def download(filepath):
86
- return static_file(filepath, root=root, download=True)
85
+ return static_file(filepath, root=self.download_root, download=True)
86
+
87
+ @self.bottle.route('/favicon.ico')
88
+ def favicon():
89
+ response.content_type = 'image/svg+xml'
90
+ svg_icon = '''<?xml version="1.0" encoding="UTF-8"?>
91
+ <svg width="32" height="32" viewBox="0 0 32 32" xmlns="http://www.w3.org/2000/svg">
92
+ <circle cx="16" cy="16" r="14" fill="#007bff"/>
93
+ <path d="M16 8a8 8 0 0 0-8 8h2a6 6 0 0 1 12 0h2a8 8 0 0 0-8-8z" fill="white"/>
94
+ <circle cx="16" cy="20" r="2" fill="white"/>
95
+ </svg>
96
+ '''
97
+ return svg_icon
98
+
99
+ def run(self):
100
+ http_server = WSGIRefServer(port=self.port)
101
+ print('Click the link below to open the service homepage %s' % '\n \t\t http://localhost:%s \n \t\t http://%s:%s' % (self.port, sys_info.get_local_ipv4(), self.port), file=sys.stderr)
102
+ self.bottle.run(server=http_server, quiet=self.quiet)
103
+
104
+ def set_index(self, filename='index.html', root='./', is_tpl=False, redirect_url=None, **kwargs):
105
+ self.index_root = root
106
+ self.index_filename = filename
107
+ self.is_tpl = is_tpl
108
+ self.redirect_url = redirect_url
109
+ self.tmp_args = kwargs
110
+
111
+ def set_static(self, root='./static'):
112
+ self.static_root = root
113
+
114
+ def set_download(self, root='./download'):
115
+ self.download_root = root
87
116
 
88
117
  def mount(self, context_path, app, **kwargs):
89
118
  self.bottle.mount(context_path, app, **kwargs)
ctools/database.py CHANGED
@@ -11,6 +11,13 @@ from ctools import call, string_tools
11
11
  from ctools.thread_pool import thread_local
12
12
 
13
13
  """
14
+ class XXXX(BaseMixin):
15
+ __tablename__ = 't_xxx_info'
16
+ __table_args__ = {'comment': 'xxx信息表'}
17
+ server_content: Column = Column(String(50), nullable=True, default='', comment='123123')
18
+ server_ip: Column = Column(String(30), index=True)
19
+ user_id: Column = Column(BigInteger)
20
+
14
21
  database.init_db('postgresql://postgres:123456@192.168.3.107:32566/abc', default_schema='public', db_key='source', pool_size=100)
15
22
  with database.get_session('source') as s:
16
23
  s.execute(text('insert into xxx (name) values (:name)'), {'name': string_tools.get_random_str(5)})
@@ -56,6 +63,7 @@ def init_db(db_url: str, db_key: str='default', connect_args: dict={}, default_s
56
63
  sessionMakers[db_key] = sessionMaker
57
64
  inited_db[db_key] = True
58
65
  if default_schema: event.listen(engine, 'connect', lambda dbapi_connection, connection_record: _set_search_path(dbapi_connection, default_schema))
66
+ Base.metadata.create_all(engine)
59
67
 
60
68
  def _set_search_path(dbapi_connection, default_schema):
61
69
  with dbapi_connection.cursor() as cursor:
ctools/dict_wrapper.py CHANGED
@@ -7,7 +7,9 @@ class DictWrapper(dict):
7
7
  def __getattr__(self, key):
8
8
  res = self.get(key)
9
9
  if res is None:
10
- raise AttributeError(f"'{key}' not found in this Entity")
10
+ res = self.query_params.get(key)
11
+ if res is None:
12
+ raise AttributeError(f" ==>> {key} <<== Not Found In This Entity!!!")
11
13
  if isinstance(res, dict):
12
14
  return DictWrapper(res)
13
15
  return res
@@ -0,0 +1,57 @@
1
+ Metadata-Version: 2.1
2
+ Name: gomyck-tools
3
+ Version: 1.2.9
4
+ Summary: A tools collection 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.9
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
+ Requires-Dist: prometheus_client==0.21.1
31
+ Requires-Dist: paramiko==3.5.0
32
+ Requires-Dist: pyjwt==2.10.1
33
+ Requires-Dist: cryptography==43.0.1
34
+ Requires-Dist: redis==5.2.1
35
+
36
+ # Gomyck-Tools
37
+
38
+ ## project
39
+
40
+ https://github.com/mzxc
41
+
42
+ ## install
43
+
44
+ This package need python version >= 3.9
45
+
46
+ ```shell
47
+ pip install gomyck-tools
48
+ ```
49
+
50
+ ## usage
51
+
52
+ ```python
53
+ from ctools import sys_log
54
+ sys_log.clog.info('hello world')
55
+ ```
56
+
57
+
@@ -4,8 +4,8 @@ ctools/api_result.py,sha256=UeQXI_zuZB-uY5qECTpz1fC7EGy82yGQqWMx20tyRTw,1572
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
7
- ctools/bottle_web_base.py,sha256=lP4WIvmr-JjO6kDQ-NGIIe2l96hP-aXAiInYsqiWEAU,5974
8
- ctools/bottle_webserver.py,sha256=p_obHp_9de-A3HbLF5orrqMmDayett9MeaKja7a0N9M,3601
7
+ ctools/bottle_web_base.py,sha256=N4B9DL4k2y-eXzWkOAoeuqHJRSntYpJHWvDk33Ma0-w,6336
8
+ ctools/bottle_webserver.py,sha256=l7t_sN4ayywD1sR0kzuhGioOuaqGR9VhJh7e6Gbd6aE,4642
9
9
  ctools/bottle_websocket.py,sha256=zqCE1rGlMeC9oxFOULNd137IWIhdetq83Oq5OoH_zGI,1953
10
10
  ctools/browser_element_tools.py,sha256=IFR_tWu5on0LxhuC_4yT6EOjwCsC-juIoU8KQRDqR7E,9952
11
11
  ctools/call.py,sha256=BCr8wzt5qd70okv8IZn-9-EpjywleZgvA3u1vfZ_Kt8,1581
@@ -19,9 +19,9 @@ ctools/credis.py,sha256=sW7yDQvxa7B4dWvGwUH7GROq-7ElRMDhFT6g2C8ryfE,4522
19
19
  ctools/cron_lite.py,sha256=f9g7-64GsCxcAW-HUAvT6S-kooScl8zaJyqwHY-X_rE,8308
20
20
  ctools/ctoken.py,sha256=NZSBGF3lJajJFLRIZoeXmpp8h5cKM0dAH2weySgeORc,882
21
21
  ctools/czip.py,sha256=g-2s804R06Bnp19ByVsYeRbwx5HQf_KwrStvHimVyns,632
22
- ctools/database.py,sha256=619rlE6LMZ5x9ijLv8WVmtUwbSL5tCHGwt_K-V_VmQY,6094
22
+ ctools/database.py,sha256=NVdYROhlQfElAoaUloiMeQLwxENS7etY8FTZKaW0rI8,6414
23
23
  ctools/date_utils.py,sha256=h3rvlw_K2F0QTac2Zat_1us76R0P-Qj6_6NeQPfM3VE,1697
24
- ctools/dict_wrapper.py,sha256=6lZUyHomdn5QdjQTg7EL1sC_I6tOlh8ofMRQT3XGQjM,398
24
+ ctools/dict_wrapper.py,sha256=KYFeNcaaumFXVQePnh-z7q5ANK_Arapki1qOlQBoc3k,473
25
25
  ctools/douglas_rarefy.py,sha256=43WRjGGsQ_o1yPEXypA1Xv_yuo90RVo7qaYGRslx5gQ,4890
26
26
  ctools/download_tools.py,sha256=oJbG12Hojd0J17sAlvMU480P3abi4_AB9oZkEBGFPuo,1930
27
27
  ctools/enums.py,sha256=QbHa3j7j4-BDdwaga5Y0nYfA2uNSVJDHumYdIZdKVkM,118
@@ -56,7 +56,7 @@ ctools/wordFill.py,sha256=dB1OLt6GLmWdkDV8H20VWbJmY4ggNNI8iHD1ocae2iM,875
56
56
  ctools/word_fill.py,sha256=xeo-P4DOjQUqd-o9XL3g66wQrE2diUPGwFywm8TdVyw,18210
57
57
  ctools/word_fill_entity.py,sha256=eX3G0Gy16hfGpavQSEkCIoKDdTnNgRRJrFvKliETZK8,985
58
58
  ctools/work_path.py,sha256=OmfYu-Jjg2huRY6Su8zJ_2EGFFhtBZFbobYTwbjJtG4,1817
59
- gomyck_tools-1.2.8.dist-info/METADATA,sha256=gUL87nZKJGUAwG9w5FJAMdTMQXDndYMOWKjK0ndbOL8,1376
60
- gomyck_tools-1.2.8.dist-info/WHEEL,sha256=yQN5g4mg4AybRjkgi-9yy4iQEFibGQmlz78Pik5Or-A,92
61
- gomyck_tools-1.2.8.dist-info/top_level.txt,sha256=-MiIH9FYRVKp1i5_SVRkaI-71WmF1sZSRrNWFU9ls3s,7
62
- gomyck_tools-1.2.8.dist-info/RECORD,,
59
+ gomyck_tools-1.2.9.dist-info/METADATA,sha256=WENt6ng1HZQLWvo5aTrEdurWq0HZc6AT-J092T1j62I,1354
60
+ gomyck_tools-1.2.9.dist-info/WHEEL,sha256=PZUExdf71Ui_so67QXpySuHtCi3-J3wvF4ORK6k_S8U,91
61
+ gomyck_tools-1.2.9.dist-info/top_level.txt,sha256=-MiIH9FYRVKp1i5_SVRkaI-71WmF1sZSRrNWFU9ls3s,7
62
+ gomyck_tools-1.2.9.dist-info/RECORD,,
@@ -1,5 +1,5 @@
1
1
  Wheel-Version: 1.0
2
- Generator: bdist_wheel (0.41.2)
2
+ Generator: setuptools (75.6.0)
3
3
  Root-Is-Purelib: true
4
4
  Tag: py3-none-any
5
5
 
@@ -1,57 +0,0 @@
1
- Metadata-Version: 2.1
2
- Name: gomyck-tools
3
- Version: 1.2.8
4
- Summary: A tools collection 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.9
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
- Requires-Dist: prometheus-client ==0.21.1
31
- Requires-Dist: paramiko ==3.5.0
32
- Requires-Dist: pyjwt ==2.10.1
33
- Requires-Dist: cryptography ==43.0.1
34
- Requires-Dist: redis ==5.2.1
35
-
36
- # Gomyck-Tools
37
-
38
- ## project
39
-
40
- https://github.com/mzxc
41
-
42
- ## install
43
-
44
- This package need python version >= 3.9
45
-
46
- ```shell
47
- pip install gomyck-tools
48
- ```
49
-
50
- ## usage
51
-
52
- ```python
53
- from ctools import sys_log
54
- sys_log.clog.info('hello world')
55
- ```
56
-
57
-