gomyck-tools 1.4.5__py3-none-any.whl → 1.4.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/util/jb_cut.py +3 -2
- ctools/web/bottle_web_base.py +8 -2
- ctools/web/bottle_webserver.py +45 -4
- {gomyck_tools-1.4.5.dist-info → gomyck_tools-1.4.6.dist-info}/METADATA +4 -1
- {gomyck_tools-1.4.5.dist-info → gomyck_tools-1.4.6.dist-info}/RECORD +8 -8
- {gomyck_tools-1.4.5.dist-info → gomyck_tools-1.4.6.dist-info}/WHEEL +0 -0
- {gomyck_tools-1.4.5.dist-info → gomyck_tools-1.4.6.dist-info}/licenses/LICENSE +0 -0
- {gomyck_tools-1.4.5.dist-info → gomyck_tools-1.4.6.dist-info}/top_level.txt +0 -0
ctools/util/jb_cut.py
CHANGED
|
@@ -31,7 +31,7 @@ def add_freq(word: ()):
|
|
|
31
31
|
"""
|
|
32
32
|
jieba.suggest_freq(word, True)
|
|
33
33
|
|
|
34
|
-
def get_declare_type_word(word: str, word_flag=(), use_paddle=False, exclude_flag=
|
|
34
|
+
def get_declare_type_word(word: str, word_flag=(), use_paddle=False, exclude_flag=jqfx_exclude, exclude_word=()):
|
|
35
35
|
#import paddle
|
|
36
36
|
#paddle.enable_static()
|
|
37
37
|
#sys.stdout = sys.__stdout__
|
|
@@ -42,12 +42,13 @@ def get_declare_type_word(word: str, word_flag=(), use_paddle=False, exclude_fla
|
|
|
42
42
|
:param word_flag: 标签
|
|
43
43
|
:param use_paddle: 是否使用 paddle
|
|
44
44
|
:param exclude_flag: 排除的标签
|
|
45
|
+
:param exclude_word: 排除的词
|
|
45
46
|
:return: 筛选之后的单词(数组)
|
|
46
47
|
"""
|
|
47
48
|
# linux 可以开放下面的语句, 并发执行分词, windows 不支持
|
|
48
49
|
# if platform.system() == 'Linux': jieba.enable_parallel(4)
|
|
49
50
|
ret = []
|
|
50
51
|
for w, flag in pseg.cut(word, use_paddle=use_paddle):
|
|
51
|
-
if (flag in word_flag or len(word_flag) == 0) and flag not in exclude_flag:
|
|
52
|
+
if (flag in word_flag or len(word_flag) == 0) and flag not in exclude_flag and w not in exclude_word:
|
|
52
53
|
ret.append((w, flag))
|
|
53
54
|
return ret
|
ctools/web/bottle_web_base.py
CHANGED
|
@@ -23,6 +23,7 @@ class GlobalState:
|
|
|
23
23
|
'/index',
|
|
24
24
|
'/login',
|
|
25
25
|
'/favicon.ico',
|
|
26
|
+
'/static/',
|
|
26
27
|
}
|
|
27
28
|
allowRemoteCallURI = set()
|
|
28
29
|
auth_ignore_func = set()
|
|
@@ -44,7 +45,7 @@ def cache_white_list(app):
|
|
|
44
45
|
for path, tuples in routes.items():
|
|
45
46
|
req_func = inspect.getmodule(tuples[0].callback).__name__ + "." + tuples[0].callback.__name__
|
|
46
47
|
if req_func in GlobalState.auth_ignore_func:
|
|
47
|
-
print("add white list: {}".format(
|
|
48
|
+
print("add white list: {}".format(route.rule))
|
|
48
49
|
GlobalState.withOutLoginURI.add(join_path(app.context_path, real_func.context_path, path))
|
|
49
50
|
|
|
50
51
|
def init_app(context_path="/", main_app=False):
|
|
@@ -58,7 +59,11 @@ def init_app(context_path="/", main_app=False):
|
|
|
58
59
|
def init_main_app():
|
|
59
60
|
@app.hook('before_request')
|
|
60
61
|
def before_request():
|
|
61
|
-
|
|
62
|
+
for v in GlobalState.withOutLoginURI:
|
|
63
|
+
if v.endswith('/'):
|
|
64
|
+
if request.path.startswith(v): return
|
|
65
|
+
else:
|
|
66
|
+
if v in request.path: return
|
|
62
67
|
for interceptor in GlobalState.interceptors:
|
|
63
68
|
res: R = interceptor['func']()
|
|
64
69
|
if res.code != 200: bottle.abort(res.code, res.message)
|
|
@@ -124,6 +129,7 @@ def before_intercept(order=0):
|
|
|
124
129
|
return decorator
|
|
125
130
|
|
|
126
131
|
# annotation
|
|
132
|
+
# 接口请求地址后面带不带斜杠都会影响: /api/xxx/ 和 /api/xxx 是不一样的
|
|
127
133
|
def auth_ignore(func):
|
|
128
134
|
"""忽略登录验证的接口"""
|
|
129
135
|
ignore_req_func = inspect.getmodule(func).__name__ + "." + func.__name__
|
ctools/web/bottle_webserver.py
CHANGED
|
@@ -1,13 +1,14 @@
|
|
|
1
|
+
import os
|
|
1
2
|
import sys
|
|
2
3
|
from socketserver import ThreadingMixIn
|
|
3
4
|
from wsgiref.simple_server import WSGIServer, WSGIRequestHandler, make_server
|
|
4
5
|
|
|
5
|
-
from bottle import ServerAdapter, Bottle, template, static_file, abort, redirect, response
|
|
6
|
+
from bottle import ServerAdapter, Bottle, template, static_file, abort, redirect, response, request
|
|
6
7
|
|
|
7
8
|
from ctools import sys_info
|
|
8
9
|
from ctools.pkg.dynamic_imp import load_modules_from_package
|
|
9
|
-
from ctools.web.
|
|
10
|
-
|
|
10
|
+
from ctools.web.api_result import R
|
|
11
|
+
from ctools.web.bottle_web_base import cache_white_list, auth_ignore, GlobalState
|
|
11
12
|
|
|
12
13
|
"""
|
|
13
14
|
import controllers
|
|
@@ -53,6 +54,7 @@ class CBottle:
|
|
|
53
54
|
self.redirect_url = None
|
|
54
55
|
self.static_root = './static'
|
|
55
56
|
self.download_root = './download'
|
|
57
|
+
self.template_root = './templates'
|
|
56
58
|
|
|
57
59
|
@self.bottle.route(['/', '/index'])
|
|
58
60
|
def index():
|
|
@@ -63,6 +65,13 @@ class CBottle:
|
|
|
63
65
|
except FileNotFoundError:
|
|
64
66
|
abort(404, "File not found...")
|
|
65
67
|
|
|
68
|
+
@self.bottle.route('/template/<filepath:path>')
|
|
69
|
+
def tpl(filepath, tmp_args):
|
|
70
|
+
try:
|
|
71
|
+
return template(f"{self.template_root}/{filepath}", tmp_args)
|
|
72
|
+
except FileNotFoundError:
|
|
73
|
+
abort(404, "File not found...")
|
|
74
|
+
|
|
66
75
|
@self.bottle.route('/static/<filepath:path>')
|
|
67
76
|
def static(filepath):
|
|
68
77
|
try:
|
|
@@ -86,22 +95,54 @@ class CBottle:
|
|
|
86
95
|
'''
|
|
87
96
|
return svg_icon
|
|
88
97
|
|
|
98
|
+
def auto_register_statics(self, dist_root='./static'):
|
|
99
|
+
for d in os.listdir(dist_root):
|
|
100
|
+
full_path = os.path.join(dist_root, d)
|
|
101
|
+
if os.path.isdir(full_path):
|
|
102
|
+
self.add_static_route(f'/{d}', full_path)
|
|
103
|
+
|
|
104
|
+
def add_static_route(self, url_prefix, root):
|
|
105
|
+
"""动态添加静态资源映射"""
|
|
106
|
+
if not url_prefix.startswith('/'):
|
|
107
|
+
url_prefix = '/' + url_prefix
|
|
108
|
+
if not url_prefix.endswith('/'):
|
|
109
|
+
url_prefix += '/'
|
|
110
|
+
route_path = f"{url_prefix}<filepath:path>"
|
|
111
|
+
@self.bottle.route(route_path)
|
|
112
|
+
def static_handler(filepath):
|
|
113
|
+
try:
|
|
114
|
+
return static_file(filepath, root=root)
|
|
115
|
+
except FileNotFoundError:
|
|
116
|
+
abort(404, f"{filepath} not found in {root}")
|
|
117
|
+
GlobalState.withOutLoginURI.add(url_prefix)
|
|
118
|
+
print(f"[static] mounted {url_prefix} -> {root}")
|
|
119
|
+
|
|
89
120
|
def run(self):
|
|
90
121
|
http_server = WSGIRefServer(port=self.port)
|
|
91
122
|
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)
|
|
92
123
|
cache_white_list(self.bottle)
|
|
93
124
|
self.bottle.run(server=http_server, quiet=self.quiet)
|
|
94
125
|
|
|
95
|
-
def
|
|
126
|
+
def enable_spa_mode(self):
|
|
127
|
+
@self.bottle.error(404)
|
|
128
|
+
def error_404_handler(error):
|
|
129
|
+
if request.path.startswith('/api/'): return R.error(resp=R.Code.cus_code(404, "资源未找到: {}".format(error.body)))
|
|
130
|
+
return static_file(filename=self.index_filename, root=self.index_root)
|
|
131
|
+
|
|
132
|
+
def set_index(self, filename='index.html', root='./', is_tpl=False, redirect_url=None, spa=False, **kwargs):
|
|
96
133
|
self.index_root = root
|
|
97
134
|
self.index_filename = filename
|
|
98
135
|
self.is_tpl = is_tpl
|
|
99
136
|
self.redirect_url = redirect_url
|
|
137
|
+
if spa: self.enable_spa_mode()
|
|
100
138
|
self.tmp_args = kwargs
|
|
101
139
|
|
|
102
140
|
def set_static(self, root='./static'):
|
|
103
141
|
self.static_root = root
|
|
104
142
|
|
|
143
|
+
def set_template(self, root='./templates'):
|
|
144
|
+
self.template_root = root
|
|
145
|
+
|
|
105
146
|
def set_download(self, root='./download'):
|
|
106
147
|
self.download_root = root
|
|
107
148
|
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.4
|
|
2
2
|
Name: gomyck-tools
|
|
3
|
-
Version: 1.4.
|
|
3
|
+
Version: 1.4.6
|
|
4
4
|
Summary: A tools collection for python development by hao474798383
|
|
5
5
|
Author-email: gomyck <hao474798383@163.com>
|
|
6
6
|
License-Expression: Apache-2.0
|
|
@@ -41,6 +41,9 @@ Requires-Dist: jieba==0.42.1; extra == "cut"
|
|
|
41
41
|
Requires-Dist: paddlepaddle==2.6.1; extra == "cut"
|
|
42
42
|
Provides-Extra: ml
|
|
43
43
|
Requires-Dist: scikit-learn>=1.7.1; extra == "ml"
|
|
44
|
+
Requires-Dist: pandas>=2.3.2; extra == "ml"
|
|
45
|
+
Requires-Dist: lxml>=6.0.1; extra == "ml"
|
|
46
|
+
Requires-Dist: xlrd>=2.0.2; extra == "ml"
|
|
44
47
|
Dynamic: license-file
|
|
45
48
|
|
|
46
49
|
# Gomyck-Tools
|
|
@@ -69,20 +69,20 @@ ctools/util/env_config.py,sha256=L98G9LPdpD7Yl5XbA_-KfkcA4mDunQoKiYtK5w7QR-s,179
|
|
|
69
69
|
ctools/util/html_soup.py,sha256=rnr8M3gn3gQGo-wNaNFXDjdzp8AAkv9o4yqfIIfO-zw,1567
|
|
70
70
|
ctools/util/http_util.py,sha256=cx0FRnPLFdJ0mF9UYphl40SZj68fqG30Q0udku9hZIE,769
|
|
71
71
|
ctools/util/image_process.py,sha256=nqJOi2p8wLe8wRsfkH99MyEYSjE9i4fthxBJwrrZVB8,835
|
|
72
|
-
ctools/util/jb_cut.py,sha256=
|
|
72
|
+
ctools/util/jb_cut.py,sha256=h8Ey-LbpHtbAHskITn5GXEO7-DHJ_ZLODmE8Lc_dgSc,1664
|
|
73
73
|
ctools/util/snow_id.py,sha256=KCuQ0zOTlmus8gZetmRA5y0jBSd8J0KXcJ33EzgCKjE,2225
|
|
74
74
|
ctools/web/__init__.py,sha256=koSNYeKF5Z_xbp4Q2qbZ4ZP-3--1phbOYN9e4SJy_gk,98
|
|
75
75
|
ctools/web/aio_web_server.py,sha256=p46BOU3_m4Jb57yAACeedKjhlFc1YC0QJSUe2selBgA,5693
|
|
76
76
|
ctools/web/api_result.py,sha256=i1MjTnnlgkWl_q07xr-TLQeLYlXEh4DEclUFE414nSk,1568
|
|
77
|
-
ctools/web/bottle_web_base.py,sha256=
|
|
78
|
-
ctools/web/bottle_webserver.py,sha256=
|
|
77
|
+
ctools/web/bottle_web_base.py,sha256=qpqmu9hxrjgd1UuIGXHs8nq1f3xmOk04L4v1Hw34qhs,8605
|
|
78
|
+
ctools/web/bottle_webserver.py,sha256=0xHLnuGIShxrEHc2mLnyx43NDVkCqM5QnlkY-Ndzrk4,6650
|
|
79
79
|
ctools/web/bottle_websocket.py,sha256=xsu9fAtTuR5DsSsQjiBfaYxLjOWFyfr1sYM6cktTovI,1957
|
|
80
80
|
ctools/web/ctoken.py,sha256=WaB29kqGlKAh21aUw5avl2h8AgLD1aESw8KCpqaN5nM,2539
|
|
81
81
|
ctools/web/download_util.py,sha256=v0JTXiED1bvoWFfwfd-LD5s7_aoRQ0lCkaGwSnSp7WI,1954
|
|
82
82
|
ctools/web/params_util.py,sha256=eJDV3PSq-ZHb8UZf6xqs8kOhbyZzits1H9yPoUBIDXg,828
|
|
83
83
|
ctools/web/upload_util.py,sha256=z1QQCi4SFx08jrAQH5-Y_ShiM4MghuD_5Qz6V9KK_4U,1076
|
|
84
|
-
gomyck_tools-1.4.
|
|
85
|
-
gomyck_tools-1.4.
|
|
86
|
-
gomyck_tools-1.4.
|
|
87
|
-
gomyck_tools-1.4.
|
|
88
|
-
gomyck_tools-1.4.
|
|
84
|
+
gomyck_tools-1.4.6.dist-info/licenses/LICENSE,sha256=X25ypfH9E6VTht2hcO8k7LCSdHUcoG_ALQt80jdYZfY,547
|
|
85
|
+
gomyck_tools-1.4.6.dist-info/METADATA,sha256=7VzJxrSxS8a1A1UBPG0XOGO-_-xE6_-5sXYoBPb3d2I,1826
|
|
86
|
+
gomyck_tools-1.4.6.dist-info/WHEEL,sha256=_zCd3N1l69ArxyTb8rzEoP9TpbYXkqRFSNOD5OuxnTs,91
|
|
87
|
+
gomyck_tools-1.4.6.dist-info/top_level.txt,sha256=-MiIH9FYRVKp1i5_SVRkaI-71WmF1sZSRrNWFU9ls3s,7
|
|
88
|
+
gomyck_tools-1.4.6.dist-info/RECORD,,
|
|
File without changes
|
|
File without changes
|
|
File without changes
|