kunapi 1.4__tar.gz → 1.6__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.
Files changed (36) hide show
  1. {kunapi-1.4 → kunapi-1.6}/PKG-INFO +2 -2
  2. {kunapi-1.4 → kunapi-1.6}/kunapi/Events.py +1 -5
  3. {kunapi-1.4 → kunapi-1.6}/kunapi/__init__.py +1 -1
  4. {kunapi-1.4 → kunapi-1.6}/kunapi/app.py +65 -62
  5. {kunapi-1.4 → kunapi-1.6}/kunapi/common/autoload.py +0 -68
  6. kunapi-1.6/kunapi/common/globals.py +9 -0
  7. {kunapi-1.4 → kunapi-1.6}/kunapi/common/request.py +4 -1
  8. {kunapi-1.4 → kunapi-1.6}/kunapi/kunapi.py +13 -19
  9. {kunapi-1.4 → kunapi-1.6}/kunapi.egg-info/PKG-INFO +2 -2
  10. {kunapi-1.4 → kunapi-1.6}/kunapi.egg-info/SOURCES.txt +0 -4
  11. kunapi-1.4/kunapi/common/globals.py +0 -9
  12. kunapi-1.4/kunapi/tempfile/kunapi/app/__init__.py +0 -3
  13. kunapi-1.4/kunapi/tempfile/kunapi/server.py +0 -13
  14. {kunapi-1.4 → kunapi-1.6}/kunapi/common/__init__.py +0 -0
  15. {kunapi-1.4 → kunapi-1.6}/kunapi/config/__init__.py +0 -0
  16. {kunapi-1.4/kunapi/tempfile → kunapi-1.6/kunapi/tempfile/kunapi/app}/__init__.py +0 -0
  17. {kunapi-1.4 → kunapi-1.6}/kunapi/tempfile/kunapi/app/common/__init__.py +0 -0
  18. {kunapi-1.4 → kunapi-1.6}/kunapi/tempfile/kunapi/app/common/autoload.py +0 -0
  19. {kunapi-1.4 → kunapi-1.6}/kunapi/tempfile/kunapi/app/common/model.py +0 -0
  20. {kunapi-1.4 → kunapi-1.6}/kunapi/tempfile/kunapi/app/config/__init__.py +0 -0
  21. {kunapi-1.4 → kunapi-1.6}/kunapi/tempfile/kunapi/app/config/app.py +0 -0
  22. {kunapi-1.4 → kunapi-1.6}/kunapi/tempfile/kunapi/app/index/__init__.py +0 -0
  23. {kunapi-1.4 → kunapi-1.6}/kunapi/tempfile/kunapi/app/index/common/__init__.py +0 -0
  24. {kunapi-1.4 → kunapi-1.6}/kunapi/tempfile/kunapi/app/index/common/autoload.py +0 -0
  25. {kunapi-1.4 → kunapi-1.6}/kunapi/tempfile/kunapi/app/index/controller/__init__.py +0 -0
  26. {kunapi-1.4 → kunapi-1.6}/kunapi/tempfile/kunapi/app/index/controller/index/__init__.py +0 -0
  27. {kunapi-1.4 → kunapi-1.6}/kunapi/tempfile/kunapi/app/index/controller/index/common/__init__.py +0 -0
  28. {kunapi-1.4 → kunapi-1.6}/kunapi/tempfile/kunapi/app/index/controller/index/common/autoload.py +0 -0
  29. {kunapi-1.4 → kunapi-1.6}/kunapi/tempfile/kunapi/app/index/controller/index/common/model.py +0 -0
  30. {kunapi-1.4 → kunapi-1.6}/kunapi/tempfile/kunapi/app/index/controller/index/index.py +0 -0
  31. {kunapi-1.4 → kunapi-1.6}/kunapi.egg-info/dependency_links.txt +0 -0
  32. {kunapi-1.4 → kunapi-1.6}/kunapi.egg-info/entry_points.txt +0 -0
  33. {kunapi-1.4 → kunapi-1.6}/kunapi.egg-info/requires.txt +0 -0
  34. {kunapi-1.4 → kunapi-1.6}/kunapi.egg-info/top_level.txt +0 -0
  35. {kunapi-1.4 → kunapi-1.6}/setup.cfg +0 -0
  36. {kunapi-1.4 → kunapi-1.6}/setup.py +0 -0
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 1.2
2
2
  Name: kunapi
