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)
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
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)
def makeDir(self,filename): makeDir(os.path.dirname(filename))