本文整理汇总了Python中iiif.info.IIIFInfo类的典型用法代码示例。如果您正苦于以下问题:Python IIIFInfo类的具体用法?Python IIIFInfo怎么用?Python IIIFInfo使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了IIIFInfo类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test01_minmal
def test01_minmal(self):
# Just do the trivial JSON test
ir = IIIFInfo(identifier="i1",api_version='1.0')
self.assertEqual( ir.as_json(validate=False), '{\n "identifier": "i1", \n "profile": "http://library.stanford.edu/iiif/image-api/compliance.html#level1"\n}' )
ir.width=100
ir.height=200
self.assertEqual( ir.as_json(), '{\n "height": 200, \n "identifier": "i1", \n "profile": "http://library.stanford.edu/iiif/image-api/compliance.html#level1", \n "width": 100\n}' )
示例2: test01_minmal
def test01_minmal(self):
# Just do the trivial JSON test
ir = IIIFInfo(server_and_prefix="http://example.com",identifier="i1",api_version='1.1')
self.assertEqual( ir.as_json(validate=False), '{\n "@context": "http://library.stanford.edu/iiif/image-api/1.1/context.json", \n "@id": "http://example.com/i1", \n "profile": "http://library.stanford.edu/iiif/image-api/1.1/compliance.html#level1"\n}' )
ir.width=100
ir.height=200
self.assertEqual( ir.as_json(), '{\n "@context": "http://library.stanford.edu/iiif/image-api/1.1/context.json", \n "@id": "http://example.com/i1", \n "height": 200, \n "profile": "http://library.stanford.edu/iiif/image-api/1.1/compliance.html#level1", \n "width": 100\n}' )
示例3: do_GET_body
def do_GET_body(self):
"""Create body of GET."""
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))
try:
# self.path has leading / then identifier/params...
self.path = self.path.lstrip("/")
sys.stderr.write("path = %s" % (self.path))
iiif.parse_url(self.path)
except Exception as e:
# Something completely unexpected => 500
raise IIIFError(
code=500, text="Internal Server Error: unexpected exception parsing request (" + str(e) + ")"
)
# Now we have a full iiif request
if re.match("[\w\.\-]+$", iiif.identifier):
file = os.path.join(TESTIMAGE_DIR, iiif.identifier)
if not os.path.isfile(file):
images_available = ""
for image_file in os.listdir(TESTIMAGE_DIR):
if os.path.isfile(os.path.join(TESTIMAGE_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",
)
# Now know image is OK
manipulator = IIIFRequestHandler.manipulator_class()
# Stash manipulator object so we can cleanup after reading file
self.manipulator = manipulator
self.compliance_uri = manipulator.compliance_uri
if iiif.info:
# get size
manipulator.srcfile = file
manipulator.do_first()
# most of info.json comes from config, a few things
# specific to image
i = IIIFInfo()
i.identifier = self.iiif.identifier
i.width = manipulator.width
i.height = manipulator.height
import io
return (io.StringIO(i.as_json()), "application/json")
else:
(outfile, mime_type) = manipulator.derive(file, iiif)
return (open(outfile, "r"), mime_type)
示例4: test10_read_example_from_spec
def test10_read_example_from_spec(self):
"""Test reading of example from spec."""
i = IIIFInfo()
fh = open("tests/testdata/info_json_2_0/info_from_spec.json")
i.read(fh)
self.assertEqual(i.context, "http://iiif.io/api/image/2/context.json")
self.assertEqual(i.id, "http://www.example.org/image-service/abcd1234/1E34750D-38DB-4825-A38A-B60A345E591C")
self.assertEqual(i.protocol, "http://iiif.io/api/image")
self.assertEqual(i.width, 6000)
self.assertEqual(i.height, 4000)
self.assertEqual(
i.sizes, [{"width": 150, "height": 100}, {"width": 600, "height": 400}, {"width": 3000, "height": 2000}]
)
self.assertEqual(
i.profile,
[
"http://iiif.io/api/image/2/level2.json",
{
"formats": ["gif", "pdf"],
"qualities": ["color", "gray"],
"supports": [
"canonicalLinkHeader",
"rotationArbitrary",
"profileLinkHeader",
"http://example.com/feature/",
],
},
],
)
# extracted information
self.assertEqual(i.compliance, "http://iiif.io/api/image/2/level2.json")
示例5: test06_validate
def test06_validate(self):
i = IIIFInfo(api_version='1.1')
self.assertRaises( Exception, i.validate, () )
i = IIIFInfo(identifier='a')
self.assertRaises( Exception, i.validate, () )
i = IIIFInfo(identifier='a',width=1,height=2)
self.assertTrue( i.validate() )
示例6: test20_write_example_in_spec
def test20_write_example_in_spec(self):
i = IIIFInfo(
api_version='2.1',
id="http://www.example.org/image-service/abcd1234/1E34750D-38DB-4825-A38A-B60A345E591C",
#"protocol" : "http://iiif.io/api/image",
width=6000,
height=4000,
sizes=[
{"width" : 150, "height" : 100},
{"width" : 600, "height" : 400},
{"width" : 3000, "height": 2000}
],
tiles=[
{"width" : 512, "scaleFactors" : [1,2,4,8,16]}
],
profile="http://iiif.io/api/image/2/level2.json",
formats = [ "gif", "pdf" ],
qualities = [ "color", "gray" ],
supports = [ "canonicalLinkHeader", "rotationArbitrary", "profileLinkHeader", "http://example.com/feature/" ],
service={
"@context": "http://iiif.io/api/annex/service/physdim/1/context.json",
"profile": "http://iiif.io/api/annex/service/physdim",
"physicalScale": 0.0025,
"physicalUnits": "in"
}
)
reparsed_json = json.loads( i.as_json() )
example_json = json.load( open('test_info/2.1/info_from_spec.json') )
self.maxDiff = 4000
self.assertEqual( reparsed_json, example_json )
示例7: test03_array_vals
def test03_array_vals(self):
"""Test array values."""
i = IIIFInfo(api_version='1.1')
i.scale_factors = [1, 2, 3]
self.assertEqual(i.scale_factors, [1, 2, 3])
i._setattr('scale_factors', [4, 5, 6])
self.assertEqual(i.scale_factors, [4, 5, 6])
示例8: test01_minmal
def test01_minmal(self):
# Just do the trivial JSON test
# ?? should this empty case raise and error instead?
ir = IIIFInfo(identifier="http://example.com/i1", api_version='2.1')
self.assertEqual( ir.as_json(validate=False), '{\n "@context": "http://iiif.io/api/image/2/context.json", \n "@id": "http://example.com/i1", \n "profile": [\n "http://iiif.io/api/image/2/level1.json"\n ], \n "protocol": "http://iiif.io/api/image"\n}' )
ir.width=100
ir.height=200
self.assertEqual( ir.as_json(), '{\n "@context": "http://iiif.io/api/image/2/context.json", \n "@id": "http://example.com/i1", \n "height": 200, \n "profile": [\n "http://iiif.io/api/image/2/level1.json"\n ], \n "protocol": "http://iiif.io/api/image", \n "width": 100\n}' )
示例9: test01_empty_auth_defined
def test01_empty_auth_defined(self):
"""Test empty auth."""
info = IIIFInfo(identifier="http://example.com/i1", api_version='2.1')
auth = IIIFAuth()
auth.add_services(info)
self.assertJSONEqual(info.as_json(
validate=False), '{\n "@context": "http://iiif.io/api/image/2/context.json", \n "@id": "http://example.com/i1", \n "profile": [\n "http://iiif.io/api/image/2/level1.json"\n ], \n "protocol": "http://iiif.io/api/image"\n}')
self.assertEqual(info.service, None)
示例10: test06_validate
def test06_validate(self):
"""Test validate method."""
i = IIIFInfo()
self.assertRaises(Exception, i.validate, ())
i = IIIFInfo(identifier="a")
self.assertRaises(Exception, i.validate, ())
i = IIIFInfo(identifier="a", width=1, height=2)
self.assertTrue(i.validate())
示例11: test20_scale_factors
def test20_scale_factors(self):
"""Test getter/setter for scale_factors property."""
i = IIIFInfo(api_version="1.1")
self.assertEqual(i.scale_factors, None)
i.scale_factors = [1, 2]
self.assertEqual(i.scale_factors, [1, 2])
i.scale_factors = [7, 8]
self.assertEqual(i.scale_factors, [7, 8])
示例12: test02_scale_factor
def test02_scale_factor(self):
"""Test scale factor."""
ir = IIIFInfo(width=1, height=2, scale_factors=[
1, 2], api_version='1.1')
# self.assertRegexpMatches( ir.as_json(validate=False),
# r'"scale_factors": \[\s*1' ) #,\s*2\s*]' ) #no assertRegexpMatches in
# 2.6
json = ir.as_json(validate=False)
self.assertTrue(re.search(r'"scale_factors": \[\s*1', json))
示例13: test05_level_and_profile
def test05_level_and_profile(self):
i = IIIFInfo(api_version='1.1')
i.level = 0
self.assertEqual( i.level, 0 )
self.assertEqual( i.profile, "http://library.stanford.edu/iiif/image-api/1.1/compliance.html#level0" )
i.level = 2
self.assertEqual( i.level, 2 )
self.assertEqual( i.profile, "http://library.stanford.edu/iiif/image-api/1.1/compliance.html#level2" )
i.profile = "http://library.stanford.edu/iiif/image-api/1.1/compliance.html#level1"
self.assertEqual( i.level, 1 )
示例14: test11_read_example_with_explicit_version
def test11_read_example_with_explicit_version(self):
i = IIIFInfo() #default not 1.1
fh = open('test_info/1.1/info_from_spec.json')
i.read(fh) #will get 1.1 from @context
self.assertEqual( i.api_version, '1.1' )
fh = open('test_info/1.1/info_from_spec.json')
self.assertRaises( Exception, i.read, fh, '0.1' ) # 0.1 bad
fh = open('test_info/1.1/info_from_spec.json')
i.read(fh, '1.1')
self.assertEqual( i.api_version, '1.1' )
示例15: image_information_response
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)