3
- Version: 1.4
3
+ Version: 1.6
4
4
  Summary: kunapi
5
5
  Home-page: https://docs.kwebapp.cn/index/index/2
6
6
  Author: 百里-坤坤
@@ -9,5 +9,5 @@ Maintainer: 坤坤
9
9
  Maintainer-email: fengkun01@qq.com
10
10
  License: MIT License
11
11
  Description: kunapi
12
- Keywords: kunapi1.4
12
+ Keywords: kunapi1.6
13
13
  Platform: UNKNOWN
@@ -67,8 +67,4 @@ class Events:
67
67
  while True:
68
68
  time.sleep(0.1)
69
69
  except KeyboardInterrupt as e:
70
- self.kill_process()
71
- # observer.stop()
72
- # observer.join()
73
-
74
- # Events(['server.py']) #执行server.py文件
70
+ self.kill_process()
@@ -1,5 +1,5 @@
1
1
  # -*- coding: utf-8 -*-
2
- __version__ = '1.4'
2
+ __version__ = '1.6'
3
3
  try:
4
4
  from .app import web
5
5
  except:pass
@@ -73,7 +73,7 @@ class web:
73
73
  env['url_scheme']=env['HTTP_X_REAL_IP']
74
74
  except:
75
75
  env['url_scheme']=env['wsgi.url_scheme'],
76
- status,resheader,body=self.__routes(self,env)
76
+ status,resheader,body=self.__routes(env)
77
77
  if type(body) is bytes:
78
78
  pass
79
79
  else:
@@ -248,9 +248,9 @@ class web:
248
248
  globals.VAR.defmodular=''
249
249
  globals.VAR.defplug=''
250
250
  route=self.__config.route
251
- modular=web.__get_modular(self,header)
251
+ modular=self.__get_modular(header)
252
252
  if route['plug']:
253
- getplug=web.__get_plug(self,header)
253
+ getplug=self.__get_plug(header)
254
254
  else:
255
255
  getplug=''
256
256
  routedefault=route['default']
@@ -270,8 +270,7 @@ class web:
270
270
  # plug=route['plug']
271
271
  if getplug:
272
272
  plug=getplug
