Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
T
Tasks
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Container Registry
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
This is an archived project. Repository and other project resources are read-only.
Show more breadcrumbs
Arkindex
Tasks
Commits
0d4a44ca
Commit
0d4a44ca
authored
1 year ago
by
ml bonhomme
Committed by
Erwan Rouchet
1 year ago
Browse files
Options
Downloads
Patches
Plain Diff
Check IIIF version @context property
parent
b71d5b5a
No related branches found
No related tags found
1 merge request
!363
Check IIIF version @context property
Pipeline
#138235
passed
1 year ago
Stage: release
Changes
2
Pipelines
6
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
arkindex_tasks/import_iiif/parser.py
+19
-0
19 additions, 0 deletions
arkindex_tasks/import_iiif/parser.py
tests/import_iiif/test_iiif_parser.py
+22
-1
22 additions, 1 deletion
tests/import_iiif/test_iiif_parser.py
with
41 additions
and
1 deletion
arkindex_tasks/import_iiif/parser.py
+
19
−
0
View file @
0d4a44ca
...
...
@@ -129,6 +129,24 @@ class IIIFParser(object):
if
self
.
stream
and
not
self
.
stream
.
closed
:
self
.
stream
.
close
()
def
check_version
(
self
):
"""
Raise an error if the manifest is IIIF v3
"""
context
=
next
(
(
value
for
prefix
,
event
,
value
in
ijson
.
parse
(
self
.
stream
)
if
prefix
==
"
@context
"
),
None
,
)
if
context
and
"
http://iiif.io/api/presentation/3/context.json
"
in
context
:
raise
ValueError
(
"
The import functionality does not support IIIF Presentation API version 3
"
)
self
.
stream
.
seek
(
0
)
def
get_type
(
self
):
"""
Get a parser class for the given IIIF object.
...
...
@@ -155,6 +173,7 @@ class IIIFParser(object):
@staticmethod
def
load
(
stream
,
*
args
,
**
kwargs
):
p
=
IIIFParser
(
stream
)
p
.
check_version
()
cls
=
p
.
get_type
()
return
cls
(
stream
,
*
args
,
**
kwargs
)
...
...
This diff is collapsed.
Click to expand it.
tests/import_iiif/test_iiif_parser.py
+
22
−
1
View file @
0d4a44ca
...
...
@@ -24,6 +24,22 @@ class TestIIIFParser(TestCase):
IIIFParser
(
stream
).
close
()
self
.
assertTrue
(
stream
.
closed
)
def
test_v3
(
self
):
stream
=
BytesIO
(
json
.
dumps
(
{
"
@context
"
:
"
http://iiif.io/api/presentation/3/context.json
"
,
"
id
"
:
"
something
"
,
"
type
"
:
"
sc:Manifest
"
,
}
).
encode
(
"
utf-8
"
)
)
with
self
.
assertRaises
(
ValueError
,
msg
=
"
The import functionality does not support IIIF Presentation API version 3
"
,
):
IIIFParser
(
stream
).
check_version
()
def
test_get_type
(
self
):
stream
=
BytesIO
(
json
.
dumps
({
"
@id
"
:
"
something
"
,
"
@type
"
:
"
sc:Manifest
"
}).
encode
(
"
utf-8
"
)
...
...
@@ -43,7 +59,12 @@ class TestIIIFParser(TestCase):
def
test_load
(
self
):
stream
=
BytesIO
(
json
.
dumps
({
"
@id
"
:
"
something
"
,
"
@type
"
:
"
sc:Manifest
"
}).
encode
(
"
utf-8
"
)
json
.
dumps
(
{
"
@id
"
:
"
something
"
,
"
@type
"
:
"
sc:Manifest
"
,
}
).
encode
(
"
utf-8
"
)
)
self
.
assertIsInstance
(
IIIFParser
.
load
(
stream
),
ManifestParser
)
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment