def image_information_response(self): """Parse image information request and create response.""" dr = degraded_request(self.identifier) if (dr): self.logger.info("image_information: degraded %s -> %s" % (self.identifier,dr)) self.degraded = self.identifier self.identifier = dr else: self.logger.info("image_information: %s" % (self.identifier)) # get size self.manipulator.srcfile=self.file self.manipulator.do_first() # most of info.json comes from config, a few things specific to image info = { 'tile_height': self.config.tile_height, 'tile_width': self.config.tile_width, 'scale_factors' : self.config.scale_factors } i = IIIFInfo(conf=info,api_version=self.api_version) i.server_and_prefix = self.server_and_prefix i.identifier = self.iiif.identifier i.width = self.manipulator.width i.height = self.manipulator.height if (self.api_version>='2.0'): i.qualities = [ "default", "color", "gray" ] #FIXME - should come from manipulator else: i.qualities = [ "native", "color", "gray" ] #FIXME - should come from manipulator i.formats = [ "jpg", "png" ] #FIXME - should come from manipulator if (self.auth): self.auth.add_services(i) return self.make_response(i.as_json(),content_type=self.json_mime_type)
def image_information_response(self): """Parse image information request and create response.""" dr = degraded_request(self.identifier) if (dr): self.logger.info("image_information: degraded %s -> %s" % (self.identifier, dr)) self.degraded = self.identifier self.identifier = dr else: self.logger.info("image_information: %s" % (self.identifier)) # get size self.manipulator.srcfile = self.file self.manipulator.do_first() # most of info.json comes from config, a few things specific to image info = { 'tile_height': self.config.tile_height, 'tile_width': self.config.tile_width, 'scale_factors': self.config.scale_factors } # calculate scale factors if not hard-coded if ('auto' in self.config.scale_factors): info['scale_factors'] = self.manipulator.scale_factors( self.config.tile_width, self.config.tile_height) i = IIIFInfo(conf=info, api_version=self.api_version) i.server_and_prefix = self.server_and_prefix i.identifier = self.iiif.identifier i.width = self.manipulator.width i.height = self.manipulator.height if (self.api_version >= '2.0'): # FIXME - should come from manipulator i.qualities = ["default", "color", "gray"] else: # FIXME - should come from manipulator i.qualities = ["native", "color", "gray"] i.formats = ["jpg", "png"] # FIXME - should come from manipulator if (self.auth): self.auth.add_services(i) return self.make_response( i.as_json(), headers={"Content-Type": self.json_mime_type})
def image_information_response(self): """Parse image information request and create response.""" dr = degraded_request(self.identifier) if dr: self.logger.info("image_information: degraded %s -> %s" % (self.identifier, dr)) self.degraded = self.identifier self.identifier = dr else: self.logger.info("image_information: %s" % (self.identifier)) # get size self.manipulator.srcfile = self.file self.manipulator.do_first() # most of info.json comes from config, a few things specific to image info = { "tile_height": self.config.tile_height, "tile_width": self.config.tile_width, "scale_factors": self.config.scale_factors, } # calculate scale factors if not hard-coded if "auto" in self.config.scale_factors: info["scale_factors"] = self.manipulator.scale_factors(self.config.tile_width, self.config.tile_height) i = IIIFInfo(conf=info, api_version=self.api_version) i.server_and_prefix = self.server_and_prefix i.identifier = self.iiif.identifier i.width = self.manipulator.width i.height = self.manipulator.height if self.api_version >= "2.0": # FIXME - should come from manipulator i.qualities = ["default", "color", "gray"] else: # FIXME - should come from manipulator i.qualities = ["native", "color", "gray"] i.formats = ["jpg", "png"] # FIXME - should come from manipulator if self.auth: self.auth.add_services(i) return self.make_response(i.as_json(), headers={"Content-Type": self.json_mime_type})
def do_GET_body(self): iiif=self.iiif if (len(self.path)>1024): raise IIIFError(code=414, text="URI Too Long: Max 1024 chars, got %d\n" % len(self.path)) #print "GET " + self.path try: iiif.parse_url(self.path) except IIIFRequestBaseURI as e: info_uri = self.server_and_prefix + '/' + urllib.quote(self.iiif.identifier) + '/info.json' raise IIIFError(code=303, headers={'Location': info_uri}) except IIIFError as e: # Pass through raise e except Exception as e: # Something completely unexpected => 500 raise IIIFError(code=500, text="Internal Server Error: unexpected exception parsing request (" + str(e) + ")") # URL path parsed OK, now determine how to handle request if (re.match('[\w\.\-]+$',iiif.identifier)): file = os.path.join(IIIFRequestHandler.IMAGE_DIR,iiif.identifier) if (not os.path.isfile(file)): images_available="" for image_file in os.listdir(IIIFRequestHandler.IMAGE_DIR): if (os.path.isfile(os.path.join(IIIFRequestHandler.IMAGE_DIR,image_file))): images_available += " "+image_file+"\n" raise IIIFError(code=404,parameter="identifier", text="Image resource '"+iiif.identifier+"' not found. Local image files available:\n" + images_available) else: raise IIIFError(code=404,parameter="identifier", text="Image resource '"+iiif.identifier+"' not found. Only local test images and http: URIs for images are supported.\n") # self.compliance_level=self.manipulator.complianceLevel # Do we have auth? if (self.auth_type == 'basic'): auth_map = parse_authorization_header(self.headers.get('Authorization','')) if (auth_map and auth_map['type']=='basic' and auth_map['username']+':'+auth_map['password']==IIIFRequestHandler.USER_PASS): # authz, continue pass else: # failed, send 401 with null image info, no service link for auth as # basic auth is all done via the WWW-Authenticate header i = IIIFInfo(api_version=self.api_version) i.identifier = 'null' i.width = 0 i.height = 0 return self.send_json_response(json=i.as_json(),status=401) if (self.iiif.info): # get size self.manipulator.srcfile=file self.manipulator.do_first() # most of info.json comes from config, a few things specific to image i = IIIFInfo(conf=IIIFRequestHandler.INFO,api_version=self.api_version) i.server_and_prefix = self.server_and_prefix i.identifier = self.iiif.identifier i.width = self.manipulator.width i.height = self.manipulator.height i.qualities = [ "native", "color" ] #FIXME - should come from manipulator i.formats = [ "jpg", "png" ] #FIXME - should come from manipulator return self.send_json_response(i.as_json(),200) else: if (self.api_version<'2.0' and self.iiif.format is None and 'Accept' in self.headers): # In 1.0 and 1.1 conneg was specified as an alternative to format, see: # http://iiif.io/api/image/1.0/#format # http://iiif.io/api/image/1.1/#parameters-format formats = { 'image/jpeg': 'jpg', 'image/tiff': 'tif', 'image/png': 'png', 'image/gif': 'gif', 'image/jp2': 'jps', 'application/pdf': 'pdf' } accept = do_conneg( self.headers['Accept'], formats.keys() ) # Ignore Accept header if not recognized, should this be an error instead? if (accept in formats): self.iiif.format = formats[accept] (outfile,mime_type)=self.manipulator.derive(file,iiif) return self.send_good_response(open(outfile,'r'),mime_type)