273
- routedefault,PATH_INFO=web.__getconfigroute(
274
- self,
273
+ routedefault,PATH_INFO=self.__getconfigroute(
275
274
  PATH_INFO,
276
275
  header
277
276
  )
@@ -288,8 +287,7 @@ class web:
288
287
  param.append(urllib.parse.unquote(path))
289
288
  i+=1
290
289
  else: #配置模块没有配置插件
291
- routedefault,PATH_INFO=web.__getconfigroute(
292
- self,
290
+ routedefault,PATH_INFO=self.__getconfigroute(
293
291
  PATH_INFO,
294
292
  header
295
293
  )
@@ -312,8 +310,7 @@ class web:
312
310
  # plug=route['plug']
313
311
  elif getplug:
314
312
  plug=getplug
315
- routedefault,PATH_INFO=web.__getconfigroute(
316
- self,
313
+ routedefault,PATH_INFO=self.__getconfigroute(
317
314
  PATH_INFO,
318
315
  header
319
316
  )
@@ -333,7 +330,7 @@ class web:
333
330
  param.append(urllib.parse.unquote(path))
334
331
  i+=1
335
332
  else: #完全默认
336
- routedefault,PATH_INFO=web.__getconfigroute(self,PATH_INFO,header)
333
+ routedefault,PATH_INFO=self.__getconfigroute(PATH_INFO,header)
337
334
  if routedefault: #使用默认路由
338
335
  for path in PATH_INFO:
339
336
  if path:
@@ -382,8 +379,21 @@ class web:
382
379
  body=data
383
380
  return body,status,resheader
384
381
  def __set_globals(self,header):
382
+
383
+
384
+ globals.VAR = threading.local()
385
+ globals.HEADER = threading.local()
386
+ globals.G = threading.local()
387
+
388
+ PATH_INFO=header['PATH_INFO'].split('/')
389
+ if PATH_INFO[0]==' ' or PATH_INFO[0]=='':
390
+ del PATH_INFO[0]
391
+ methods,modular,plug,files,funct,param=self.defaultroute(header,PATH_INFO)
392
+ globals.VAR.component=(methods,modular,plug,files,funct,param)
393
+ globals.VAR.defmodular=''
394
+ globals.VAR.defplug=''
395
+
385
396
  globals.HEADER.GET=header
386
- # globals.HEADER.url_scheme=header['url_scheme']
387
397
  globals.HEADER.Method=header['REQUEST_METHOD']
388
398
  globals.HEADER.URL=header['RAW_URI']
389
399
  globals.HEADER.PATH_INFO=header['PATH_INFO']
@@ -405,26 +415,23 @@ class web:
405
415
  globals.HEADER.HTTP_USER_AGENT=header['HTTP_USER_AGENT']
406
416
  except:
407
417
  globals.HEADER.HTTP_USER_AGENT=None
408
- def __del_globals():
409
- globals.VAR = threading.local()
410
- globals.HEADER = threading.local()
411
- globals.G = threading.local()
418
+ def __del_globals(self):
419
+ pass
420
+ globals.VAR = None
421
+ globals.HEADER = None
422
+ globals.G = None
412
423
  def __routes(self,header):
413
424
  body="这是一个http测试服务器"
414
425
  status="200 ok"
415
426
  resheader={"Content-Type":"application/json; charset=utf-8"}
416
- web.__set_globals(self,header)
417
- PATH_INFO=header['PATH_INFO'].split('/')
418
- if PATH_INFO[0]==' ' or PATH_INFO[0]=='':
419
- del PATH_INFO[0]
420
- methods,modular,plug,files,funct,param=web.defaultroute(self,header,PATH_INFO)
421
- globals.VAR.component=(methods,modular,plug,files,funct,param)
427
+ self.__set_globals(header)
428
+ methods,modular,plug,files,funct,param=globals.VAR.component
422
429
  if header['REQUEST_METHOD'] in methods:
423
430
  try:
424
- obj=getattr(web.__appname,modular)
431
+ obj=getattr(self.__appname,modular)
425
432
  except (AttributeError,UnboundLocalError):
426
433
  status="500 Internal Server Error"
427
- body=web.__tpl(
434
+ body=self.__tpl(
428
435
  title = status,
429
436
  e=status,
430
437
  data="路由不存在:"+str(modular)+"/"
@@ -434,7 +441,7 @@ class web:
434
441
  obj=getattr(obj,"controller")
435
442
  except (AttributeError,UnboundLocalError):
436
443
  status="404 Not Found"
437
- body=web.__tpl(
444
+ body=self.__tpl(
438
445
  title = status,
439
446
  e=status,
440
447
  data="路由不存在:"+str(modular)+"/controller/"
@@ -446,15 +453,14 @@ class web:
446
453
  con="无法找到目录:"+str(modular)+"/controller/"+str(plug)+"/"
447
454
  try:
448
455
  data=getattr(obj,"error")(e,con)
449
- body,status,resheader=web.__tran(
450
- self,
456
+ body,status,resheader=self.__tran(
451
457
  data,
452
458
  status,
453
459
  resheader
454
460
  )
455
461
  except (AttributeError,UnboundLocalError):
456
462
  status="404 Not Found"
457
- body=web.__tpl(
463
+ body=self.__tpl(
458
464
  title = status,
459
465
  e=status,data=con
460
466
  )
@@ -464,7 +470,7 @@ class web:
464
470
  if self.__config.app['app_debug']:
465
471
  print(traceback.format_exc())
466
472
  errms=traceback.format_exc().split("\n")
467
- body=web.__tpl(
473
+ body=self.__tpl(
468
474
  title = status,
469
475
  data=errms,e=e
470
476
  )
@@ -475,15 +481,14 @@ class web:
475
481
  con="无法找到文件:"+str(modular)+"/controller/"+str(plug)+"/"+str(files)+".py"
476
482
  try:
477
483
  data=getattr(obj,"error")(e,con)
478
- body,status,resheader=web.__tran(
479
- self
480
- ,data
484
+ body,status,resheader=self.__tran(
485
+ data
481
486
  ,status
482
487
  ,resheader
483
488
  )
484
489
  except (AttributeError,UnboundLocalError):
485
490
  status="404 Not Found"
486
- body=web.__tpl(
491
+ body=self.__tpl(
487
492
  title = status
488
493
  ,data=con
489
494
  ,e=status)
@@ -493,7 +498,7 @@ class web:
493
498
  if self.__config.app['app_debug']:
494
499
  print(traceback.format_exc())
495
500
  errms=traceback.format_exc().split("\n")
496
- body=web.__tpl(
501
+ body=self.__tpl(
497
502
  title = status,
498
503
  data=errms,
499
504
  e=e
@@ -505,8 +510,8 @@ class web:
505
510
  try:
506
511
  data=getattr(obj,self.__config.app['before_request'])()
507
512
  if data:
508
- body,status,resheader=web.__tran(
509
- self,data,
513
+ body,status,resheader=self.__tran(
514
+ data,
510
515
  status,
511
516
  resheader
512
517
  )
@@ -516,8 +521,8 @@ class web:
516
521
  except Exception as e:
517
522
  try:
518
523
  data=getattr(obj,"error")(e,traceback.format_exc().split("\n"))
519
- body,status,resheader=web.__tran(
520
- self,data,
524
+ body,status,resheader=self.__tran(
525
+ data,
521
526
  status,
522
527
  resheader
523
528
  )
@@ -527,7 +532,7 @@ class web:
527
532
  errms=status
528
533
  if self.__config.app['app_debug']:
529
534
  errms=traceback.format_exc().split("\n")
530
- body=web.__tpl(
535
+ body=self.__tpl(
531
536
  title = status,
532
537
  data=errms,e=e
533
538
  )
@@ -538,7 +543,7 @@ class web:
538
543
  if self.__config.app['app_debug']:
539
544
  print(traceback.format_exc())
540
545
  errms=traceback.format_exc().split("\n")
541
- body=web.__tpl(
546
+ body=self.__tpl(
542
547
  title = status,
543
548
  data=errms,e=e
544
549
  )
@@ -549,16 +554,16 @@ class web:
549
554
  data=getattr(obj,funct)(*param) #兼容性之前的控制器
550
555
  else:
551
556
  data=getattr(objclass,funct)(*param)
552
- body,status,resheader=web.__tran(
553
- self,data,
557
+ body,status,resheader=self.__tran(
558
+ data,
554
559
  status,
555
560
  resheader
556
561
  )
557
562
  except Exception as e:
558
563
  try:
559
564
  data=getattr(obj,"error")(e,traceback.format_exc().split("\n"))
560
- body,status,resheader=web.__tran(
561
- self,data,
565
+ body,status,resheader=self.__tran(
566
+ data,
562
567
  status,
563
568
  resheader
564
569
  )
@@ -568,7 +573,7 @@ class web:
568
573
  if self.__config.app['app_debug']:
569
574
  print(traceback.format_exc())
570
575
  errms=traceback.format_exc().split("\n")
571
- body=web.__tpl(
576
+ body=self.__tpl(
572
577
  title = status,
573
578
  data=errms,
574
579
  e=e
@@ -579,14 +584,14 @@ class web:
579
584
  if self.__config.app['app_debug']:
580
585
  print(traceback.format_exc())
581
586
  errms=traceback.format_exc().split("\n")
582
- body=web.__tpl(
587
+ body=self.__tpl(
583
588
  title = status,
584
589
  data=errms,
585
590
  e=e
586
591
  )
587
592
  else:
588
593
  status="405 Method Not Allowed"
589
- body=web.__tpl(
594
+ body=self.__tpl(
590
595
  title = status,
591
596
  data='405 Method Not Allowed',
592
597
  e=''
@@ -600,13 +605,13 @@ class web:
600
605
  try:
601
606
  data=getattr(obj,self.__config.app['after_request'])(body,status,resheader)
602
607
  if data:
603
- body,status,resheader=web.__tran(self,data,status,resheader)
608
+ body,status,resheader=self.__tran(data,status,resheader)
604
609
  except (AttributeError,UnboundLocalError):pass
605
610
  except Exception as e:
606
611
  try:
607
612
  data=getattr(obj,"error")(e,traceback.format_exc().split("\n"))
608
- body,status,resheader=web.__tran(
609
- self,data,
613
+ body,status,resheader=self.__tran(
614
+ data,
610
615
  status,
611
616
  resheader
612
617
  )
@@ -616,7 +621,7 @@ class web:
616
621
  if self.__config.app['app_debug']:
617
622
  print(traceback.format_exc())
618
623
  errms=traceback.format_exc().split("\n")
619
- body=web.__tpl(
624
+ body=self.__tpl(
620
625
  title = status
621
626
  ,data=errms,
622
627
  e=e
@@ -627,7 +632,7 @@ class web:
627
632
  if self.__config.app['app_debug']:
628
633
  print(traceback.format_exc())
629
634
  errms=traceback.format_exc().split("\n")
630
- body=web.__tpl(
635
+ body=self.__tpl(
631
636
  title = status,
632
637
  data=errms,
633
638
  e=""
@@ -635,15 +640,12 @@ class web:
635
640
  resheaders=[]
636
641
  for key in resheader:
637
642
  resheaders.append((key,resheader[key]))
638
- web.__del_globals()
639
-
640
-
641
643
  if self.__config.fdgrsgrsegsrsgrsbsdbftbrsbfdrtrtbdfsrsgr=='kwebs' or self.__config.fdgrsgrsegsrsgrsbsdbftbrsbfdrtrtbdfsrsgr=='kwebsp':#请求后执行的函数
642
644
  try:
643
645
  getattr(obj,"rfdsgeagesegdsfdsfdrrsebskwebsafterrequest")() #关闭数据库相关连接
644
646
  except:pass
645
647
 
646
-
648
+ self.__del_globals()
647
649
  if isinstance(resheaders,list):
648
650
  if not body:
649
651
  body=''
@@ -653,15 +655,15 @@ class web:
653
655
  body=str(body)
654
656
  return str(status),resheaders,body
655
657
  else:
656
- raise Exception()
657
- def __tpl(**context):
658
+ raise
659
+ def __tpl(self,**context):
658
660
  arr=json_encode({
659
661
  'title':context['title'],
660
662
  'msg':str(context['e']),
661
663
  'error':context['data']
662
664
  })
663
665
  return arr
664
- # def __tpl(**context):
666
+ # def __tpl(__tpl,**context):
665
667
  # title,status,error=context
666
668
  # arr=json_encode({
667
669
  # 'title':title,
@@ -728,6 +730,7 @@ class web:
728
730
  'HTTP_X_REAL_IP':env.get('HTTP_X_REAL_IP'),
729
731
  'files':files
730
732
  }
733
+
731
734
  p=(config.app['staticpath']+reqheader['RAW_URI'].replace(' ',''))
732
735
  status='200 ok'
733
736
  if os.path.isfile(p):
@@ -760,7 +763,7 @@ class web:
760
763
  resheader.append(("Last-Modified",otherStyleTime))
761
764
  resheader.append(("ETag",ETag))
762
765
  else:
763
- status,resheader,body=web.__routes(self,reqheader)
766
+ status,resheader,body=self.__routes(reqheader)
764
767
  from kunapi import __version__
765
768
  resheader.append(('Server', "kunapi-"+__version__))
766
769
  if type(body) is bytes:
@@ -769,7 +772,7 @@ class web:
769
772
  body=bytes(body, encoding='utf-8')
770
773
  start_response(status,resheader)
771
774
  return [body]
772
- def __waitress(self,host,port):
775
+ def __waitress(self,host,port,threads=1):
773
776
  if host=='0.0.0.0':
774
777
  print("\033[32m* (CTRL+单击打开)http://127.0.0.1:"+str(port)+"(按CTRL+C退出)")
775
778
  else:
@@ -779,8 +782,8 @@ class web:
779
782
  else:
780
783
  print('\033[37m* 调试器:已关闭')
781
784
  from waitress import serve
782
- serve(self.__application, host=host, port=port)
783
- def __http_wsgi(self,host,port,filename):
785
+ serve(self.__application, host=host, port=port,threads=threads,channel_timeout=3600) #框架不支持多线程 所以 threads设为1
786
+ def __http_wsgi(self,host,port):
784
787
  "http——wsgi测试服务 windows建议使用Waitress‌"
785
788
  from wsgiref.simple_server import make_server
786
789
  print("* \033[1;31;40m! 警告:\033[0m这是一个wsgiref开发服务器。不要在生产环境中部署使用它")
@@ -834,58 +834,6 @@ class create:
834
834
  import pip
835
835
  if not os.path.exists(self.project+self.appname):
836
836
  raise Exception('项目不存在')
837
- # if config.fdgrsgrsegsrsgrsbsdbftbrsbfdrtrtbdfsrsgr=='kwebsp':
838
- # r=requests.get(config.domain['kcwebsfile']+"/kunapi/kwebsp.zip")
839
- # f = open("./"+self.project+"k.zip", "wb")
840
- # for chunk in r.iter_content(chunk_size=512):
841
- # if chunk:
842
- # f.write(chunk)
843
- # f.close()
844
- # kcwszip.unzip_file("./"+self.project+"kwebsp.zip","./"+self.project+self.appname)
845
- # os.remove("./"+self.project+"kwebsp.zip")
846
- # elif config.fdgrsgrsegsrsgrsbsdbftbrsbfdrtrtbdfsrsgr=='kwebs':
847
- # r=requests.get(config.domain['kcwebsfile']+"/kunapi/kwebs.zip")
848
- # f = open("./"+self.project+"kwebs.zip", "wb")
849
- # for chunk in r.iter_content(chunk_size=512):
850
- # if chunk:
851
- # f.write(chunk)
852
- # f.close()
853
- # kcwszip.unzip_file("./"+self.project+"kwebs.zip","./"+self.project+self.appname)
854
- # os.remove("./"+self.project+"kwebs.zip")
855
- # elif config.fdgrsgrsegsrsgrsbsdbftbrsbfdrtrtbdfsrsgr=='kunapi':
856
- # r=requests.get(config.domain['kcwebsfile']+"/kapi/kapi.zip")
857
- # f = open("./"+self.project+"kapi.zip", "wb")
858
- # for chunk in r.iter_content(chunk_size=512):
859
- # if chunk:
860
- # f.write(chunk)
861
- # f.close()
862
- # kcwszip.unzip_file("./"+self.project+"kapi.zip","./"+self.project+self.appname)
863
- # os.remove("./"+self.project+"kapi.zip")
864
- # else:
865
- # raise Exception('包名错误')
866
- # if not os.path.isfile("./"+self.project+"server.py"):
867
- # # if "Windows" in platform.platform():
868
- # # pythonname="python"
869
- # # else:
870
- # # pythonname="python3.8"
871
- # servertext=('#项目运行文件,请务修改\n'+
872
- # 'import kunapi,sys,'+self.appname+'\n'+
873
- # 'app=kunapi.web(__name__,'+self.appname+')\n'+
874
- # 'if __name__ == "__main__":\n'+
875
- # ' try:\n'+
876
- # ' route=sys.argv[1]\n'+
877
- # ' if "eventlog"==route:\n'+
878
- # ' raise Exception("")\n'+
879
- # ' except:\n'+
880
- # ' #host监听ip port端口 name python解释器名字 (windows一般是python linux一般是python3) \n'+
881
- # ' app.run(host="0.0.0.0",port="39001",name="python3.8")\n'+
882
- # ' else:\n'+
883
- # ' app.cli(route)\n'
884
- # )
885
- # f=open("./"+self.project+"server.py","w+",encoding='utf-8')
886
- # f.write(servertext)
887
- # f.close()
888
- # return True,"应用创建成功"
889
837
  else:
890
838
  if not os.path.isfile(self.project+self.appname+"/__init__.py") or not os.path.exists(self.project+self.appname+"/common"):
891
839
  return False,self.appname+"不是kunapi应用"
@@ -1010,22 +958,6 @@ class create:
1010
958
  f.close()
1011
959
  else:
1012
960
  return False,self.modular+"模块下载失败"
1013
- if not os.path.isfile("./server.py"):
1014
- if "Windows" in platform.platform():
1015
- pythonname="python"
1016
- else:
1017
- pythonname="python3"
1018
- # sys.argv[0]=re.sub('.py','',sys.argv[0])
1019
- servertext=('# -*- coding: utf-8 -*-\n#gunicorn -b 0.0.0.0:39010 '+self.appname+':app\n'+
1020
- 'from kunapi import web\n'+
1021
- 'import '+self.appname+' as application\n'+
1022
- 'app=web(__name__,application)\n'+
1023
- 'if __name__ == "__main__":\n'+
1024
- ' #host监听ip port端口 name python解释器名字 (windows一般是python linux一般是python3)\n'+
1025
- ' app.run(host="0.0.0.0",port="39001",name="'+pythonname+'")')
1026
- f=open("./"+self.project+"server.py","w+",encoding='utf-8')
1027
- f.write(servertext)
1028
- f.close()
1029
961
  return True,"安装成功"
1030
962
  else:
1031
963
 
@@ -0,0 +1,9 @@
1
+ # -*- coding: utf-8 -*-
2
+ import threading
3
+ ##普通全局变量 请求结束后删除
4
+ VAR = threading.local()
5
+ HEADER = threading.local()
6
+ G = threading.local()
7
+
8
+
9
+
@@ -113,7 +113,10 @@ class HEADER:
113
113
  def SERVER_PROTOCOL():
114
114
  return kcwsglobals.HEADER.SERVER_PROTOCOL
115
115
  def HTTP_HOST():
116
- return kcwsglobals.HEADER.HTTP_HOST
116
+ if kcwsglobals.HEADER.HTTP_HOST:
117
+ return kcwsglobals.HEADER.HTTP_HOST
118
+ else:
119
+ return ''
117
120
  def HTTP_COOKIE():
118
121
  return kcwsglobals.HEADER.HTTP_COOKIE
119
122
  def HTTP_USER_AGENT():
@@ -11,6 +11,10 @@ def get_cmd_par(fdgrsgrsegsrsgrsbsdbftbrsbfdrtrtbdfsrsgr=''):
11
11
  if python_version[0:3]!='3.8':
12
12
  print("\033[1;31;40m "+fdgrsgrsegsrsgrsbsdbftbrsbfdrtrtbdfsrsgr1+"依赖python3.8,与你现在的python"+python_version+"不兼容")
13
13
  exit()
14
+ if 'Linux' in get_sysinfo()['platform'] or 'Windows' in get_sysinfo()['platform']:pass
15
+ else:
16
+ print("\033[1;31;40m "+fdgrsgrsegsrsgrsbsdbftbrsbfdrtrtbdfsrsgr1+"不支持当前操作系统 解压在linux或windows系统下运行")
17
+ exit()
14
18
  try:
15
19
  opts, args = getopt.getopt(sys.argv[1:], "h", ["project=","app=","modular=","plug=","user=","pwd=","host=","port=","timeout=","processcount=",
16
20
  "install","uninstall","pack","upload","cli"])
@@ -236,7 +240,7 @@ def cllfunction():
236
240
  exit()
237
241
  config.fdgrsgrsegsrsgrsbsdbftbrsbfdrtrtbdfsrsgr=fdgrsgrsegsrsgrsbsdbftbrsbfdrtrtbdfsrsgr1
238
242
  types=sys.argv[len(sys.argv)-1]
239
- if True:# os.name == 'nt':
243
+ if os.name == 'nt':
240
244
  from kunapi import web
241
245
  try:
242
246
  import app as application
@@ -256,25 +260,14 @@ def cllfunction():
256
260
  else:
257
261
  save_route_cli_pid('pid/'+str(sys.argv[tar-1])+fdgrsgrsegsrsgrsbsdbftbrsbfdrtrtbdfsrsgr1+'_server_pid')
258
262
  app.run(host=cmd_par['host'],port=int(cmd_par['port']))
259
- else:
263
+ elif 'Linux' in get_sysinfo()['platform']:
260
264
  pythonpath=site.getsitepackages()[0].replace('\\','/')
261
265
  t=pythonpath.split('/')
262
266
  tt='/'+t[-3]+'/'+t[-2]+'/'+t[-1]
263
267
  pythonpath=pythonpath.replace(tt,'')
264
268
  if not os.path.exists('/usr/bin/'+fdgrsgrsegsrsgrsbsdbftbrsbfdrtrtbdfsrsgr1) and os.path.isfile(pythonpath+'/bin/'+fdgrsgrsegsrsgrsbsdbftbrsbfdrtrtbdfsrsgr1):
265
269
  os.system("ln -s "+pythonpath+"/bin/"+fdgrsgrsegsrsgrsbsdbftbrsbfdrtrtbdfsrsgr1+" /usr/bin/"+fdgrsgrsegsrsgrsbsdbftbrsbfdrtrtbdfsrsgr1)
266
- # if types=='-stop' or types=='-start':
267
- # pass
268
- # else:
269
- # print("启动参数错误,支持 -start和-stop")
270
- # exit()
271
- # try:
272
- # f=open("pid",'r')
273
- # pid=f.read()
274
- # f.close()
275
- # if pid:
276
- # os.system("kill "+pid)
277
- # except:pass
270
+
278
271
  if __name__ == 'kunapi.kunapi':
279
272
  kill_route_cli('pid/'+fdgrsgrsegsrsgrsbsdbftbrsbfdrtrtbdfsrsgr1+'_server_pid')
280
273
  try:
@@ -292,7 +285,8 @@ def cllfunction():
292
285
  sys.argv=[sys.argv[0], '-w', str(cmd_par['processcount']), '-b', cmd_par['host']+':'+str(cmd_par['port']),'-t',cmd_par['timeout'], 'server:'+cmd_par['appname']]
293
286
  sys.exit(run())
294
287
  exit()
295
-
288
+ else:
289
+ raise Exception('不支持该操作系统')
296
290
  elif cmd_par['install'] or cmd_par['pack'] or cmd_par['upload'] or cmd_par['uninstall']:
297
291
  if cmd_par['install']:#插入 应用、模块、插件
298
292
  if cmd_par['appname'] and cmd_par['modular']:
@@ -308,13 +302,13 @@ def cllfunction():
308
302
  remppath=os.path.split(os.path.realpath(__file__))[0]
309
303
  if not os.path.exists(cmd_par['project']+'/'+cmd_par['appname']) and not os.path.exists(cmd_par['appname']):
310
304
  shutil.copytree(remppath+'/tempfile/kunapi',cmd_par['project'])
311
- if get_sysinfo()['uname'][0]=='Linux':
305
+ if os.name == 'nt':
312
306
  try:
313
- os.remove(cmd_par['project']+"/server.bat")
307
+ os.remove(cmd_par['project']+"/server.sh")
314
308
  except:pass
315
- elif get_sysinfo()['uname'][0]=='Windows':
309
+ else:
316
310
  try:
317
- os.remove(cmd_par['project']+"/server.sh")
311
+ os.remove(cmd_par['project']+"/server.bat")
318
312
  except:pass
319
313
  print('kunapi项目创建成功')
320
314
  exit()
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 1.2
2
2
  Name: kunapi
3
- Version: 1.4
3
+ Version: 1.6
4
4
  Summary: kunapi
5
5
  Home-page: https://docs.kwebapp.cn/index/index/2
6
6
  Author: 百里-坤坤
@@ -9,5 +9,5 @@ Maintainer: 坤坤
9
9
  Maintainer-email: fengkun01@qq.com
10
10
  License: MIT License
11
11
  Description: kunapi
12
- Keywords: kunapi1.4
12
+ Keywords: kunapi1.6
13
13
  Platform: UNKNOWN
@@ -14,8 +14,6 @@ kunapi/common/autoload.py
14
14
  kunapi/common/globals.py
15
15
  kunapi/common/request.py
16
16
  kunapi/config/__init__.py
17
- kunapi/tempfile/__init__.py
18
- kunapi/tempfile/kunapi/server.py
19
17
  kunapi/tempfile/kunapi/app/__init__.py
20
18
  kunapi/tempfile/kunapi/app/common/__init__.py
21
19
  kunapi/tempfile/kunapi/app/common/autoload.py
@@ -36,8 +34,6 @@ kunapi/common/autoload.py
36
34
  kunapi/common/globals.py
37
35
  kunapi/common/request.py
38
36
  kunapi/config/__init__.py
39
- kunapi/tempfile/__init__.py
40
- kunapi/tempfile/kunapi/server.py
41
37
  kunapi/tempfile/kunapi/app/__init__.py
42
38
  kunapi/tempfile/kunapi/app/common/__init__.py
43
39
  kunapi/tempfile/kunapi/app/common/autoload.py
@@ -1,9 +0,0 @@
1
- # -*- coding: utf-8 -*-
2
- from threading import local
3
- ##普通全局变量 请求结束后删除
4
- VAR = local()
5
- HEADER = local()
6
- G = local()
7
-
8
-
9
-
@@ -1,3 +0,0 @@
1
- # -*- coding: utf-8 -*-
2
- # #导入模块
3
- from . import index
@@ -1,13 +0,0 @@
1
- #项目运行文件,请务修改
2
- import kunapi,sys,app
3
- app=kunapi.web(__name__,app)
4
- if __name__ == "__main__":
5
- try:
6
- route=sys.argv[1]
7
- if "eventlog"==route:
8
- raise Exception("")
9
- except:
10
- #host监听ip port端口 name python解释器名字 (windows一般是python linux一般是python3)
11
- app.run(host="0.0.0.0",port="3000",name="python3.8")
12
- else:
13
- app.cli(route)
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes