How to use the idutils.detect_identifier_schemes 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 / zenodo / modules / records / serializers / schemas / common.py View on Github external
def validate_data(self, data):
        """Validate identifier and scheme."""
        id_ = data.get('identifier')
        scheme = data.get('scheme')
        if not id_:
            raise ValidationError(
                'Identifier is required.',
                field_names=['identifier']
            )

        schemes = idutils.detect_identifier_schemes(id_)
        if not schemes:
            raise ValidationError(
                'Not a valid persistent identifier.',
                field_names=['identifier']
            )
        if scheme not in schemes:
            raise ValidationError(
                'Not a valid {0} identifier.'.format(scheme),
                field_names=['identifier']
            )
github zenodo / zenodo / zenodo / modules / records / views.py View on Github external
def pid_url(identifier, scheme=None, url_scheme='https'):
    """Convert persistent identifier into a link."""
    if scheme is None:
        try:
            scheme = idutils.detect_identifier_schemes(identifier)[0]
        except IndexError:
            scheme = None
    try:
        if scheme and identifier:
            return idutils.to_url(identifier, scheme, url_scheme=url_scheme)
    except Exception:
        current_app.logger.warning('URL generation for identifier {0} failed.'
                                   .format(identifier), exc_info=True)
    return ''
github inveniosoftware / invenio / invenio / modules / deposit / validation_utils.py View on Github external
def __call__(self, form, field):
        """Validate."""
        schemes = idutils.detect_identifier_schemes(field.data)
        if not schemes:
            raise ValidationError(self.message)
github zenodo / zenodo / zenodo / modules / records / serializers / fields / persistentid.py View on Github external
def _deserialize(self, value, attr, data):
        """Deserialize persistent identifier value."""
        value = super(PersistentId, self)._deserialize(value, attr, data)
        value = value.strip()

        schemes = idutils.detect_identifier_schemes(value)
        if self.scheme and self.scheme.lower() not in schemes:
            self.fail('invalid_scheme', scheme=self.scheme)
        if not schemes:
            self.fail('invalid_pid')
        return idutils.normalize_pid(value, schemes[0]) \
            if self.normalize else value
github zenodo / zenodo / zenodo / modules / deposit / loaders / schemas / legacyjson.py View on Github external
def get_scheme(self, obj):
        """Get scheme."""
        scheme = obj.get('scheme')
        if not scheme and obj.get('identifier'):
            scheme = idutils.detect_identifier_schemes(obj['identifier'])
            if scheme:
                scheme = scheme[0]
        return scheme if scheme else ""
github zenodo / zenodo / zenodo / modules / records / serializers / schemas / common.py View on Github external
def detect_scheme(self, data):
        """Load scheme."""
        id_ = data.get('identifier')
        scheme = data.get('scheme')
        if not scheme and id_:
            scheme = idutils.detect_identifier_schemes(id_)
            if scheme:
                data['scheme'] = scheme[0]
        return data