kcws 3.50__tar.gz → 3.52__tar.gz

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.
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 1.2
2
2
  Name: kcws
3
- Version: 3.50
3
+ Version: 3.52
4
4
  Summary: kcwebs作为web开发而设计的高性能框架
5
5
  Home-page: https://docs.kwebapp.cn/index/index/2
6
6
  Author: 百里-坤坤
@@ -9,5 +9,5 @@ Maintainer: 坤坤
9
9
  Maintainer-email: fk1402936534@qq.com
10
10
  License: MIT License
11
11
  Description: kcwebs作为web开发而设计的高性能框架,采用全新的架构思想,注重易用性。遵循MIT开源许可协议发布,意味着个人和企业可以免费使用kcwebs,甚至允许把你基于kcwebs开发的应用开源或商业产品发布或销售。完整文档请访问:https://docs.kwebapp.cn/index/index/2
12
- Keywords: kcws3.50
12
+ Keywords: kcws3.52
13
13
  Platform: UNKNOWN
@@ -1,5 +1,5 @@
1
1
  # -*- coding: utf-8 -*-
2
- __version__ = '3.50'
2
+ __version__ = '3.52'
3
3
  try:
4
4
  from .app import web
5
5
  except:
@@ -0,0 +1,5 @@
1
+ # -*- coding: utf-8 -*-
2
+ from . autoload import *
3
+ from . import globals
4
+ from . import request
5
+ G=globals.G
@@ -1,8 +1,57 @@
1
1
  # -*- coding: utf-8 -*-
2
- import time,hashlib,json,re,os,platform,shutil,requests,importlib,traceback,tarfile,zipfile,signal,psutil
2
+ import time,hashlib,json,re,os,platform,shutil,requests,importlib,traceback,tarfile,zipfile,signal,psutil,random
3
3
  from kcws import config
4
4
  from . import globals
5
5
  import subprocess
6
+ def is_index(params,index):
7
+ """判断列表或字典里的索引是否存在
8
+
9
+ params 列表或字典
10
+
11
+ index 索引值
12
+
13
+ return Boolean类型
14
+ """
15
+ try:
16
+ params[index]
17
+ except KeyError:
18
+ return False
19
+ except IndexError:
20
+ return False
21
+ else:
22
+ return True
23
+ def randoms(lens=6,types=1):
24
+ """生成随机字符串
25
+
26
+ lens 长度
27
+
28
+ types 1数字 2字母 3字母加数字
29
+ """
30
+ strs="0123456789qwertyuiopasdfghjklzxcvbnmQWERTYUIOPASDFGHJKLZXCVBNM,!@#$%^&*()_+=-;',./:<>?"
31
+ if types==1:
32
+ strs="0123456789"
33
+ elif types==2:
34
+ strs="qwertyuiopasdfghjklzxcvbnmQWERTYUIOPASDFGHJKLZXCVBNM"
35
+ elif types==3:
36
+ strs="0123456789qwertyuiopasdfghjklzxcvbnmQWERTYUIOPASDFGHJKLZXCVBNM"
37
+ k=''
38
+ i=0
39
+ while i < lens:
40
+ k+=random.choice(strs)
41
+ i+=1
42
+ return k
43
+
44
+ def timestampToDate(times,format="%Y-%m-%d %H:%M:%S"):
45
+ """时间戳转换时间
46
+
47
+ times 10位时间戳
48
+
49
+ format 日期格式 如%Y-%m-%d %H:%M:%S
50
+ """
51
+ timeArray = time.localtime(int(times))
52
+ return time.strftime(format.encode('unicode-escape').decode(),timeArray).encode().decode('unicode-escape')
53
+
54
+
6
55
  def get_pid_by_port(port):
7
56
  """获取使用指定端口使用的进程号pid"""
8
57
  pid=[]
@@ -18,164 +67,6 @@ def get_pid_by_port(port):
18
67
  else:
19
68
  raise Exception(strs)
20
69
  return pid
