def execFun(self,fun,str): f= BinMap() f.put("ojson","") rs=self.db.callproc("aws_entrance",[fun,str],f) rs=rs.getvalue(0,"ojson") print(rs) return json.loads(rs)
def http_queryobject(httpMap): querystring=""; regex = re.compile(".+\?(.+)", re.IGNORECASE) out=regex.findall(httpMap.getvalue("HTTP_QUERY_STRING")) if len(out)>0: querystring="&"+out[0] if httpMap.getvalue("HTTP_POST_VARS")!="": querystring="&"+httpMap.getvalue("HTTP_POST_VARS") regex = re.compile("&(\w+)=([^&]+)", re.IGNORECASE) out=regex.findall(querystring) queryobject=BinMap() queryobject.clear() for i in range(len(out)): queryobject.put(out[i][0], out[i][1]) return queryobject
def initArgs(self,args): self.__args=args; if self.__args is None: self.__args=BinMap() self.__args.put('code', '1'); self.__args.put('message', '数据下载成功'); else: if not self.__args.isexists('code'): self.__args.put('code', '1'); if not self.__args.isexists('message'): self.__args.put('message', '数据下载成功'); if not self.__args.isexists('count'): self.__args.put('count', '0'); for i in range(0,self.__args.size()): self.appendElement(self.__args.getkey(i), self.__args.getvalue(num=i))
def __init__(self,connstr=None,host=None,user=None,passwd=None,db=None,port=None): DbModel.__init__(self,connstr,host,user,passwd,db,port) def getCursor(self): if self.port is not None: self.conn= psycopg2.connect(host=self.host,user=self.user,password=self.passwd,database=self.db,port=self.port) else: self.conn= psycopg2.connect(host=self.host,user=self.user,password=self.passwd,database=self.db,port=5432) self.cursor = self.conn.cursor() if __name__=="__main__": import json db=PgModel(host='127.0.0.1', user='******',passwd='windows123',db='awsweb') f= BinMap(); # f.put("login_name","") # f.put("user_name","") # print (db.getSelectResult(f,'1=1','pu_user')).getitem() # f.clear() # f.put("v_json","") # f.put("v_code","") # f.put("v_message","") # rs=db.getSelectResult(f,'1=1','validate_user(\'admin\',\' v_pwd\',null,null,\'web\')') # print rs.getitem() # f.put("ojson","") # rs=db.getSelectResult(f,'1=1','aws_entrance(\'validate_user\',\'admin\')') # print json.loads(rs.getvalue(0,"ojson"))
class ActionXml(Action): __dom=None; __root=None; __args=None; def __init__(self): self.init(); def getList(self,data,items,args=None): self.appendAttribute("type", "list") args.put('count',str(data.size())) self.initArgs(args); rows=self.appendElement('list') for i in range(0,data.size()): row=self.appendElement('item') for j in range(0,items.size()): yitem=str(items.getvalue(num=j)) p = re.compile(r'\[(\w+)\]') for m in p.finditer(yitem): yitem=yitem.replace(str(m.group()),str(data.getvalue(i,str(m.group(1))))) self.appendElement(items.getkey(num=j),yitem,row) rows.appendChild(row) self.__root.appendChild(rows) def getPageList(self,data,items,args=None): self.appendAttribute('type', 'pagelist') rowsCount=data.getvalue(key='rowsCount') rowsData=data.getvalue(key="rows") args.put('count',str(rowsCount)) self.initArgs(args); rows=self.appendElement('list') for i in range(0,rowsData.size()): row=self.appendElement('item') for j in range(0,items.size()): yitem=str(items.getvalue(num=j)) p = re.compile(r'\[(\w+)\]') for m in p.finditer(yitem): yitem=yitem.replace(str(m.group()),str(rowsData.getvalue(i,str(m.group(1))))) self.appendElement(items.getkey(num=j),yitem,row) rows.appendChild(row) self.__root.appendChild(rows) def getResult(self,args): self.initArgs(args); def getInfo(self,data,items,args=None): self.appendAttribute('type', 'info') args.put('count',str(data.size())) self.initArgs(args); rows=self.appendElement('list') for i in range(0,data.size()): content=""; for j in range(0,items.size()): content+="【"+items.getvalue(num=j)+"】"+data.getvalue(i,items.getkey(j)); if j is not items.size()-1: content+="\n"; self.appendElement("item", content, rows) self.__root.appendChild(rows) def init(self): impl = xml.dom.minidom.getDOMImplementation() self.__dom=impl.createDocument(None, "doc", None) self.__root=self.__dom.documentElement def initArgs(self,args): self.__args=args; if self.__args is None: self.__args=BinMap() self.__args.put('code', '1'); self.__args.put('message', '数据下载成功'); else: if not self.__args.isexists('code'): self.__args.put('code', '1'); if not self.__args.isexists('message'): self.__args.put('message', '数据下载成功'); if not self.__args.isexists('count'): self.__args.put('count', '0'); for i in range(0,self.__args.size()): self.appendElement(self.__args.getkey(i), self.__args.getvalue(num=i)) def appendElement(self,item,text=None,parent=None): element=self.__dom.createElement(item); if text is not None: text=self.__dom.createTextNode(text); element.appendChild(text); if parent is None: self.__root.appendChild(element); else: parent.appendChild(element); return element; def appendAttribute(self,key,value,element=None): if element is not None: element.setAttribute(key, value) else: self.__root.setAttribute(key, value) def reponse(self): return self.__dom.toxml('utf-8');
def http_parse_query(meg): http=BinMap(); regex = re.compile("(GET|POST)\s+(.+?)\s+(.+?)\r\n", re.IGNORECASE) out=regex.findall(meg) if len(out)>0: http.setvalue("HTTP_METHOD", out[0][0]) http.setvalue("HTTP_QUERY_STRING", out[0][1]) http.setvalue("HTTP_PROTOCOL", out[0][2]) else: http.setvalue("HTTP_METHOD", "") http.setvalue("HTTP_QUERY_STRING", "") http.setvalue("HTTP_PROTOCOL", "") http_parse_query_item(meg,"Accept:\s+(.+?)\r\n",http,"HTTP_ACCEPT") http_parse_query_item(meg,"Accept-Language:\s+(.+?)\r\n",http,"HTTP_ACCEPT_LANGUAGE") http_parse_query_item(meg,"User-Agent:\s+(.+?)\r\n",http,"HTTP_USER_AGENT") http_parse_query_item(meg,"Content-Type:\s+(.+?)\r\n",http,"HTTP_CONTENT_TYPE") http_parse_query_item(meg,"Accept-Encoding:\s+(.+?)\r\n",http,"HTTP_ACCEPT_ENCODING") http_parse_query_item(meg,"Host:\s+(.+?)\r\n",http,"HTTP_HOST") http_parse_query_item(meg,"Connection:\s+(.+?)\r\n",http,"HTTP_CONNECTION") http_parse_query_item(meg,"Content-Length:\s+(.+?)\r\n",http,"HTTP_CONNECTION_LENGTH") http_parse_query_item(meg,"Cache-Control:\s+(.+?)\r\n",http,"HTTP_CACHE_CONTROL") regex = re.compile("\r\n\r\n(.+)", re.IGNORECASE) out=regex.findall(meg) if len(out)>0: http.setvalue("HTTP_POST_VARS", out[0]) else: http.setvalue("HTTP_POST_VARS", "") return http
def getList(self,data,items,args=None): rs=BinMap() rs.put('code', '1') rs.put('message', '数据正常') rs.put('count', data.size()) rs.put('type','list') rows=[] for i in range(0,data.size()): row=BinMap() for j in range(0,items.size()): yitem=str(items.getvalue(num=j)) p = re.compile(r'\[(\w+)\]') for m in p.finditer(yitem): yitem=yitem.replace(str(m.group()),str(data.getvalue(i,str(m.group(1))))) row.put(items.getkey(num=j), yitem) rows.append(row.getitem()) rs.put('data', rows) return rs