diff --git a/LICENSE b/LICENSE
index 6cebfc2212fdf7935dd338cb3f5520d334f3f940..e57e69a5be5508ee28532f589e3e30fb5eb69066 100644
--- a/LICENSE
+++ b/LICENSE
@@ -1,6 +1,6 @@
MIT License
-Copyright (c) 2020 坤坤
+Copyright (c) 2020 冯树坤
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
diff --git a/README.md b/README.md
index 7dee6dd9b198d69f9dc93c34c6ad9647cf5e8914..e3f3a9c856c65da3904f5190344f28ea4aacf057 100644
--- a/README.md
+++ b/README.md
@@ -1,66 +1,20 @@
-完整文档请参考:http://intapp.kwebapp.cn/index/index/doc/docde/1
-#### 创建应用
-- 新建一个server.py文件,内容如下,执行python3 server.py创建应用
-- 如下面的代码创建了一个app应用,同时在app应用下创建了一个api模块
-```server.py
-from kcweb.create import create
-create("app","api") # 创建项目
-```
-- 您的目录结构应该是这样,如下:
-```
-├─./ 框架目录
-├─app 公共方法目录
-│ ├─common 公共函数目录
-│ │ ├─__init__.py 函数文件
-│ ├─config 配置目录
-│ │ ├─__init__.py 配置文件
-│ ├─api 模块目录
-│ │ ├─common 该模块的公共函数目录
-│ │ │ ├─__init__.py 函数文件
-│ │ ├─controller 控制器目录
-│ │ │ ├─__init__.py 版本初始化文件
-│ │ │ ├─v1
-│ │ │ │ ├─__init__.py 函数初始化文件
-│ │ │ │ ├─index.py 控制器文件
-│ │ │ ├─v2
-│ │ │ │ ├─__init__.py 函数初始化文件
-│ │ │ │ ├─index.py 控制器文件
-│ │ ├─tpl 模板文件目录
-│ │ │ ├─v1
-│ │ │ │ ├─index
-│ │ │ │ │ ├─index.html 模块文件
-│ │ │ ├─v1
-│ │ │ │ ├─index
-│ │ │ │ │ ├─index.html 模块文件
-│ │ ├─__init__.py 控制器初始化文件
-│ ├─static 静态资源目录
-│ ├─runtime 缓存目录
-│ ├─__init__.py 自动导入模块文件
-├─server.py 应用创建后生成的运行文件(应用创建时自动创建)
-```
-- 其中server.py文件内容将被修改如下
-```
-# #gunicorn -b 0.0.0.0:39001 server:app
-from kcweb import web
-import app as application
-app=web(__name__,application)
-if __name__ == "__main__":
- #app 是当前文件名 host监听ip port端口 name python解释器名字 (windows一般是python linux一般是python3)
- app.run("server",host="0.0.0.0",port="39001",name="python")
-```
-- 如果您当前系统的python解释器名字是python3,你应该是在当前目录下执行python3 server.py。 然后访问127.0.0.1:39001
+
kcweb==4.12.3框架简要说明
+kcweb作为web开发而设计的高性能框架,采用全新的架构思想,注重易用性。遵循MIT开源许可协议发布,意味着个人和企业可以免费使用kcweb,甚至允许把你基于kcweb开发的应用开源或商业产品发布或销售。
-- 如果您当前系统的python解释器名字是python,您应该修改server.py代码如下
-```
-# #gunicorn -b 0.0.0.0:39001 server:app
-from kcweb import web
-import app as application
-app=web(__name__,application)
-if __name__ == "__main__":
- #app 是当前文件名 host监听ip port端口
- app.run("server",host="0.0.0.0",port="39001",name="python")
-```
-然后访问127.0.0.1:39001
+[官方完整文档](https://intapp.kwebapp.cn/intapp/doc/index/finddoc/1/29/1 "官方文档")
+------------
+
+- 状态
+>
+开发版
+
+----
+
+- 兼容性
+>
+向下兼容到4.12.2
+
+-----
diff --git a/app.py b/app.py
index ebf10f982bce01a59420027a2bcac8c796167aff..d631d601d89d3842429ca567da56c806de0acb63 100644
--- a/app.py
+++ b/app.py
@@ -69,11 +69,20 @@ class web:
env['BODY_DATA']=str(env['wsgi.input'].next(), encoding = "utf-8")
except:
env['BODY_DATA']=""
+ try:
+ env['HTTP_X_REAL_IP']=env['HTTP_X_REAL_IP']
+ except:
+ env['HTTP_X_REAL_IP']=""
+ try:
+ env['url_scheme']=env['HTTP_X_REAL_IP']
+ except:
+ env['url_scheme']=env['wsgi.url_scheme'],
status,resheader,body=self.__routes(self,env)
if type(body) is bytes:
pass
else:
body=bytes(body, encoding='utf-8')
+ # print(env)
start_response(status,resheader)
return [body]
return apps
@@ -123,6 +132,7 @@ class web:
'HTTP_HOST':'',
'HTTP_COOKIE':'',
'REMOTE_ADDR':'',
+ 'HTTP_X_REAL_IP':'',
'HTTP_USER_AGENT':'',
'BODY_DATA':''
}
@@ -358,6 +368,7 @@ class web:
return body,status,resheader
def __set_globals(self,header):
globals.HEADER.GET=header
+ # globals.HEADER.url_scheme=header['url_scheme']
globals.HEADER.Method=header['REQUEST_METHOD']
globals.HEADER.URL=header['RAW_URI']
globals.HEADER.PATH_INFO=header['PATH_INFO']
@@ -365,6 +376,8 @@ class web:
globals.HEADER.SERVER_PROTOCOL=header['SERVER_PROTOCOL']
globals.HEADER.HTTP_HOST=header['HTTP_HOST']
globals.HEADER.BODY_DATA=header['BODY_DATA']
+ globals.HEADER.REMOTE_ADDR=header['REMOTE_ADDR']
+ globals.HEADER.HTTP_X_REAL_IP=header['HTTP_X_REAL_IP']
try:
globals.HEADER.files=header['files']
except:
@@ -563,7 +576,7 @@ class web:
if self.__config.app['after_request']: #请求后执行的函数
try:
- data=getattr(obj,self.__config.app['after_request'])()
+ data=getattr(obj,self.__config.app['after_request'])(body,status,resheader)
if data:
body,status,resheader=web.__tran(self,data,status,resheader)
except (AttributeError,UnboundLocalError):pass
@@ -652,19 +665,24 @@ class web:
except:
env['REMOTE_ADDR']=''
try:
- env['HTTP_COOKIE']
+ env['wsgi.url_scheme']
except:
- env['HTTP_COOKIE']=''
+ env['wsgi.url_scheme']=''
try:
- env['REMOTE_ADDR']
+ env['HTTP_X_REAL_IP']
except:
- env['REMOTE_ADDR']=''
+ env['HTTP_X_REAL_IP']=''
+ try:
+ env['HTTP_COOKIE']
+ except:
+ env['HTTP_COOKIE']=''
try:
env['HTTP_USER_AGENT']
except:
env['HTTP_USER_AGENT']=''
reqheader={
'REQUEST_METHOD':env['REQUEST_METHOD'],
+ 'url_scheme':env['wsgi.url_scheme'],
'RAW_URI':env['RAW_URI'],
'PATH_INFO':env['PATH_INFO'],
'QUERY_STRING':env['QUERY_STRING'],
@@ -674,6 +692,7 @@ class web:
'REMOTE_ADDR':env['REMOTE_ADDR'],
'HTTP_USER_AGENT':env['HTTP_USER_AGENT'],
'BODY_DATA':env['BODY_DATA'],
+ 'HTTP_X_REAL_IP':env['HTTP_X_REAL_IP'],
'files':files
}
p=(config.app['staticpath']+reqheader['RAW_URI'].replace(' ',''))
@@ -792,6 +811,7 @@ class web:
'HTTP_HOST':HTTP_HOST,
'HTTP_COOKIE':HTTP_COOKIE,
'REMOTE_ADDR':REMOTE_ADDR,
+ 'HTTP_X_REAL_IP':'',
'HTTP_USER_AGENT':HTTP_USER_AGENT,
'BODY_DATA':BODY_DATA
}
@@ -909,6 +929,7 @@ class web:
'HTTP_HOST':HTTP_HOST,
'HTTP_COOKIE':HTTP_COOKIE,
'REMOTE_ADDR':REMOTE_ADDR,
+ 'HTTP_X_REAL_IP':'',
'HTTP_USER_AGENT':HTTP_USER_AGENT,
'BODY_DATA':BODY_DATA
}
diff --git a/common/autoload.py b/common/autoload.py
index 974efdf2755b08a3729bf55122a6a76a922a286a..a015f40f0cfff3d1adde492eb1d36e360646cf3e 100644
--- a/common/autoload.py
+++ b/common/autoload.py
@@ -310,6 +310,12 @@ def Templates(path,**context):
t=lookup.get_template(path)
body=t.render(**context)
return body
+def getfunction(strs):
+ """获取指定文件对象
+
+ strs :app.index.common.autoload 获取app/index/common/目录下的autoload对象
+ """
+ return importlib.import_module(strs)
def mysql(table=None,configss=None):
"""mysql数据库操作实例
@@ -581,6 +587,7 @@ class kcwtar:
return False
class response:
+ tpldata={} #公共模板变量
def tpl(path=None,status='200 ok',response_cache=False,ETag=None,header={"Content-Type":"text/html; charset=utf-8"},**context):
"""返回模板内容
@@ -594,6 +601,13 @@ class response:
header 响应头
"""
+ for k in dir(response):
+ if k not in ['download','json','pic','redirect','tpl','tpldata','video'] and k[-2:]!='__':
+ try:
+ context[k]=response.__dict__[k]
+ except KeyError:
+ pass
+ context['config']=config
headers=copy.deepcopy(header)
getroutecomponent=globals.VAR.component
if path:
@@ -623,16 +637,16 @@ class response:
else:
headers['response_cache']="default"
set_cache(ETag,1)
- body=Template(Temppath,config=config,**context)
+ body=Template(Temppath,**context)
dateArray = core_datetime.datetime.utcfromtimestamp(times()-86400)
otherStyleTime = dateArray.strftime('%a, %d %b %Y %H:%M:%S GMT')
headers['Last-Modified']=otherStyleTime
headers['ETag']=ETag
return body,status,headers
elif status:
- return Template(Temppath,config=config,**context),status,headers
+ return Template(Temppath,tpldata=response.tpldata,**context),status,headers
else:
- return Template(Temppath,config=config,**context),'200 ok',headers
+ return Template(Temppath,tpldata=response.tpldata,**context),'200 ok',headers
def json(res=[],status='200 ok',response_cache=False,ETag=None,header={"Content-Type":"application/json; charset=utf-8","Access-Control-Allow-Origin":"*"}):
"""响应json内容
@@ -892,6 +906,9 @@ class create:
elif arr['code']==0:
os.remove(self.appname+"/"+self.modular+"/controller/"+plug+".zip")
return True,arr['msg']
+ elif arr['code']==0:
+ os.remove(self.appname+"/"+self.modular+"/controller/"+plug+".zip")
+ return False,arr['msg']
else:
os.remove(self.appname+"/"+self.modular+"/controller/"+plug+".zip")
return False,arr['msg']
@@ -906,6 +923,7 @@ class create:
else:
http=Http()
i=0
+ j=0
tplug=plug
modular=self.modular
while True:
@@ -926,91 +944,91 @@ class create:
modular="api"
tplug="index" #默认插件
elif arr['code']==0 and arr['data']:
+ i=0
+ j+=1
arr=arr['data']
- tttttt=0
- while True:
- if tttttt<5:
- r=requests.get(arr['dowurl'])
- f = open(self.appname+"/"+self.modular+"/controller/"+plug+".zip", "wb")
- for chunk in r.iter_content(chunk_size=512):
- if chunk:
- f.write(chunk)
- f.close()
- if zipfile.is_zipfile(self.appname+"/"+self.modular+"/controller/"+plug+".zip"):
- break
- else:
- tttttt+=1
- else:
- return False,plug+"插件下载失败"
- if os.path.isfile(self.appname+"/"+self.modular+"/controller/"+plug+".zip"):#安装打包好的插件
- zip.unzip_file(self.appname+"/"+self.modular+"/controller/"+plug+".zip",self.appname+"/"+self.modular+"/controller/"+plug+"/")
- os.remove(self.appname+"/"+self.modular+"/controller/"+plug+".zip")
- if os.path.isfile(self.appname+"/"+self.modular+"/controller/"+plug+"/install.txt"): #安装依赖包
- install_requires=[]
- try:
- f=open(self.appname+"/"+self.modular+"/controller/"+plug+"/install.txt")
- while True:
- line = f.readline()
- if not line:
- break
- elif len(line) > 2:
- install_requires.append(line)
- f.close()
- except:
- shutil.rmtree(self.appname+"."+self.modular+"/controller/"+plug)
- return False,"error"
- if len(install_requires):
- try:
- install_requires.insert(0,"install")
- if 0 != pip.main(install_requires):
- shutil.rmtree(self.appname+"/"+self.modular+"/controller/"+plug)
- return False,"error"
- except AttributeError as e:
- shutil.rmtree(self.appname+"/"+self.modular+"/controller/"+plug)
- if config.app['app_debug']:
- print("建议更新您的pip版本。参考命令:Python -m pip install --user --upgrade pip -i https://mirrors.aliyun.com/pypi/simple/")
- return False,str(e)
- # try:
- # m=importlib.import_module(self.appname+"."+self.modular+"/controller/"+plug+".install")
- # except:
- # shutil.rmtree(self.appname+"."+self.modular+"/controller/"+plug)
- # print(traceback.format_exc())
- # return False,"插件依赖包文件不存在或依赖包文件格式错误"
- # else:
- # try:
- # a=m.install()
- # except:
- # shutil.rmtree(self.appname+"."+self.modular+"/controller/"+plug)
- # return False,"插件依赖包install函数被破坏"
- # if not a[0]:
- # shutil.rmtree(self.appname+"."+self.modular+"/controller/"+plug)
- # return False,str(a[1])
-
- f=open(self.appname+"/"+self.modular+"/controller/__init__.py","r",encoding='utf-8')
- text=f.read()
- f.close()
- text=re.sub("\nfrom . import "+plug,"",text)
- text=re.sub("from . import "+plug,"",text)
- f=open(self.appname+"/"+self.modular+"/controller/__init__.py","w",encoding='utf-8')
- text+="\nfrom . import "+plug
- f.write(text)
- f.close()
-
- f=open(self.appname+"/"+self.modular+"/controller/"+plug+"/common/autoload.py","r",encoding='utf-8')
- text=f.read()
- f.close()
- text=re.sub("app.api",self.appname+"."+self.modular,text)
- f=open(self.appname+"/"+self.modular+"/controller/"+plug+"/common/autoload.py","w",encoding='utf-8')
- f.write(text)
- f.close()
-
- return True,"插件安装成功,"+plug+"=="+str(arr['edition'])
- else:
+ r=requests.get(arr['dowurl'])
+ f = open(self.appname+"/"+self.modular+"/controller/"+plug+".zip", "wb")
+ for chunk in r.iter_content(chunk_size=512):
+ if chunk:
+ f.write(chunk)
+ f.close()
+ if zipfile.is_zipfile(self.appname+"/"+self.modular+"/controller/"+plug+".zip") and os.path.isfile(self.appname+"/"+self.modular+"/controller/"+plug+".zip"):
+ break
+ if j >= 10:
return False,str(plug)+"插件下载失败"
+ time.sleep(0.1)
else:
- return False,str(plug)+"插件下载失败"
+ return False,str(plug)+"插件搜索失败"
else:
return False,self.modular+"模块下找不到"+str(plug)+"插件"
+ if os.path.isfile(self.appname+"/"+self.modular+"/controller/"+plug+".zip"):#安装打包好的插件
+ zip.unzip_file(self.appname+"/"+self.modular+"/controller/"+plug+".zip",self.appname+"/"+self.modular+"/controller/"+plug+"/")
+ os.remove(self.appname+"/"+self.modular+"/controller/"+plug+".zip")
+ if os.path.isfile(self.appname+"/"+self.modular+"/controller/"+plug+"/install.txt"): #安装依赖包
+ install_requires=[]
+ try:
+ f=open(self.appname+"/"+self.modular+"/controller/"+plug+"/install.txt")
+ while True:
+ line = f.readline()
+ if not line:
+ break
+ elif len(line) > 2:
+ install_requires.append(line)
+ f.close()
+ except:
+ shutil.rmtree(self.appname+"."+self.modular+"/controller/"+plug)
+ return False,"error"
+ if len(install_requires):
+ try:
+ install_requires.insert(0,"install")
+ if 0 != pip.main(install_requires):
+ shutil.rmtree(self.appname+"/"+self.modular+"/controller/"+plug)
+ return False,"error"
+ except AttributeError as e:
+ shutil.rmtree(self.appname+"/"+self.modular+"/controller/"+plug)
+ if config.app['app_debug']:
+ print("建议更新您的pip版本。参考命令:Python -m pip install --user --upgrade pip -i https://mirrors.aliyun.com/pypi/simple/")
+ return False,str(e)
+ if os.path.isfile(self.appname+"."+self.modular+"/controller/"+plug+"/install.py"):
+ try:
+ m=importlib.import_module(self.appname+"."+self.modular+"/controller/"+plug+".install")
+ except:
+ shutil.rmtree(self.appname+"."+self.modular+"/controller/"+plug)
+ print(traceback.format_exc())
+ return False,"插件依赖包文件不存在或依赖包文件格式错误"
+ else:
+ try:
+ a=m.install()
+ except:
+ shutil.rmtree(self.appname+"."+self.modular+"/controller/"+plug)
+ return False,"插件依赖包install函数被破坏"
+ # if not a[0]:
+ # shutil.rmtree(self.appname+"."+self.modular+"/controller/"+plug)
+ # return False,str(a[1])
+
+ f=open(self.appname+"/"+self.modular+"/controller/__init__.py","r",encoding='utf-8')
+ text=f.read()
+ f.close()
+ text=re.sub("\nfrom . import "+plug,"",text)
+ text=re.sub("from . import "+plug,"",text)
+ f=open(self.appname+"/"+self.modular+"/controller/__init__.py","w",encoding='utf-8')
+ text+="\nfrom . import "+plug
+ f.write(text)
+ f.close()
+
+ f=open(self.appname+"/"+self.modular+"/controller/"+plug+"/common/autoload.py","r",encoding='utf-8')
+ text=f.read()
+ f.close()
+ text=re.sub("app.api",self.appname+"."+self.modular,text)
+ f=open(self.appname+"/"+self.modular+"/controller/"+plug+"/common/autoload.py","w",encoding='utf-8')
+ f.write(text)
+ f.close()
+
+
+ return True,"插件安装成功,"+plug+"=="+str(arr['edition'])
+ else:
+ return False,str(plug)+"插件获取失败"
def uninstallmodular(self):
"卸载模块"
f=open(self.appname+"/__init__.py","r")
@@ -1123,11 +1141,31 @@ class create:
"from "+self.appname+" import config\n"+
"G=globals.G")
f.close()
+
+ content=''
+ f=open(self.appname+"/"+self.modular+"/common/autoload.py","r",encoding='utf-8')
+ while True:
+ line = f.readline()
+ if not line:
+ break
+ elif 'from' not in line and 'import' not in line:
+ content+=line
+ f.close()
f=open(self.appname+"/"+self.modular+"/common/autoload.py","w",encoding='utf-8')
- f.write("from "+self.appname+".common import *")
+ f.write("from "+self.appname+".common import *\n"+content)
+ f.close()
+
+ content=''
+ f=open(self.appname+"/"+self.modular+"/controller/index/common/autoload.py","r",encoding='utf-8')
+ while True:
+ line = f.readline()
+ if not line:
+ break
+ elif 'from' not in line and 'import' not in line:
+ content+=line
f.close()
f=open(self.appname+"/"+self.modular+"/controller/index/common/autoload.py","w",encoding='utf-8')
- f.write("from "+self.appname+"."+self.modular+".common import *")
+ f.write("from "+self.appname+"."+self.modular+".common import *\n"+content)
f.close()
return True,"应用创建成功"
else:
@@ -1157,12 +1195,19 @@ class create:
modular="api"
elif arr['code']==0 and arr['data']:
arr=arr['data']
- r=requests.get(arr['dowurl'])
- f = open(self.appname+"/"+self.modular+".zip", "wb")
- for chunk in r.iter_content(chunk_size=1024*100):
- if chunk:
- f.write(chunk)
- f.close()
+ #循环下载模块
+ i=0
+ while i < 5:
+ r=requests.get(arr['dowurl'])
+ f = open(self.appname+"/"+self.modular+".zip", "wb")
+ for chunk in r.iter_content(chunk_size=1024*100):
+ if chunk:
+ f.write(chunk)
+ f.close()
+ time.sleep(0.3)
+ if os.path.isfile(self.appname+"/"+self.modular+".zip"):
+ break
+ i+=1
if os.path.isfile(self.appname+"/"+self.modular+".zip"):#安装打包好的模块
zip.unzip_file(self.appname+"/"+self.modular+".zip",self.appname+"/"+self.modular+"/")
os.remove(self.appname+"/"+self.modular+".zip")
@@ -1192,33 +1237,51 @@ class create:
if config.app['app_debug']:
print("建议更新您的pip版本。参考命令:Python -m pip install --user --upgrade pip -i https://mirrors.aliyun.com/pypi/simple/")
return False,str(e)
- # try:
- # m=importlib.import_module(self.appname+'.'+self.modular+'.install')
- # except:
- # shutil.rmtree(self.appname+"/"+self.modular)
- # print(traceback.format_exc())
- # return False,"模块依赖包文件不存在或依赖包文件格式错误"
- # else:
- # try:
- # a=m.install()
- # except:
- # shutil.rmtree(self.appname+"/"+self.modular)
- # return False,"模块依赖包install方法被破坏"
- # if not a[0]:
- # shutil.rmtree(self.appname+"/"+self.modular)
- # return False,str(a[1])
+ if os.path.isfile(self.appname+"/"+self.modular+"/install.py"):#如果存在依赖文件
+ try:
+ m=importlib.import_module(self.appname+'.'+self.modular+'.install')
+ except:
+ shutil.rmtree(self.appname+"/"+self.modular)
+ print(traceback.format_exc())
+ return False,"模块依赖包文件不存在或依赖包文件格式错误"
+ else:
+ try:
+ a=m.install()
+ except:
+ shutil.rmtree(self.appname+"/"+self.modular)
+ return False,"模块依赖包install方法被破坏"
+ # if not a[0]:
+ # shutil.rmtree(self.appname+"/"+self.modular)
+ # return False,str(a[1])
content="\nfrom . import "+self.modular
f=open(self.appname+"/__init__.py","a",encoding='utf-8')
f.write(content)
f.close()
-
+ content=''
+ f=open(self.appname+"/"+self.modular+"/common/autoload.py","r",encoding='utf-8')
+ while True:
+ line = f.readline()
+ if not line:
+ break
+ elif 'from' not in line and 'import' not in line:
+ content+=line
f.close()
f=open(self.appname+"/"+self.modular+"/common/autoload.py","w",encoding='utf-8')
- f.write("from "+self.appname+".common import *")
+ f.write("from "+self.appname+".common import *\n"+content)
+ f.close()
+
+ content=''
+ f=open(self.appname+"/"+self.modular+"/controller/index/common/autoload.py","r",encoding='utf-8')
+ while True:
+ line = f.readline()
+ if not line:
+ break
+ elif 'from' not in line and 'import' not in line:
+ content+=line
f.close()
f=open(self.appname+"/"+self.modular+"/controller/index/common/autoload.py","w",encoding='utf-8')
- f.write("from "+self.appname+"."+self.modular+".common import *")
+ f.write("from "+self.appname+"."+self.modular+".common import *\n"+content)
f.close()
else:
return False,self.modular+"模块下载失败"
diff --git a/common/request.py b/common/request.py
index 4a65a1da2cf0d87911d532912817df0b22802c60..d566aa3a54b6a8b200dc92d71a7432c7bedb419d 100644
--- a/common/request.py
+++ b/common/request.py
@@ -118,6 +118,20 @@ class HEADER:
return kcwglobals.HEADER.HTTP_COOKIE
def HTTP_USER_AGENT():
return kcwglobals.HEADER.HTTP_USER_AGENT
+ def REMOTE_ADDR():
+ return kcwglobals.HEADER.REMOTE_ADDR
+ def HTTP_X_REAL_IP():
+ "nginx服务器发送的客户端IP"
+ return kcwglobals.HEADER.HTTP_X_REAL_IP
+ def Physical_IP():
+ "获取访问用户物理ip"
+ if kcwglobals.HEADER.HTTP_X_REAL_IP:
+ return kcwglobals.HEADER.HTTP_X_REAL_IP
+ else:
+ return kcwglobals.HEADER.REMOTE_ADDR
+ # def url_scheme():
+ # "获取http类型 待测试"
+ # return kcwglobals.HEADER.url_scheme
def get_data():
"获取请求参数体"
return kcwglobals.HEADER.BODY_DATA
diff --git a/config/__init__.py b/config/__init__.py
index 830b36307e2d0d2da6e94b29ba4ed10e693679b2..938fc680fc25a6226a87e2b8a24ec4c582f7f4ec 100644
--- a/config/__init__.py
+++ b/config/__init__.py
@@ -100,7 +100,7 @@ email['recNick']='' #默认收件人昵称
kcweb={}
kcweb['name']='kcweb' #项目的名称
-kcweb['version']='4.12.2' #项目版本
+kcweb['version']='4.12.5' #项目版本
kcweb['description']='' #项目的简单描述
kcweb['long_description']='' #项目详细描述
kcweb['license']='MIT' #开源协议 mit开源
@@ -116,7 +116,7 @@ domain={}
domain['kcwebfile']="https://file.kwebapp.cn"
domain['kcwebstatic']="https://static.kwebapp.cn"
domain['kcwebimg']="https://img.kwebapp.cn"
-# domain['kcwebapi']="https://kcweb.kwebapp.cn"
+# domain['kcwebapi']="//kcweb.kwebapp.cn"
domain['kcwebapi']="https://kcweb.kwebapp.cn"
#其他配置
diff --git a/setup.py b/setup.py
index 1d4a1c242983f7ead24deb4659e31d8e77a4d19b..2b3993ed5ee67838a5e30feecc491a175be3d221 100644
--- a/setup.py
+++ b/setup.py
@@ -1,7 +1,7 @@
# python setup.py sdist upload
# twine upload --repository-url https://test.pypi.org/legacy/ dist/* #上传到测试
-# pip install --index-url https://test.pypi.org/simple/ kcweb #安装测试服务上的kcweb
+# pip install --index-url https://pypi.org/simple/ kcweb #安装测试服务上的kcweb pip3 install kcweb==4.12.4 -i https://pypi.org/simple/
#############################################
from setuptools import setup, find_packages,Extension
import os
@@ -16,7 +16,7 @@ def file_get_content(k):
return con
confkcw={}
confkcw['name']='kcweb' #项目的名称
-confkcw['version']='4.12.2' #项目版本
+confkcw['version']='4.12.5' #项目版本
confkcw['description']='' #项目的简单描述
confkcw['long_description']="增加websocket" #项目详细描述
confkcw['license']='MIT License' #开源协议 mit开源
diff --git a/utill/db/mysql.py b/utill/db/mysql.py
index c2598e816e35e0464d29902ef0bec79194edce4e..905706420082335ae84d5524aa6617ce2a8341b8 100644
--- a/utill/db/mysql.py
+++ b/utill/db/mysql.py
@@ -2,7 +2,7 @@
from .pymysql import connect,escape_string
# import config.conf as config
import kcweb.config as config
-import time,traceback,decimal,random #,copy
+import time,traceback,decimal,random,copy
dbconfig=config.database
class mysql:
"""数据库实例"""
@@ -20,7 +20,7 @@ class mysql:
def __del__(self):
pass
def close(self):
- "关闭连接,该方法无需理会,框架自动完成"
+ "关闭连接,web一下模式下该方法无需理会,框架自动完成"
if not self.__config['pattern'] and mysql.__conn:
if self.__connlists:
for k in self.__connlists:
@@ -38,7 +38,7 @@ class mysql:
i=0
for thost in self.__config['host']:
identifier=thost+str(self.__config['port'][i])+self.__config['user'][i]+self.__config['password'][i]+self.__config['db'][i]
- print(mysql.__conn)
+ # print(mysql.__conn)
for k in mysql.__conn[identifier]:
try:
k['obj'].close()
@@ -55,6 +55,7 @@ class mysql:
mysql.__conn={}
if self.__config['debug']:
print("mysql短连接已关闭",mysql.__conn)
+ mysql.__config=copy.deepcopy(dbconfig)
__dbcount=1
def __setdbcount(self):
"设置数据库配置总数量"
@@ -631,7 +632,9 @@ class mysql:
result = self.__cursor.fetchall() #获取查询结果
self.__cursor.close()
self.__None()
- cou=int(result[0][0])
+ cou=result[0][0]
+ if not cou:
+ cou=0
return cou
def setinc(self,field,key=1,affair=False):
@@ -718,20 +721,22 @@ class mysql:
增删改后的任务进行提交
"""
- if not self.__config['pattern']:
- self.__conn[self.__masteridentifier].commit()
- else:
- self.__conn[self.__masteridentifier][self.__dbobjident]['obj'].commit()
+ if self.__masteridentifier:
+ if not self.__config['pattern']:
+ self.__conn[self.__masteridentifier].commit()
+ else:
+ self.__conn[self.__masteridentifier][self.__dbobjident]['obj'].commit()
def rollback(self):
"""事务回滚
增删改后的任务进行撤销
"""
- if not self.__config['pattern']:
- self.__conn[self.__masteridentifier].rollback()
- else:
- self.__conn[self.__masteridentifier][self.__dbobjident]['obj'].rollback()
+ if self.__masteridentifier:
+ if not self.__config['pattern']:
+ self.__conn[self.__masteridentifier].rollback()
+ else:
+ self.__conn[self.__masteridentifier][self.__dbobjident]['obj'].rollback()
def getsql(self):
"""得到生成的sql语句"""
return self.__sql
@@ -947,7 +952,7 @@ class mysql:
elif types=='sum':
self.__sql="SELECT SUM(%s) FROM %s" % (self.__field,self.__table)
elif types=='setinc':
- self.__sql="update %s set %s=%s+%d" % (self.__table,data['field'],data['field'],data['key'])
+ self.__sql="update %s set %s=%s+%s" % (self.__table,data['field'],data['field'],data['key'])
elif types=='update':
strs=''
for k in data: