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_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_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`` is too strict in what it accepts. try: isbn = str(ISBN(uid)) self._ensure_reference_field('isbn', {}) self.obj['reference']['isbn'] = isbn except Exception: 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_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 _add_uid(self, uid, skip_handle=False): """Add unique identifier in correct field. The ``skip_handle`` flag is used when adding a uid through the add_url function since urls can be easily confused with handle elements. """ # 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', []) normalized_doi = idutils.normalize_doi(uid) if normalized_doi not in self.obj['reference']['dois']: self.obj['reference']['dois'].append(normalized_doi) elif idutils.is_handle(uid) and not skip_handle: 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 elif is_cds_url(uid): self._ensure_reference_field('external_system_identifiers', []) cds_id = extract_cds_id(uid) cds_id_dict = {'schema': 'CDS', 'value': cds_id} if cds_id_dict not in self.obj['reference'][ 'external_system_identifiers']: self.obj['reference']['external_system_identifiers'].append( cds_id_dict) elif is_ads_url(uid): self._ensure_reference_field('external_system_identifiers', []) self.obj['reference']['external_system_identifiers'].append({ 'schema': 'ADS', 'value': extract_ads_id(uid), }) else: # ``idutils.is_isbn`` is too strict in what it accepts. try: isbn = str(ISBN(uid)) self._ensure_reference_field('isbn', {}) self.obj['reference']['isbn'] = isbn except Exception: raise ValueError('Unrecognized uid type')
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 _is_handle(id_, type_): return (not type_ or type_.upper() == 'HDL') and is_handle(id_)
def _is_handle(id_, type_): return (not type_ or type_.upper() == 'HDL') and is_handle(id_)
def _is_handle(type_, id_): return (not type_ or type_.upper() in ('DOI', 'HDL')) and is_handle(id_)