21
- class kcwszip:
22
- def __clean_filename(filename):
23
- # 移除或替换非法字符
24
- filename =re.sub(r'[<>:"/\\|?*]', '', filename)
25
- filename=filename.replace('\t','')
26
- # print('filenamefilenamefilenamefilename',filename)
27
- return filename
28
- def packzip(src,dst):
29
- "压缩"
30
- filelist = []
31
- if os.path.isfile(src):
32
- filelist.append(src)
33
- for root, dirs, files in os.walk(src):
34
- for name in files:
35
- filelist.append(os.path.join(root, name))
36
- zf = zipfile.ZipFile(dst, "w", zipfile.zlib.DEFLATED)
37
- for tar in filelist:
38
- arcname = tar[len(src):]
39
- zf.write(tar,arcname)
40
- zf.close()
41
- def unzip_file(dst, src,all=True):
42
- "解压"
43
- if all:
44
- zf = zipfile.ZipFile(dst)
45
- zf.extractall(src)
46
- zf.close()
47
- else:
48
- zip_ref=zipfile.ZipFile(dst)
49
- for item in zip_ref.infolist():
50
- zip_ref.extract(item, src)
51
- zip_ref.close()
52
- def unzip(filename):
53
- "解压到文件所在目录"
54
- diswjj=''
55
- tarr=filename.split('.')
56
- i=0
57
- while i<len(tarr)-1:
58
- if i<=len(tarr)-3:
59
- diswjj+=tarr[i]+'.'
60
- else:
61
- diswjj+=tarr[i]
62
- i+=1
63
- # if not os.path.exists(diswjj):
64
- # os.makedirs(diswjj,exist_ok=True)
65
- try:
66
- zip_ref=zipfile.ZipFile(filename, 'r')
67
- for item in zip_ref.infolist():
68
- try:
69
- item.filename = item.filename.encode('cp437').decode('gbk')
70
- except:pass
71
- try:
72
- item.filename = item.filename.replace('\t','').replace('\n','').replace('\b','')
73
- except:pass
74
- # print("item.filename",item.filename)
75
- try:
76
- zip_ref.extract(item, diswjj)
77
- except Exception as e:
78
- stre=str(e)
79
- if 'Bad CRC-32 for fil' in stre:#文件损坏
80
- print('压缩文件文件损坏',stre)
81
- pass
82
- elif '[Errno 2] No such file or directory: ' in stre:
83
- print('不是有效文件',stre)
84
- pass
85
- elif '[WinError 3] 系统找不到指定的路径' in stre:
86
- print('系统找不到指定的路径',stre)
87
- pass
88
- elif '文件名或扩展名太长' in stre:
89
- if os.path.exists(diswjj):
90
- try:
91
- shutil.rmtree(diswjj)
92
- except:pass
93
- try:
94
- zip_ref.close()
95
- except:pass
96
- if os.name == 'nt':
97
- if not os.path.exists("c:/temp"):
98
- os.makedirs("c:/temp", exist_ok=True)
99
- newspath="c:/temp/"+md5(filename)
100
- print('文件名或扩展名太长,正在复制到 '+newspath+' 重试')
101
- tempname=newspath+'.zip'
102
- if not os.path.exists(newspath):
103
- os.makedirs(newspath, exist_ok=True)
104
- shutil.copy(filename, tempname)
105
- return kcwszip.unzip(tempname)
106
- else:
107
- print('stre',stre,filename)
108
- raise Exception(e)
109
- else:
110
- if os.path.exists(diswjj):
111
- try:
112
- shutil.rmtree(diswjj)
113
- except:pass
114
- try:
115
- zip_ref.close()
116
- except:pass
117
- print('stre',stre,filename)
118
- raise Exception(e)
119
- zip_ref.close()
120
- except Exception as e:
121
- stre=str(e)
122
- print('zip解压异常',stre)
123
- raise Exception(e)
124
- # if 'File is not a zip file' in stre or 'Bad CRC-32 for fil' in stre:
125
- # if os.path.exists(diswjj):
126
- # try:
127
- # shutil.rmtree(diswjj)
128
- # except:pass
129
- # return False
130
- # else:
131
- # if os.path.exists(diswjj):
132
- # shutil.rmtree(diswjj)
133
- # raise Exception(e)
134
- #处理中文乱码
135
- arr=get_file(diswjj,is_folder=False)
136
- for kkk in arr:
137
- new_name=kkk['path'].split('/')
138
- try:
139
- new_name=kkk['path'].replace(new_name[len(new_name)-1],kkk['name'].encode('cp437').decode("gbk"))
140
- except:
141
- # print(kkk['name'],'编码无需要解码')
142
- pass
143
- else:
144
- try:
145
- os.rename(kkk['path'], new_name)
146
- except Exception as e:
147
- stre=str(e)
148
- if '当文件已存在时,无法创建该文件' in stre:
149
- pass
150
- else:
151
- if os.path.exists(diswjj):
152
- shutil.rmtree(diswjj)
153
- raise Exception(e)
154
- return diswjj
155
- class kcwstar:
156
- def targz(src,dst):
157
- """
158
- 打包目录为tar.gz
159
- :param src: 需要打包的目录
160
- :param dst: 压缩文件名
161
- :return: bool
162
- """
163
- with tarfile.open(dst, "w:gz") as tar:
164
- tar.add(src, arcname=os.path.basename(src))
165
- return True
166
- def untar(dst, src):
167
- """
168
- 解压tar.gz文件
169
- :param dst: 压缩文件名
170
- :param src: 解压后的存放路径
171
- :return: bool
172
- """
173
- try:
174
- t = tarfile.open(dst)
175
- t.extractall(path = src)
176
- return True
177
- except Exception as e:
178
- return False
179
70
 
