Ejemplo n.º 1
0
 def image(self, *args, **kwargs):
     '''Get Image From Comic'''
     Utils.allow_methods(kwargs=kwargs)
     if len(args) < 2:
         raise cherrypy.HTTPError(400, 'No Comic Path Requested')
     path = '/'.join(args[:-1])
     index = -1
     try:
         index = int(args[-1])
     except ValueError:
         raise cherrypy.HTTPError(400, 'No Comic Page Requested')
     index -= 1
     base = self.prefix + path
     if not is_zipfile(base):
         raise cherrypy.HTTPError(404, 'Requested Comic Not Exists')
     comic = ZipFile(base)
     pages = Utils.sort_list([info for info in comic.infolist()
         if Utils.is_image(info.filename)], lambda x: x.filename.lower())
     if index < 0  or index >= len(pages):
         raise cherrypy.HTTPError(404, 'Requested Comic Page Not Exists')
     page = pages[index]
     modified = Utils.date_to_httpdate(mktime(page.date_time + (0, 0, 0)))
     etag = Utils.make_etag(path, index, modified)
     Utils.validate_conditional(etag, modified)
     types = mimetypes.guess_type(pages[index].filename)
     cherrypy.response.headers['Content-Type'] = types[0]
     return comic.read(pages[index])
Ejemplo n.º 2
0
 def info(self, *args, **kwargs):
     '''Get Info About a Comic'''
     Utils.allow_methods(kwargs=kwargs)
     if len(args) < 1:
         raise cherrypy.HTTPError(400, 'No Comic Path Requested')
     path = '/'.join(args)
     filename = self.prefix + path
     if not is_zipfile(filename):
         raise cherrypy.HTTPError(404, 'Requested Comic Not Exists')
     comic = ZipFile(filename)
     name = Utils.filename_to_name(filename)
     comment = str(comic.comment, 'utf8')
     pages = Utils.sort_list([info for info in comic.infolist()
         if Utils.is_image(info.filename)], lambda x: x.filename.lower())
     modified = Utils.date_to_httpdate(os.path.getmtime(filename))
     etag = Utils.make_etag(path, modified)
     Utils.validate_conditional(etag, modified)
     return {
         'name': name,
         'comment': comment,
         'pagecount': len(pages),
         'pages': [
             {
                 'filename': page.filename,
                 'name': Utils.filename_to_name(page.filename),
                 'comment': str(page.comment, 'utf8'),
                 'size': page.file_size
             }
             for page in pages
         ]
     }
Ejemplo n.º 3
0
 def image(self, * args, **kwargs):
     '''Get Image From The Gallery'''
     Utils.allow_methods(kwargs=kwargs)
     path = Utils.urlpatherize(args)
     filename = self.prefix + path
     if not os.path.isfile(filename):
         raise cherrypy.HTTPError(404, 'File Not Found')
     try:
         types = mimetypes.guess_type(filename)
         cherrypy.response.headers['Content-Type'] = types[0]
         modified = Utils.date_to_httpdate(os.path.getmtime(filename))
         etag = Utils.make_etag(filename, modified)
         Utils.validate_conditional(etag, modified)
         with open(filename, 'rb') as file:
             return file.read()
     except IOError:
         raise cherrypy.HTTPError(403, 'Permission denied')