How to use the idutils.normalize_doi function in idutils

To help you get started, we’ve selected a few idutils examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github zenodo / zenodo / tests / unit / records / test_schemas_json_load.py View on Github external
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())
github inspirehep / inspire-next / inspirehep / modules / references / processors.py View on Github external
def add_uid(self, uid):
        """Add unique identifier in correct field."""
        # We might add None values from wherever. Kill them here.
        uid = uid or ''
        if _is_arxiv(uid):
            self._ensure_reference_field('arxiv_eprint', _normalize_arxiv(uid))
        elif idutils.is_doi(uid):
            self._ensure_reference_field('dois', [])
            self.obj['reference']['dois'].append(idutils.normalize_doi(uid))
        elif idutils.is_handle(uid):
            self._ensure_reference_field('persistent_identifiers', [])
            self.obj['reference']['persistent_identifiers'].append({
                'schema': 'HDL',
                'value': idutils.normalize_handle(uid),
            })
        elif idutils.is_urn(uid):
            self._ensure_reference_field('persistent_identifiers', [])
            self.obj['reference']['persistent_identifiers'].append({
                'schema': 'URN',
                'value': uid,
            })
        elif self.RE_VALID_CNUM.match(uid):
            self._ensure_reference_field('publication_info', {})
            self.obj['reference']['publication_info']['cnum'] = uid
        else:
github zenodo / zenodo / zenodo / modules / records / serializers / fields / doi.py View on Github external
def _deserialize(self, value, attr, data):
        """Deserialize DOI value."""
        value = super(DOI, self)._deserialize(value, attr, data)
        value = value.strip()
        if value == '' and not (
                self.required or self.context.get('doi_required')):
            return value
        if not idutils.is_doi(value):
            self.fail('invalid_doi')
        return idutils.normalize_doi(value)
github inspirehep / inspire-next / inspirehep / modules / literaturesuggest / normalizers.py View on Github external
def normalize_provided_doi(obj, formdata):
    try:
        doi = formdata.get('doi')
        formdata['doi'] = normalize_doi(doi)
    except AttributeError:
        formdata['doi'] = None

    return formdata
github inspirehep / inspire-next / inspirehep / dojson / hep / rules / bd0xx.py View on Github external
persistent_identifiers = self.get('persistent_identifiers', [])

    values = force_list(value)
    for value in values:
        id_ = force_single_element(value.get('a', ''))
        material = force_single_element(value.get('q', '')).lower()
        schema = force_single_element(value.get('2', ''))

        sources = force_list(value.get('9'))
        source = _get_first_non_curator_source(sources)

        if _is_doi(id_, schema):
            dois.append({
                'material': material,
                'source': source,
                'value': normalize_doi(id_),
            })
        else:
            schema = 'HDL' if _is_handle(id_, schema) else schema
            persistent_identifiers.append({
                'material': material,
                'schema': schema,
                'source': source,
                'value': id_,
            })

    self['persistent_identifiers'] = persistent_identifiers
    return dois
github inspirehep / inspire-next / inspirehep / modules / crossref / views.py View on Github external
def search(doi=None):
    provided_doi = doi or request.args.get('doi')
    try:
        normalized_doi = normalize_doi(provided_doi)
        result = get_json(normalized_doi)
    except AttributeError:
        result = {
            'query': {},
            'source': 'inspire',
            'status': 'badrequest',
        }

    resp = jsonify(result)
    resp.status_code = current_app.config['CROSSREF_RESPONSE_CODES'].get(result['status'], 200)
    return resp