How to use the idutils.normalize_isbn 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 inspirehep / inspire-next / inspirehep / modules / references / processors.py View on Github external
'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:
            # idutils.is_isbn has a different implementation than normalize
            # isbn. Better to do it like this.
            try:
                isbn = idutils.normalize_isbn(uid)
                self._ensure_reference_field('isbn', {})
                self.obj['reference']['isbn'] = isbn.replace(' ', '').replace('-', '')
            # See https://github.com/nekobcn/isbnid/issues/2 and
            # https://github.com/nekobcn/isbnid/issues/3 for understanding the
            # long exception list.
            except (ISBNError, ISBNRangeError, UnicodeEncodeError):
                self.add_misc(uid)
github inspirehep / inspire-next / inspirehep / modules / records / serializers / fields_export.py View on Github external
def hyphenate_if_possible(no_hyphens):
        try:
            return normalize_isbn(no_hyphens)
        except ISBNError:
            return no_hyphens
github inspirehep / inspire-next / inspirehep / dojson / hep / fields / bd01x09x.py View on Github external
def isbns(self, key, value):
    """ISBN, its medium and an additional comment."""
    try:
        isbn = normalize_isbn(force_single_element(value['a']))
    # See https://github.com/nekobcn/isbnid/issues/2 and
    # https://github.com/nekobcn/isbnid/issues/3 for understanding the long
    # exception list.
    except (KeyError, ISBNError, ISBNRangeError, UnicodeEncodeError):
        return {}

    b = value.get('b', '').lower()
    if 'online' == b:
        medium = 'online'
        comment = ''
    elif 'print' == b:
        medium = 'print'
        comment = ''
    elif 'electronic' in b:
        medium = 'online'
        comment = 'electronic'