Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
S
swh-indexer
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Model registry
Operate
Environments
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Platform
Development
swh-indexer
Commits
957db0f9
Commit
957db0f9
authored
6 months ago
by
vlorentz
Browse files
Options
Downloads
Patches
Plain Diff
Fix support of sword-v2-atom-codemeta-v2-in-json documents with missing @xmlns
parent
6718f356
No related branches found
Branches containing commit
No related tags found
Tags containing commit
1 merge request
!517
Fix support of sword-v2-atom-codemeta-v2-in-json documents with missing @xmlns
Pipeline
#11085
failed
5 months ago
Stage: external
Changes
2
Pipelines
3
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
swh/indexer/metadata_dictionary/codemeta.py
+28
-3
28 additions, 3 deletions
swh/indexer/metadata_dictionary/codemeta.py
swh/indexer/tests/metadata_dictionary/test_codemeta.py
+14
-0
14 additions, 0 deletions
swh/indexer/tests/metadata_dictionary/test_codemeta.py
with
42 additions
and
3 deletions
swh/indexer/metadata_dictionary/codemeta.py
+
28
−
3
View file @
957db0f9
...
...
@@ -170,6 +170,19 @@ class SwordCodemetaMapping(BaseExtrinsicMapping):
return
compact
(
metadata
,
forgefed
=
False
)
def
iter_keys
(
d
):
"""
Recursively iterates on dictionary keys
"""
if
isinstance
(
d
,
dict
):
yield
from
d
for
value
in
d
:
yield
from
iter_keys
(
value
)
elif
isinstance
(
d
,
list
):
for
value
in
d
:
yield
from
iter_keys
(
value
)
else
:
pass
class
JsonSwordCodemetaMapping
(
SwordCodemetaMapping
):
"""
Variant of :class:`SwordCodemetaMapping` that reads the legacy
...
...
@@ -193,9 +206,21 @@ class JsonSwordCodemetaMapping(SwordCodemetaMapping):
logger
.
error
(
"
Failed to parse JSON document: %s
"
,
content
)
return
None
else
:
if
json_doc
.
get
(
"
@xmlns
"
)
!=
ATOM_URI
:
# Technically, non-default XMLNS were allowed, but it does not seem like
# anyone used them, so they do not need to be implemented here.
if
"
@xmlns
"
not
in
json_doc
:
# Technically invalid, but old versions of the deposit dropped
# XMLNS information
json_doc
[
"
@xmlns
"
]
=
ATOM_URI
if
"
@xmlns:codemeta
"
not
in
json_doc
and
any
(
key
.
startswith
(
"
codemeta:
"
)
for
key
in
iter_keys
(
json_doc
)
):
# ditto
json_doc
[
"
@xmlns:codemeta
"
]
=
CODEMETA_CONTEXT_URL
if
json_doc
[
"
@xmlns
"
]
not
in
(
ATOM_URI
,
[
ATOM_URI
]):
# Technically, non-default XMLNS were allowed, but no one used them,
# and we don't write this format anymore, so they do not need to be
# implemented here.
raise
NotImplementedError
(
f
"
Unexpected XMLNS set:
{
json_doc
}
"
)
# Root tag was stripped by swh-deposit
...
...
This diff is collapsed.
Click to expand it.
swh/indexer/tests/metadata_dictionary/test_codemeta.py
+
14
−
0
View file @
957db0f9
...
...
@@ -541,6 +541,20 @@ def test_json_sword():
}
def
test_json_sword_no_xmlns
():
content
=
"""
{
"
title
"
:
"
Example Software
"
,
"
codemeta:url
"
:
"
http://example.org/
"
,
"
codemeta:author
"
: [{
"
codemeta:name
"
:
"
Author 1
"
}],
"
codemeta:version
"
:
"
1.0
"
}
"""
# noqa
result
=
MAPPINGS
[
"
JsonSwordCodemetaMapping
"
]().
translate
(
content
)
assert
result
==
{
"
@context
"
:
"
https://doi.org/10.5063/schema/codemeta-2.0
"
,
"
author
"
:
[
{
"
name
"
:
"
Author 1
"
},
],
"
name
"
:
"
Example Software
"
,
"
url
"
:
"
http://example.org/
"
,
"
version
"
:
"
1.0
"
,
}
def
test_json_sword_codemeta_parsing_error
(
caplog
):
caplog
.
set_level
(
logging
.
ERROR
)
assert
MAPPINGS
[
"
JsonSwordCodemetaMapping
"
]().
translate
(
b
"
{123}
"
)
is
None
...
...
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