Example #1
0
    def do_GET(self):
        latteSession=""
        headerInfo=requestHeaderInfo.requestHeaderInfo(self)
        
        print("request url :" +self.path)

        #get GET parameters value.
        param=methodGetGetParam.methodGetGetParam(self.path)

        self.pyFile=None; #no file uploaded
        
        
        
        url = self.path.split('?')[0]
        try:
            self.path=self.urlMap[url]
            moduleName=self.path.split('.')[0]
            print("moduleName : "+moduleName)
            urlTest_pyl=moduleName+'_pyl'
            
            #Checking a cookie value to know whether session exists or not.
            print("Cookie : "+headerInfo.getHeaderInfo()["Cookie"])
            
            sessionutil =sessionUtil.session
            
            cookies=headerInfo.getHeaderInfo()["Cookie"].split(";");

            
            for item in cookies:
                cookie = item.split("=")
                if cookie[0]=="PYLATTESESSIONID":
                    #print (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
                
            print("session ID : "+sessionKey);
            
            try:
                sessionData = sessionutil.getSessionData(sessionutil,sessionKey)
            except IOError:
                sessionData =""
                
            sessionDic = sessionutil.sessionDataTodict(sessionutil,sessionData)
            
            #print(urlTest_pyl)
            folders = ['./topy']
            pyl = __import__(urlTest_pyl,fromlist=[folders])
            imp.reload(pyl)
            print("Got started to process dynamic Page")
            module=getattr(pyl, moduleName)(param.getParam(),self.pyFile,sessionDic,headerInfo.getHeaderInfo(),self.databaseInfo)
            #print("processing DynamicPage End")
            htmlcode = module.getHtml()    # completely generaged HTML
            #print(htmlcode)
            finalSessionDic=module.getSession()
            sessionData = sessionutil.dictToSessionData(sessionutil,finalSessionDic)
            
            sessionutil.setSessionData(sessionutil,sessionKey, sessionData)
            ##wf = open("temp.html","w")
            ##wf.write(htmlcode)
            ##wf.close()
            self.dynamicHtml = htmlcode;
            self.isPyl=True

        except KeyError:# If there is nothing to process dynamically, look for static thing
            print('Not Found pyl')
            self.isPyl=False
            sessionKey=None
            pass
        except TypeError:
            print('Error - Result of processing SQL is None. NoneType object is not subscriptable.')
            pass
        
        
        if(self.isPyl == True):
            #if session value is same
            try:
                if latteSession=="" and sessionKey!=None:
                    try:
                        self.send_head("PYLATTESESSIONID="+sessionKey+"; "+headerInfo.getHeaderInfo()["Cookie"])
                    except TypeError:
                        self.send_head("PYLATTESESSIONID="+sessionKey)
                else:
                    self.send_head(None)#send sessionid to header
            except IndexError:
                self.send_head(None)
                
            self.wfile.write(bytes(self.dynamicHtml, 'UTF-8'))
        else:
            f = self.send_head(None)
            
            if f:
                self.copyfile(f, self.wfile)
                f.close()
        print("\n")
        pass
Example #2
0
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')]
Example #3
0
    def do_POST(self):
        latteSession=""
        
        headerInfo=requestHeaderInfo.requestHeaderInfo(self)
        
        print(self.path)
        
        #print("Start of getting POST parameter")
        post_payload = self.rfile.read(int(headerInfo.getHeaderInfo()["Content-Length"]));
        print(post_payload)
        if post_payload.find(b'Content-Disposition: form-data')!=-1:
            print("multy-part upload");
            import Pylatte.WebServer.postMultipartForm as postMultipartForm
            param=postMultipartForm.postMultipartForm(post_payload)
            self.pyFile=param.getFileInfo()
            
        else:
            param=methodGetPostParam.methodGetPostParam(str(post_payload))
            self.pyFile=None;
        #print("End of getting POST parameter")
        
        
        
        url = self.path
        try:
            self.path=self.urlMap[url]
            moduleName=self.path.split('.')[0]
            print("moduleName : "+moduleName)
            urlTest_pyl=moduleName+'_pyl'
            
            
            #print(urlTest_pyl)
            folders = ['./topy']
            pyl = __import__(urlTest_pyl,fromlist=[folders])#import py files which is generated from pyl files.
            imp.reload(pyl)
            #Checking a cookie value to know whether session exists or not.
            print("Cookie:"+headerInfo.getHeaderInfo()["Cookie"])
            
            sessionutil =sessionUtil.session
            
            cookies=headerInfo.getHeaderInfo()["Cookie"].split(";");
    
            for item in cookies:
                cookie = item.split("=")
                if cookie[0]=="PYLATTESESSIONID":
                    #print (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
                
            print("session ID : "+sessionKey);
            
            try:
                sessionData = sessionutil.getSessionData(sessionutil, sessionKey)
            except IOError:
                sessionData =""
                
            sessionDic = sessionutil.sessionDataTodict(sessionutil,sessionData)
            
            print("processing Dynamic Page")
            module=getattr(pyl, moduleName)(param.getParam(),self.pyFile,sessionDic,headerInfo.getHeaderInfo(),self.databaseInfo)
            #print("processing Dynamic Page End")
            
            #세션유지시킬 값도 가져와야됨.
            
            htmlcode = module.getHtml()
            #print(htmlcode)
            finalSessionDic=module.getSession()
            sessionData = sessionutil.dictToSessionData(sessionutil,finalSessionDic)
            
            sessionutil.setSessionData(sessionutil,sessionKey, sessionData)
            ##wf = open("temp.html","w")
            ##wf.write(htmlcode)
            ##wf.close()
            self.dynamicHtml = htmlcode;
            self.isPyl=True

        except KeyError:# If there is nothing to process dynamically, look for static thing
            print('Not Found pyl')
            self.isPyl=False
            sessionKey=None
            pass
        except TypeError:
            print('Error - Result of processing SQL is None. NoneType object is not subscriptable.')
            pass
        
        
        if(self.isPyl == True):
            #if session value is same
            try:
                if latteSession=="" and sessionKey!=None:
                    try:
                        self.send_head("PYLATTESESSIONID="+sessionKey+"; "+headerInfo.getHeaderInfo()["Cookie"])
                    except TypeError:
                        self.send_head("PYLATTESESSIONID="+sessionKey)
                else:
                    self.send_head(None)#send sessionid to header
            except IndexError:
                self.send_head(None)
                
            self.wfile.write(bytes(self.dynamicHtml, 'UTF-8'))
        else:
            f = self.send_head(None)
            
            if f:
                self.copyfile(f, self.wfile)
                f.close()
                
        print("\n")
        pass