本文整理汇总了Python中iiif.request.IIIFRequest.parse_url方法的典型用法代码示例。如果您正苦于以下问题:Python IIIFRequest.parse_url方法的具体用法?Python IIIFRequest.parse_url怎么用?Python IIIFRequest.parse_url使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类iiif.request.IIIFRequest
的用法示例。
在下文中一共展示了IIIFRequest.parse_url方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test02_derive
# 需要导入模块: from iiif.request import IIIFRequest [as 别名]
# 或者: from iiif.request.IIIFRequest import parse_url [as 别名]
def test02_derive(self):
m = IIIFManipulator()
r = IIIFRequest()
r.parse_url('id1/full/full/0/default')
tmp = tempfile.mkdtemp()
outfile = os.path.join(tmp,'testout.png')
try:
m.derive(srcfile='testimages/test1.png',
request=r, outfile=outfile);
self.assertTrue( os.path.isfile(outfile) )
self.assertEqual( os.path.getsize(outfile), 65810 )
finally:
shutil.rmtree(tmp)
# and where path to outfile must be created
outfile = os.path.join(tmp,'a','b','testout.png')
try:
m.derive(srcfile='testimages/test1.png',
request=r, outfile=outfile);
self.assertTrue( os.path.isfile(outfile) )
self.assertEqual( os.path.getsize(outfile), 65810 )
finally:
shutil.rmtree(tmp)
示例2: test03_is_scaled_full_image
# 需要导入模块: from iiif.request import IIIFRequest [as 别名]
# 或者: from iiif.request.IIIFRequest import parse_url [as 别名]
def test03_is_scaled_full_image(self):
"""Test check for whether request is scaled full image."""
r = IIIFRequest(identifier='dummy',
api_version='2.1')
r.parse_url('full/full/0/default.jpg')
self.assertFalse(r.is_scaled_full_image())
r.parse_url('full/!10,10/0/default.jpg')
self.assertFalse(r.is_scaled_full_image())
r.parse_url('10,10,90,90/10,10/0/default.jpg')
self.assertFalse(r.is_scaled_full_image())
r.parse_url('full/10,10/1/default.jpg')
self.assertFalse(r.is_scaled_full_image())
r.parse_url('full/10,10/0/default.png')
self.assertFalse(r.is_scaled_full_image())
r.parse_url('full/10,10/0/color.jpg')
self.assertFalse(r.is_scaled_full_image())
#
r = IIIFRequest(identifier='dummy',
api_version='2.1')
r.parse_url('full/10,10/0/default.jpg')
self.assertTrue(r.is_scaled_full_image())
示例3: IIIFHandler
# 需要导入模块: from iiif.request import IIIFRequest [as 别名]
# 或者: from iiif.request.IIIFRequest import parse_url [as 别名]
#.........这里部分代码省略.........
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_request_response(self, path):
"""Parse image request and create response."""
# Parse the request in path
if (len(path) > 1024):
raise IIIFError(code=414,
text="URI Too Long: Max 1024 chars, got %d\n" % len(path))
try:
self.iiif.identifier = self.identifier
self.iiif.parse_url(path)
except IIIFRequestPathError as e:
# Reraise as IIIFError with code=404 because we can't tell
# whether there was an encoded slash in the identifier or
# whether there was a bad number of path segments.
raise IIIFError(code=404, text=e.text)
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) + ")")
dr = degraded_request(self.identifier)
if (dr):
self.logger.info("image_request: degraded %s -> %s" %
(self.identifier, dr))
self.degraded = self.identifier
self.identifier = dr
self.iiif.quality = 'gray'
else:
# Parsed request OK, attempt to fulfill
self.logger.info("image_request: %s" % (self.identifier))
file = self.file
self.manipulator.srcfile = file
self.manipulator.do_first()
if (self.api_version < '2.0' and
self.iiif.format is None and
'Accept' in request.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(request.headers['Accept'], list(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, self.iiif)
# FIXME - find efficient way to serve file with headers
self.add_compliance_header()
return send_file(outfile, mimetype=mime_type)
def error_response(self, e):
"""Make response for an IIIFError e.
Also add compliance header.
"""
self.add_compliance_header()
return self.make_response(*e.image_server_response(self.api_version))