コード例 #1
0
ファイル: theme_files.py プロジェクト: healthkxy/micolog
    def get(self):
    	request_path = self.request.path[8:]
    	server_path = os.path.normpath(os.path.join(cwd, 'themes', request_path))
    	fstat=os.stat(server_path)
    	fmtime=datetime.fromtimestamp(fstat[stat.ST_MTIME])

    	if self.request.if_modified_since and self.request.if_modified_since.replace(tzinfo=None) >= fmtime:
    		self.response.headers['Date'] = format_date(datetime.utcnow())
    		self.response.headers['Last-Modified'] = format_date(fmtime)
    		cache_expires(self.response, max_age)
    		self.response.set_status(304)
    		self.response.clear()

    	elif server_path.startswith(theme_path):
    		ext = os.path.splitext(server_path)[1]
    		if types_map.has_key(ext):
    			mime_type = types_map[ext]
    		else:
    			mime_type = 'application/octet-stream'
    		try:
    			self.response.headers['Content-Type'] = mime_type
    			self.response.headers['Last-Modified'] = format_date(fmtime)
    			cache_expires(self.response, max_age)
    			self.response.out.write(open(server_path, 'rb').read())
    		except Exception, e:
    		    Error404(self)
コード例 #2
0
ファイル: plog.py プロジェクト: jfojfo/foblog
    def get(self):
        cwd = os.getcwd()
        theme_path = os.path.join(cwd, 'themes')
        max_age = 600  #expires in 10 minutes

        request_path = self.request.path[len(settings.app_root) + len('/themes/'):]
        server_path = os.path.normpath(os.path.join(cwd, 'themes', request_path))
        last_config_time = memcache.obj_last_modify['config'].replace(microsecond=0)

        if self.request.if_modified_since and self.request.if_modified_since.replace(tzinfo=None) >= last_config_time:
            self.response.headers['Date'] = format_date(datetime.datetime.utcnow())
            self.response.headers['Last-Modified'] = format_date(last_config_time)
            cache_expires(self.response, max_age)
            self.response.set_status(304)
            self.response.clear()

        elif server_path.startswith(theme_path):
            ext = os.path.splitext(server_path)[1]
            if types_map.has_key(ext):
                mime_type = types_map[ext]
            else:
                mime_type = 'application/octet-stream'
            try:
                self.response.headers['Content-Type'] = mime_type
                self.response.headers['Last-Modified'] = format_date(last_config_time)
                cache_expires(self.response, max_age)
                self.response.out.write(open(server_path, 'rb').read())
            except Exception, e:
                logging.info(e)
                self.error_404()
コード例 #3
0
    def get(self, prefix, name):
        request_path = self.request.path[13:]

        server_path = os.path.normpath(
            os.path.join(cwd, 'themes', request_path))
        #server_path = cwd + "/themes" + request_path

        try:
            fstat = os.stat(server_path)
        except:
            #use zipfile
            theme_file = os.path.normpath(os.path.join(cwd, 'themes', prefix))
            if os.path.exists(theme_file + ".zip"):
                #is file exist?
                fstat = os.stat(theme_file + ".zip")
                zipdo = ZipHandler()
                zipdo.initialize(self.request, self.response)
                return zipdo.get(theme_file, name)
            else:
                Error404(self)
                return

        fmtime = datetime.fromtimestamp(fstat[stat.ST_MTIME])
        #logging.info("QUAMIME %s",os.path.splitext(server_path)[1])
        if self.request.if_modified_since and self.request.if_modified_since.replace(
                tzinfo=None) >= fmtime:
            self.response.headers['Date'] = format_date(datetime.utcnow())
            self.response.headers['Last-Modified'] = format_date(fmtime)
            cache_expires(self.response, max_age)
            self.response.set_status(304)
            self.response.clear()
        elif server_path.startswith(theme_path):
            ext = os.path.splitext(server_path)[1]
            if types_map.has_key(ext):
                mime_type = types_map[ext]
            else:
                mime_type = 'application/octet-stream'
            try:
                #logging.info("MIMETYPE %s %s",mime_type,ext)
                self.response.headers['Content-Type'] = mime_type
                self.response.headers['Last-Modified'] = format_date(fmtime)
                cache_expires(self.response, max_age)
                #logging.info("MIMETYPE in resp %s %s",str(self.response.headers),self.response.headers['Content-Type'])
                self.response.out.write(open(server_path, 'rb').read())
            except Exception, e:
                Error404(self)
コード例 #4
0
    def get(self,prefix,name):
        request_path = self.request.path[13:]


        server_path = os.path.normpath(os.path.join(cwd, 'themes', request_path))
        #server_path = cwd + "/themes" + request_path

        try:
            fstat=os.stat(server_path)
        except:
            #use zipfile
            theme_file=os.path.normpath(os.path.join(cwd, 'themes', prefix))
            if os.path.exists(theme_file+".zip"):
                #is file exist?
                fstat=os.stat(theme_file+".zip")
                zipdo=ZipHandler()
                zipdo.initialize(self.request,self.response)
                return zipdo.get(theme_file,name)
            else:
                Error404(self)
                return


        fmtime=datetime.fromtimestamp(fstat[stat.ST_MTIME])
        #logging.info("QUAMIME %s",os.path.splitext(server_path)[1])
        if self.request.if_modified_since and self.request.if_modified_since.replace(tzinfo=None) >= fmtime:
            self.response.headers['Date'] = format_date(datetime.utcnow())
            self.response.headers['Last-Modified'] = format_date(fmtime)
            cache_expires(self.response, max_age)
            self.response.set_status(304)
            self.response.clear()
        elif server_path.startswith(theme_path):
            ext = os.path.splitext(server_path)[1]
            if types_map.has_key(ext):
                mime_type = types_map[ext]
            else:
                mime_type = 'application/octet-stream'
            try:
                #logging.info("MIMETYPE %s %s",mime_type,ext)
                self.response.headers['Content-Type'] = mime_type
                self.response.headers['Last-Modified'] = format_date(fmtime)
                cache_expires(self.response, max_age)
                #logging.info("MIMETYPE in resp %s %s",str(self.response.headers),self.response.headers['Content-Type'])
                self.response.out.write(open(server_path, 'rb').read())
            except Exception, e:
                Error404(self)
コード例 #5
0
ファイル: plog.py プロジェクト: jfojfo/foblog
    def get(self):
        filename = self.request.path[len(settings.app_root) + len('/upload/'):]
        split = filename.rfind('.')
        if split == -1:
            name, ext = filename, ''
        else:
            name = filename[:split]
            ext = filename[split + 1:]

        file = UploadFile.get(db.Key(name))
        if not file:
            self.error_404()
        elif file.ext != ext:
            self.error_404()
        else:
            ext = '.' + ext
            mimetype = 'application/octet-stream'
            if types_map.has_key(ext):
                mimetype = types_map[ext]
            self.response.headers['Content-Type'] = mimetype
            self.response.headers['Content-Disposition'] = 'inline; filename="' + file.orig_name.encode('utf-8') + '"'
            self.write(file.data)