当前位置: 首页>>代码示例>>Python>>正文


Python ServerRequest.isFile方法代码示例

本文整理汇总了Python中cpc.network.server_request.ServerRequest.isFile方法的典型用法代码示例。如果您正苦于以下问题:Python ServerRequest.isFile方法的具体用法?Python ServerRequest.isFile怎么用?Python ServerRequest.isFile使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在cpc.network.server_request.ServerRequest的用法示例。


在下文中一共展示了ServerRequest.isFile方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: handleMultipart

# 需要导入模块: from cpc.network.server_request import ServerRequest [as 别名]
# 或者: from cpc.network.server_request.ServerRequest import isFile [as 别名]
    def handleMultipart(mainHeaders,msgStream):
        files = dict()
        params = dict()

        BOUNDARY = "--"+HttpMethodParser.extractBoundary(mainHeaders)        
        stopBoundary = BOUNDARY+"--"
        terminateBoundary = ''
        
        msgStream.readline() #has an empty line at start that we want to get rid of
          
        while terminateBoundary != stopBoundary:
            headers = mimetools.Message(msgStream)
            
            terminateBoundary = ''
            log.log(cpc.util.log.TRACE,'multipart headers are %s'%headers.headers)
            
            if(ServerRequest.isFile(headers['Content-Disposition'])):
                file = tempfile.TemporaryFile(mode="w+b")
            
            name =  ServerRequest.getFieldName(headers['Content-Disposition'])            
            notused,contentDispositionParams = cgi.parse_header(headers['Content-Disposition'])                        
            name = contentDispositionParams['name']
             
            
            #if we have a content length we just read it and store the data
            
            contentLength = headers.getheader('Content-Length')
            if(contentLength):   # If a content length is sent we parse the nice way
                bytes = int(contentLength)
                if(ServerRequest.isFile(headers['Content-Disposition'])):
                    file.write(msgStream.read(bytes))
                    
                else: 
                    line  = msgStream.read(bytes)
                    log.log(cpc.util.log.TRACE,"line is "+line)
                    params[name] = line  
                    
                msgStream.readline()    ## we will have a trailin CRLF that we just want to get rid of
            
            if(ServerRequest.isFile(headers['Content-Disposition'])):
                readBytes = 0
                while(True):
                    line = msgStream.readline()                    
                    if re.search(BOUNDARY,line):
                        #time to wrap it up
                        
                        if(line[-2:] == '\r\n'):                          
                            line = line[:-2]
                        elif(line[-1:] == '\n'):                     
                            line = line[:-1]
                        
                        terminateBoundary = line                                               
                        
                        file.seek(0)
                        skipBytes = 2

                        realFile = tempfile.TemporaryFile(mode="w+b")
                        realFile.write(file.read(readBytes-skipBytes))
                        
                        file.close()                        
                        realFile.seek(0)
                        
                        #For testing during dev only!!
                        #runTest(realFile)                                                      
                        
                        files[name]= realFile
                        break
                    else:
                        readBytes +=len(line)
                        file.write(line)   
                
            else:  
                while(True):
                    line = msgStream.readline()

                    if(line[-2:] == '\r\n'):                      
                        line = line[:-2]
                    elif(line[-1:] == '\n'):                     
                        line = line[:-1]
                                            
                    if re.search(BOUNDARY,line):       
                        terminateBoundary = line   
                        break;                                 
                    
                    else:
                        if name in params:
                            params[name]+= line
                        else: 
                            params[name] = line    
            
        return ServerRequest(mainHeaders,None,params,files)
开发者ID:ctk3b,项目名称:copernicus,代码行数:93,代码来源:http_method_parser.py


注:本文中的cpc.network.server_request.ServerRequest.isFile方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。