Exemplo n.º 1
0
    def get(self, theme_name, target_name):
        logging.info("theme_file - GetFile - %s/%s" % (theme_name, target_name))
        request_path = self.request.path[8:]
        server_path = os.path.normpath(os.path.join(cwd, 'themes', request_path))

        try:
            fstat = os.stat(server_path)
        except:
            # check themes exists as a zip file?
            theme_file = os.path.normpath(os.path.join(cwd, 'themes', theme_name))
            if os.path.exists(theme_file + ".zip"):
                # is file exist? find target in zip file
                fstat = os.stat(theme_file + ".zip")
                zipdo = ZipHandler()
                zipdo.initialize(self.request, self.response)
                return zipdo.get(theme_file, target_name)
            else:
                error404(self)
                return

        # request normal file in themes package
        fmtime = datetime.fromtimestamp(fstat[stat.ST_MTIME])
        if self.request.if_modified_since and self.request.if_modified_since.replace(tzinfo=None) >= fmtime:
            # use cached content
            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):
            # find minetye for this content
            ext = os.path.splitext(server_path)[1]
            if ext in types_map:
                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)
Exemplo n.º 2
0
 def get(self):
     error404(self)
Exemplo n.º 3
0
            # find minetye for this content
            ext = os.path.splitext(server_path)[1]
            if ext in types_map:
                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)
        else:
            error404(self)


# does not read file contents for templates folders
class NotFound(BaseRequestHandler):
    def get(self):
        error404(self)


def format_date(dt):
    return dt.strftime('%a, %d %b %Y %H:%M:%S GMT')


def cache_expires(response, seconds=0, **kw):
    """
    Set expiration on this request.  This sets the response to