Skip to content

Commit

Permalink
Merge pull request #40 from glenrobson/version3
Browse files Browse the repository at this point in the history
Adding extra 3.0 features
  • Loading branch information
zimeon committed Aug 22, 2019
2 parents bc82930 + b05f792 commit 1f64c24
Show file tree
Hide file tree
Showing 7 changed files with 28 additions and 15 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
.coverage
htmlcov
*.pyc
*.swp
*~
.DS_store
.cache
Expand Down
1 change: 0 additions & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
language: python
python:
- "2.7"
- "3.4"
- "3.5"
- "3.6"
install:
Expand Down
5 changes: 4 additions & 1 deletion iiif/flask_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -316,6 +316,7 @@ def image_information_response(self):
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})

Expand Down Expand Up @@ -369,8 +370,10 @@ def image_request_response(self, path):
self.iiif.format = formats[accept]
(outfile, mime_type) = self.manipulator.derive(file, self.iiif)
# FIXME - find efficient way to serve file with headers
# could this be the answer: https://stackoverflow.com/questions/31554680/how-to-send-header-in-flask-send-file
# currently no headers are sent with the file
self.add_compliance_header()
return send_file(outfile, mimetype=mime_type)
return self.make_response(send_file(outfile, mimetype=mime_type))

def error_response(self, e):
"""Make response for an IIIFError e.
Expand Down
10 changes: 6 additions & 4 deletions iiif/manipulator.py
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,8 @@ def compliance_uri(self):
elif (self.api_version == '2.0' or
self.api_version == '2.1'):
uri_pattern = r'http://iiif.io/api/image/2/level%d.json'
elif (self.api_version == '3.0'):
uri_pattern = r'http://iiif.io/api/image/3/level%d.json'
else:
return
if (self.compliance_level is None):
Expand Down Expand Up @@ -248,7 +250,7 @@ def size_to_apply(self):
Assumes current image width and height are available in self.width and
self.height, and self.request is IIIFRequest object.
Formats are: w, ,h w,h pct:p !w,h full max
Formats are: w, ,h w,h pct:p !w,h full max ^w, ^,h ^w,h
Returns (None,None) if no scaling is required.
Expand Down Expand Up @@ -305,9 +307,9 @@ def size_to_apply(self):
code=400, parameter='size',
text="Size parameter would result in zero size result image (%d,%d)." % (w, h))
# Below would be test for scaling up image size, this is allowed by spec
# if ( w>self.width or h>self.height ):
# raise IIIFError(code=400,parameter='size',
# text="Size requests scaling up image to larger than orginal.")
if ((w > self.width or h > self.height) and self.api_version >= '3.0' and not self.request.size_caret):
raise IIIFError(code=400, parameter='size',
text="Size requests scaling up image to larger than orginal.")
if (w == self.width and h == self.height):
return(None, None)
return(w, h)
Expand Down
12 changes: 11 additions & 1 deletion iiif/request.py
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,7 @@ def clear(self):
self.size_max = False # new in 2.1
self.size_pct = None
self.size_bang = None
self.size_caret = None
self.size_wh = None # (w,h)
self.rotation_mirror = False
self.rotation_deg = 0.0
Expand Down Expand Up @@ -395,6 +396,9 @@ def parse_size(self, size=None):
/w,h/ -> self.size_wh = (w,h)
/pct:p/ -> self.size_pct = p
/!w,h/ -> self.size_wh = (w,h), self.size_bang = True
/^w,h/ -> self.size_wh = (w,h), self.size_caret = True
/^w,/ -> self.size_wh = (w,None), self.size_caret = True
/^,h/ -> self.size_wh = (None,h), self.size_caret = True
Expected use:
(w,h) = iiif.size_to_apply(region_w,region_h)
Expand All @@ -408,9 +412,15 @@ def parse_size(self, size=None):
self.size = size
self.size_pct = None
self.size_bang = False
self.size_caret = False
self.size_full = False
self.size_wh = (None, None)
if (self.size is None or self.size == 'full'):
if self.size.startswith('^'):
# as caret can be used with any combination of features
# set caret to true and then remove it to catch further processing
self.size_caret = True
self.size = self.size[1:]
if (self.size is None or self.size == 'full' and self.api_version < '3.0'):
self.size_full = True
return
elif (self.size == 'max' and self.api_version >= '2.1'):
Expand Down
6 changes: 6 additions & 0 deletions run_validate.sh
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,12 @@ if $show_test_name; then
fi
iiif-validate.py -s localhost:8000 -p 2.0_pil -i 67352ccc-d1b0-11e1-89ae-279075081939 --version=2.0 --level 2 $verbosity
((errors+=$?))
if $show_test_name; then
echo "Testing PIL manipulator, API version 3.0 "
fi
iiif-validate.py -s localhost:8000 -p 3.0_pil -i 67352ccc-d1b0-11e1-89ae-279075081939 --version=3.0 --level 2 $verbosity
((errors+=$?))

if $test_netpbm; then
if $show_test_name; then
echo "Testing netpbm manipulator, API version 1.1"
Expand Down
8 changes: 0 additions & 8 deletions tests/test_request_3_0.py
Original file line number Diff line number Diff line change
Expand Up @@ -168,14 +168,6 @@ def test03_parse_size(self):
self.assertFalse(r.size_pct)
self.assertTrue(r.size_bang)
self.assertEqual(r.size_wh, (5, 6))
# 'full'
r = IIIFRequest(api_version='3.0')
r.parse_size('full')
self.assertTrue(r.size_full)
self.assertFalse(r.size_max)
self.assertFalse(r.size_pct)
self.assertFalse(r.size_bang)
self.assertEqual(r.size_wh, (None, None))
# 'max' is new in 3.0
r = IIIFRequest(api_version='3.0')
r.parse_size('max')
Expand Down

0 comments on commit 1f64c24

Please sign in to comment.