180
71
  def get_file(folder='./',is_folder=True,suffix="*",lists=[],append=False):
181
72
  """获取文件夹下所有文件夹和文件
@@ -239,10 +130,12 @@ def md5(strs):
239
130
  b = strs.encode(encoding='utf-8')
240
131
  m.update(b)
241
132
  return m.hexdigest()
242
- def kcws_kill_path_pid(folder):
133
+ def kcws_kill_path_pid(folder,retry=60):
243
134
  """结束指定目录pid
244
135
 
245
136
  folder 目录
137
+
138
+ retry 重试次数
246
139
  """
247
140
  if os.path.exists(folder):
248
141
  lis=os.listdir(folder)
@@ -251,7 +144,7 @@ def kcws_kill_path_pid(folder):
251
144
  f=open(folder+"/"+files,'r')
252
145
  pid=f.read()
253
146
  f.close()
254
- kill_pid(pid)
147
+ kill_pid(pid,retry=retry)
255
148
  os.remove(folder+"/"+files)
256
149
 
257
150
  def kcws_save_folder_pid(folder,pid):
@@ -322,13 +215,13 @@ def get_kcws_cli_info(route,types='pid'):
322
215
  pid=get_kcws_cli_pid(route)
323
216
  return get_pid_info(pid=pid,types=types)
324
217
 
325
- def kill_pid(pid):
218
+ def kill_pid(pid,retry=60):
326
219
  """通过进程结束进程
327
220
 
328
221
  pid 进程号
329
222
  """
330
223
  if pid:
331
- for i in range(60):
224
+ for i in range(retry):
332
225
  if 'Linux' in get_sysinfo()['platform']:
333
226
  os.system("kill -9 "+str(pid))
334
227
  else:
@@ -342,14 +235,16 @@ def kill_pid(pid):
342
235
  # if i>60:
343
236
  # raise Exception('kill_pid error:pid='+str(pid))
344
237
  return True
345
- def kill_route_cli(route):
238
+ def kill_route_cli(route,retry=60):
346
239
  """通过路由结束进程
347
240
 
348
241
  route 路由地址
