Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def test_valid_doi(input_val, ctx):
"""Test DOI."""
data, errors = MetadataSchemaV1(
partial=['doi'], context=ctx).load(dict(doi=input_val))
assert data['doi'] == idutils.normalize_doi(input_val.strip())
def test_identifier_schemes(app, db, minimal_record):
"""Test supported identifier schemes."""
supported_schemes = [s for s, _ in idutils.PID_SCHEMES]
minimal_record['related_identifiers'] = [
{'scheme': scheme, 'relation': 'references', 'identifier': 'foobar'}
for scheme in supported_schemes
]
# JSONSchema validation should allow all supported schemes
Record.create(minimal_record)
def _normalize_arxiv(obj):
"""Return a normalized arXiv identfier.
As in ``_is_arxiv``, we need to handle arXiv references as well
as arXiv identifiers. We also need to return a simpler arXiv
identifier than what ``idutils`` would output, so we use some
of its helpers instead of ``normalize_arxiv``.
"""
obj = obj.split()[0]
m = idutils.is_arxiv_pre_2007(obj)
if m:
return ''.join(m.group(2, 4, 5))
m = idutils.is_arxiv_post_2007(obj)
if m:
return '.'.join(m.group(2, 3))
def arxiv_id(self, key, value):
from idutils import is_arxiv_post_2007
if is_arxiv_post_2007(value):
arxiv_rep_number = {'value': 'arXiv:' + value}
else:
arxiv_rep_number = {'value': value}
if len(value.split('/')) == 2:
arxiv_rep_number['categories'] = value.split('/')[0]
if 'arxiv_eprints' in self:
self['arxiv_eprints'].append(arxiv_rep_number)
else:
self['arxiv_eprints'] = [arxiv_rep_number]
def arxiv_id(self, key, value):
if is_arxiv_post_2007(value):
arxiv_rep_number = {'value': 'arXiv:' + value}
else:
arxiv_rep_number = {'value': value}
if len(value.split('/')) == 2:
arxiv_rep_number['categories'] = value.split('/')[0]
if 'arxiv_eprints' in self:
self['arxiv_eprints'].append(arxiv_rep_number)
else:
self['arxiv_eprints'] = [arxiv_rep_number]
raise IgnoreKey
def _is_arxiv(obj):
"""Return ``True`` if ``obj`` contains an arXiv identifier.
The ``idutils`` library only handles arXiv identifiers, e.g. strings
of the form ``arXiv:yymm.xxxxx``, but we sometimes have to deal with
arXiv references, which might contain more information separated by
a space. Therefore this helper wraps ``idutils`` to support this case.
"""
arxiv_test = obj.split()
if not arxiv_test:
return False
return idutils.is_arxiv(arxiv_test[0])
def _normalize_arxiv(obj):
"""Return a normalized arXiv identfier.
As in ``_is_arxiv``, we need to handle arXiv references as well
as arXiv identifiers. We also need to return a simpler arXiv
identifier than what ``idutils`` would output, so we use some
of its helpers instead of ``normalize_arxiv``.
"""
obj = obj.split()[0]
m = idutils.is_arxiv_pre_2007(obj)
if m:
return ''.join(m.group(2, 4, 5))
m = idutils.is_arxiv_post_2007(obj)
if m:
return '.'.join(m.group(2, 3))
def _serialize(self, value, attr, obj):
if value is None:
return None
return idutils.to_url(value, 'doi', 'https')
def apply_rule(item, rule):
r = copy.deepcopy(rule)
r['link'] = idutils.to_url(item['identifier'], item['scheme'], 'https')
return r
def _dump_common_links(self, obj):
"""Dump common links for deposits and records."""
links = {}
m = obj.get('metadata', {})
doi = m.get('doi')
if doi:
links['badge'] = ui_link_for('badge', doi=quote(doi))
links['doi'] = idutils.to_url(doi, 'doi', 'https')
conceptdoi = m.get('conceptdoi')
if conceptdoi:
links['conceptbadge'] = ui_link_for('badge', doi=quote(conceptdoi))
links['conceptdoi'] = idutils.to_url(conceptdoi, 'doi', 'https')
files = m.get('_files', [])
for f in files:
if f.get('type') in thumbnail_exts:
try:
# First previewable image is used for preview.
links['thumbs'] = self._thumbnail_urls(m.get('recid'))
links['thumb250'] = self._thumbnail_url(f, 250)
except RuntimeError:
pass
break