def restart_server(self): self.sessionFileRemove() self.topyFileRemove() print("start to parser Config") parser=configParser.pyLatteConfigPaser() self.urlMap=parser.getUrlMap() self.databaseInfo = parser.getDataBaseInfo() self.filterMap=parser.getFilterMap() print("end to parser Config\n") print("start to pylToPy") for item in self.urlMap.values(): print("processing pylTopy : "+item) #Looking for filter to execute before pyl files executed. filterStr = "" for item1 in self.filterMap.keys(): if item in self.filterMap[item1]: filterStr += open('pyl/'+item1, encoding='utf-8').read()+"\n" #print(str) #print(filterStr); #if item in self.filterMap p=pylToPy.pylToPy(item,filterStr) p.outPy() print("end to pylToPy\n") print(pylatte_AsciiArt) pass
def application(environ, start_response): headerInfo = requestHeaderInfo.requestHeaderInfo(environ).getHeaderInfo() param = parse_qs(environ.get('QUERY_STRING', '')) path = environ.get('PATH_INFO', '') logging.debug("GET method Parameters "+str(param)) logging.debug("path : "+path) logging.debug("urlMap : "+str(environ["urlMap"])) logging.debug("filterMap : "+str(environ["filterMap"])) logging.debug("Cookie : "+headerInfo["HTTP_COOKIE"]) try: pylPath=environ["urlMap"][path] except KeyError: """미리 xml로 명시한 동적 요청이 아닐 경우 여기로 들어오기 되어 있음. 여기서 정적파일을 찾은 후 없으면 404 not found. """ try: path = path.replace("..","") in_file = open(os.getcwd()+path,"rb") staticFile = in_file.read() in_file.close() except IOError: return not_found(environ, start_response) start_response('200 OK', []) return [staticFile] pass moduleName=pylPath.split('.')[0] logging.debug("moduleName : "+moduleName) urlTest_pyl=moduleName+'_pyl' logging.debug(urlTest_pyl) sessionutil =sessionUtil.session cookies=headerInfo["HTTP_COOKIE"].split(";"); latteSession="" for item in cookies: cookie = item.split("=") if cookie[0]=="PYLATTESESSIONID": #logging.debug (cookie[1]) latteSession=cookie[1] #if there is no cookie value, make a new cookie value. if latteSession=="": sessionKey = sessionutil.genSessionKey(sessionutil) #If there is a cookie value, get the value from head information and put into sessionKey variable. else: sessionKey = latteSession logging.debug("session ID : "+sessionKey); try: sessionData = sessionutil.getSessionData(sessionutil,sessionKey) except IOError: sessionData ="" sessionDic = sessionutil.sessionDataTodict(sessionutil,sessionData) #---------------------make pyl to py logging.debug("make PYLtoPY-----------------------") logging.debug("path : "+path) a = environ["urlMap"] item = None if a.get(path)!=None: logging.debug(a.get(path)) item = a.get(path) logging.debug(environ["urlMap"]) logging.debug("urlMap : "+str(environ["urlMap"])) logging.debug("filterMap : "+str(environ["filterMap"])) logging.debug("make end PYLtoPY-----------------------") logging.debug("start to pylToPy") #Looking for filter to execute before pyl files executed. filterMap=environ["filterMap"] filterStr = "" for item1 in filterMap.keys(): if item in filterMap[item1]: filterStr += open('pyl/'+item1, encoding='utf-8').read()+"\n" p=pylToPy.pylToPy(item,filterStr) p.outPy() logging.debug("end to pylToPy\n") #--------------------- sys.path.append(os.path.join(os.getcwd(), 'topy')) logging.debug(sys.path) pyl = __import__(urlTest_pyl) imp.reload(pyl) logging.debug("Got started to process dynamic Page") pyFile=None; databaseInfo=tuple() module=getattr(pyl, moduleName)(param,pyFile,sessionDic,headerInfo,databaseInfo) logging.debug("processing DynamicPage End") htmlcode = module.getHtml() # completely generaged HTML #logging.debug(htmlcode) start_response('200 OK', [('Content-Type', 'text/html')]) return [bytes(htmlcode,'utf-8')]