242
+
243
+ retry 重试次数
349
244
  """
350
245
  pid=get_kcws_cli_pid(route)
351
246
  if pid:
352
- if kill_pid(pid):
247
+ if kill_pid(pid,retry=retry):
353
248
  try:
354
249
  os.remove(get_folder()+"/pid/"+md5(route)+"_cli_pid")
355
250
  except:pass
@@ -402,6 +297,242 @@ def get_sysinfo():
402
297
  # platform.python_version()
403
298
  # platform.python_version_tuple()
404
299
  return sysinfo
300
+
301
+ class kcwszip:
302
+ def __clean_filename(filename):
303
+ # 移除或替换非法字符
304
+ filename =re.sub(r'[<>:"/\\|?*]', '', filename)
305
+ filename=filename.replace('\t','')
306
+ # print('filenamefilenamefilenamefilename',filename)
307
+ return filename
308
+ def packzip(src,dst):
309
+ "压缩"
310
+ filelist = []
311
+ if os.path.isfile(src):
312
+ filelist.append(src)
313
+ for root, dirs, files in os.walk(src):
314
+ for name in files:
315
+ filelist.append(os.path.join(root, name))
316
+ zf = zipfile.ZipFile(dst, "w", zipfile.zlib.DEFLATED)
317
+ for tar in filelist:
318
+ arcname = tar[len(src):]
319
+ zf.write(tar,arcname)
320
+ zf.close()
321
+ def unzip_file(dst, src,all=True):
322
+ "解压"
323
+ if all:
324
+ zf = zipfile.ZipFile(dst)
325
+ zf.extractall(src)
326
+ zf.close()
327
+ else:
328
+ zip_ref=zipfile.ZipFile(dst)
329
+ for item in zip_ref.infolist():
330
+ zip_ref.extract(item, src)
331
+ zip_ref.close()
332
+ def unzip(filename):
333
+ "解压到文件所在目录"
334
+ diswjj=''
335
+ tarr=filename.split('.')
336
+ i=0
337
+ while i<len(tarr)-1:
338
+ if i<=len(tarr)-3:
339
+ diswjj+=tarr[i]+'.'
340
+ else:
341
+ diswjj+=tarr[i]
342
+ i+=1
343
+ # if not os.path.exists(diswjj):
344
+ # os.makedirs(diswjj,exist_ok=True)
345
+ try:
346
+ zip_ref=zipfile.ZipFile(filename, 'r')
347
+ for item in zip_ref.infolist():
348
+ try:
349
+ item.filename = item.filename.encode('cp437').decode('gbk')
350
+ except:pass
351
+ try:
352
+ item.filename = item.filename.replace('\t','').replace('\n','').replace('\b','')
353
+ except:pass
354
+ # print("item.filename",item.filename)
355
+ try:
356
+ zip_ref.extract(item, diswjj)
357
+ except Exception as e:
358
+ stre=str(e)
359
+ if 'Bad CRC-32 for fil' in stre:#文件损坏
360
+ print('压缩文件文件损坏',stre)
361
+ pass
362
+ elif '[Errno 2] No such file or directory: ' in stre:
363
+ print('不是有效文件',stre)
364
+ pass
365
+ elif '[WinError 3] 系统找不到指定的路径' in stre:
366
+ print('系统找不到指定的路径',stre)
367
+ pass
368
+ elif '文件名或扩展名太长' in stre:
369
+ if os.path.exists(diswjj):
370
+ try:
371
+ shutil.rmtree(diswjj)
372
+ except:pass
373
+ try:
374
+ zip_ref.close()
375
+ except:pass
376
+ if os.name == 'nt':
377
+ if not os.path.exists("c:/temp"):
378
+ os.makedirs("c:/temp", exist_ok=True)
379
+ newspath="c:/temp/"+md5(filename)
380
+ print('文件名或扩展名太长,正在复制到 '+newspath+' 重试')
381
+ tempname=newspath+'.zip'
382
+ if not os.path.exists(newspath):
383
+ os.makedirs(newspath, exist_ok=True)
384
+ shutil.copy(filename, tempname)
385
+ return kcwszip.unzip(tempname)
386
+ else:
387
+ print('stre',stre,filename)
388
+ raise Exception(e)
389
+ else:
390
+ if os.path.exists(diswjj):
391
+ try:
392
+ shutil.rmtree(diswjj)
393
+ except:pass
394
+ try:
395
+ zip_ref.close()
396
+ except:pass
397
+ print('stre',stre,filename)
398
+ raise Exception(e)
399
+ zip_ref.close()
400
+ except Exception as e:
401
+ stre=str(e)
402
+ print('zip解压异常',stre)
403
+ raise Exception(e)
404
+ # if 'File is not a zip file' in stre or 'Bad CRC-32 for fil' in stre:
405
+ # if os.path.exists(diswjj):
406
+ # try:
407
+ # shutil.rmtree(diswjj)
408
+ # except:pass
409
+ # return False
410
+ # else:
411
+ # if os.path.exists(diswjj):
412
+ # shutil.rmtree(diswjj)
413
+ # raise Exception(e)
414
+ #处理中文乱码
415
+ arr=get_file(diswjj,is_folder=False)
416
+ for kkk in arr:
417
+ new_name=kkk['path'].split('/')
418
+ try:
419
+ new_name=kkk['path'].replace(new_name[len(new_name)-1],kkk['name'].encode('cp437').decode("gbk"))
420
+ except:
421
+ # print(kkk['name'],'编码无需要解码')
422
+ pass
423
+ else:
424
+ try:
425
+ os.rename(kkk['path'], new_name)
426
+ except Exception as e:
427
+ stre=str(e)
428
+ if '当文件已存在时,无法创建该文件' in stre:
429
+ pass
430
+ else:
431
+ if os.path.exists(diswjj):
432
+ shutil.rmtree(diswjj)
433
+ raise Exception(e)
434
+ return diswjj
435
+ class kcwstar:
436
+ def targz(src,dst):
437
+ """
438
+ 打包目录为tar.gz
439
+ :param src: 需要打包的目录
440
+ :param dst: 压缩文件名
441
+ :return: bool
442
+ """
443
+ with tarfile.open(dst, "w:gz") as tar:
444
+ tar.add(src, arcname=os.path.basename(src))
445
+ return True
446
+ def untar(dst, src):
447
+ """
448
+ 解压tar.gz文件
449
+ :param dst: 压缩文件名
450
+ :param src: 解压后的存放路径
451
+ :return: bool
452
+ """
453
+ try:
454
+ t = tarfile.open(dst)
455
+ t.extractall(path = src)
456
+ return True
457
+ except Exception as e:
458
+ return False
459
+
460
+ class kcwsign:
461
+ verifres={}
462
+ def verifsign(params,validity=30):
463
+ """验证签名
464
+
465
+ params 验证的参数
466
+
467
+ validity 时间戳超过多少秒失败
468
+ """
469
+ kcwsign.verifres={}
470
+ if not is_index(params,'time') or not is_index(params,'rands') or not is_index(params,'sign'):
471
+ kcwsign.verifres['code']=-16
472
+ kcwsign.verifres['msg']='缺少验证参数'
473
+ return False
474
+ if not params['time'] or not params['rands'] or not params['sign']:
475
+ kcwsign.verifres['code']=-16
476
+ kcwsign.verifres['msg']='验证参数不存在'
477
+ return False
478
+ sign=params['sign']
479
+ del params['sign']
480
+ sjc=int(time.time())-int(params['time'])
481
+ if(sjc>validity or sjc<-validity):
482
+ kcwsign.verifres['code']=-14
483
+ kcwsign.verifres['msg']='时间错误,请调整设备时间,您的设备时间是:'+timestampToDate(params['time'])
484
+ return False
485
+ mysign=kcwsign.getsign(params)
486
+ if mysign==sign:
487
+ kcwsign.verifres['code']=1
488
+ kcwsign.verifres['msg']='验证成功'
489
+ return True
490
+ else:
491
+ if is_index(params,'appkey'):
492
+ params['appkey']='开发者提供的appkey'
493
+ if is_index(params,'paympassword'):
494
+ params['paympassword']='支付密码'
495
+ if is_index(params,'paypwd'):
496
+ params['paypwd']='支付密码'
497
+ if is_index(params,'password'):
498
+ params['password']='密码'
499
+ content=kcwsign.getSignContent(params)
500
+ kcwsign.verifres['code']=-15
501
+ kcwsign.verifres['msg']='签名错误,签名内容可参考:md5('+content+')'
502
+ return False
503
+ def getsign(params):
504
+ """获取签名"""
505
+ if is_index(params,'sign'):
506
+ del params['sign']
507
+ content=kcwsign.getSignContent(params)
508
+ return md5(content)
509
+ def exsignpra(params):
510
+ "生成签名参数"
511
+ params['time']=times()
512
+ params['rands']=randoms()
513
+ params['sign']=kcwsign.getsign(params)
514
+ return params
515
+ def getSignContent(params):
516
+ "字典排序"
517
+ param={}
518
+ for i in sorted (params):
519
+ param[i]=params[i]
520
+ i=0
521
+ strs=""
522
+ for k in param:
523
+ if k:
524
+ if isinstance(k,dict):
525
+ k=json_encode(k)
526
+ k=k.replace('"', '')
527
+ k=k.replace("'", '')
528
+ if param[k]:
529
+ if i==0:
530
+ strs+=str(k)+"="+str(param[k])
531
+ else:
532
+ strs+="&"+str(k)+"="+str(param[k])
533
+ i+=1
534
+ return strs
535
+
405
536
  class create:
406
537
  project=''
407
538
  appname=None
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 1.2
2
2
  Name: kcws
3
- Version: 3.50
3
+ Version: 3.52
4
4
  Summary: kcwebs作为web开发而设计的高性能框架
5
5
  Home-page: https://docs.kwebapp.cn/index/index/2
6
6
  Author: 百里-坤坤
@@ -9,5 +9,5 @@ Maintainer: 坤坤
9
9
  Maintainer-email: fk1402936534@qq.com
10
10
  License: MIT License
11
11
  Description: kcwebs作为web开发而设计的高性能框架,采用全新的架构思想,注重易用性。遵循MIT开源许可协议发布,意味着个人和企业可以免费使用kcwebs,甚至允许把你基于kcwebs开发的应用开源或商业产品发布或销售。完整文档请访问:https://docs.kwebapp.cn/index/index/2
12
- Keywords: kcws3.50
12
+ Keywords: kcws3.52
13
13
  Platform: UNKNOWN
@@ -1,5 +0,0 @@
1
- # -*- coding: utf-8 -*-
2
- from . autoload import *
3
- from . import globals
4
- from . import request
5
- G=globals.G #5.328之后的版本将G作为框架用户全局变量 与之前的“globals.G”功能相同
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes