Exemplo n.º 1
0
 def getMimeType(self,buffre,url,mtype):
     
     if '?' in url:
         url = url.split('?')[0]
         
     mime = MimeTypes()
     ext = os.path.splitext(url)[1]
     if mtype == 'text/html' and ext == '':
         if url[-1] == '/':
             l = len(url)-1
             
             url = url[0:-1]                         
         url = url+'/index.html'
         ext = '.html'
         
     #ext1 = mime.guess_extension(mtype,True)
     #print ext1
     mime_type = mime.guess_type(url)        
     #print url
     if ext:
         #print url
         u = urlparse.urlparse(url)
         #print u.netloc,u.path
         print self.host
         if self.host:
             root_dir = self.root_dir+"/"+self.host
             
         file_path = os.path.join(root_dir,u.netloc+u.path)
         print file_path
         #if not os.path.isfile(file_path):
         makeDir(os.path.dirname(file_path))
         f = open(file_path,"wb")            
         f.write(buffre)            
Exemplo n.º 2
0
Arquivo: ptdb.py Projeto: ptphp/PtPy
 def open(self,dbname):
     dbpath =  os.path.abspath(dbname)
     makeDir(os.path.dirname(dbpath))
     try:
         self.conn = sqlite3.connect(dbpath)
     except Exception , e:
         #print trace_back()
         #error_log(trace_back())
         return False        
Exemplo n.º 3
0
 def setUrlCache(self,url,v,level = 3):
     #if self.cache == False:
     #    return        
     vv = {}
     vv['url']     = v['url']        
     vv['headers'] = v['headers']        
     vv['cache']   = True
     vv['body']    = v['body'] 
     vv['local']    = v['local']        
     cp = PtCp()        
     path = self.getUrlCacheFile(url,level)
     makeDir(os.path.dirname(path))
     cp.dump(vv, path)
Exemplo n.º 4
0
 def makeDir(self,filename):
     makeDir(os.path.dirname(filename))