def isbns(self, key, value): "ISBN, its medium and an additional comment.""" try: isbn = normalize_isbn(value['a']) except (KeyError, ISBNError): 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' elif 'ebook' in b: medium = 'online' comment = 'ebook' elif 'hardcover' in b: medium = 'print' comment = 'hardcover' else: medium = '' comment = b return { 'medium': medium, 'value': isbn, 'comment': comment, }
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_eprints', []) self.obj['reference']['arxiv_eprints'].append(_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', []) value = idutils.normalize_handle(uid) if not value.startswith('hdl:'): # Prone to the day in which normalize_handle might prepend # 'hdl:'. value = u'hdl:{}'.format(value) self.obj['reference']['persistent_identifiers'].append(value) 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('publication_info', {}) self.obj['reference']['publication_info']['isbn'] = isbn # 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): pass
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' elif 'ebook' in b: medium = 'online' comment = 'ebook' elif 'hardcover' in b: medium = 'print' comment = 'hardcover' else: medium = '' comment = b return { 'medium': medium, 'value': isbn, 'comment': comment, }
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" elif "ebook" in b: medium = "online" comment = "ebook" elif "hardcover" in b: medium = "print" comment = "hardcover" else: medium = "" comment = b return {"medium": medium, "value": isbn, "comment": comment}
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' elif 'ebook' in b: medium = 'online' comment = 'ebook' elif 'hardcover' in b: medium = 'print' comment = 'hardcover' else: medium = '' comment = b return { 'medium': medium, 'value': isbn, 'comment': comment, }
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_eprints', []) self.obj['reference']['arxiv_eprints'].append( _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', []) value = idutils.normalize_handle(uid) if not value.startswith('hdl:'): # Prone to the day in which normalize_handle might prepend # 'hdl:'. value = u'hdl:{}'.format(value) self.obj['reference']['persistent_identifiers'].append(value) 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('publication_info', {}) self.obj['reference']['publication_info']['isbn'] = isbn # 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): pass
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_field("arxiv_eprints", []) self.obj["arxiv_eprints"].append(_normalize_arxiv(uid)) elif idutils.is_doi(uid): self._ensure_field("publication_info", {}) self.obj["publication_info"]["doi"] = idutils.normalize_doi(uid) elif idutils.is_handle(uid): self._ensure_field("persistent_identifiers", []) value = idutils.normalize_handle(uid) if not value.startswith("hdl:"): # Prone to the day in which normalize_handle might prepend # 'hdl:'. value = "hdl:{}".format(value) self.obj["persistent_identifiers"].append(value) elif self.RE_VALID_CNUM.match(uid): self._ensure_field("publication_info", {}) self.obj["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_field("publication_info", {}) self.obj["publication_info"]["isbn"] = isbn except ISBNError: pass
def isbns(self, key, value): "ISBN, its medium and an additional comment.""" try: isbn = normalize_isbn(value['a']) except (KeyError,): 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' elif 'ebook' in b: medium = 'online' comment = 'ebook' elif 'hardcover' in b: medium = 'print' comment = 'hardcover' else: medium = '' comment = b return { 'medium': medium, 'value': isbn, 'comment': comment, }
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: # 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)
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: # 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)
def hyphenate_if_possible(no_hyphens): try: return normalize_isbn(no_hyphens) except ISBNError: return no_hyphens