Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def test_content_negotiation_alt_url():
"content negotiation - alternative url"
res = cn.content_negotiation(ids = '10.1126/science.169.3946.635', url = "http://doi.org")
assert str == str(res).__class__
def test_content_negotiation_raises_an_http_error_with_bad_requests():
"content negotiation - raises an HTTPError with bad requests"
res = cn.content_negotiation(ids = '10.1126/foo')
"""
parsed_refs = []
for ref in refs:
if ref in _REFERENCE_CACHE:
parsed_ref = _REFERENCE_CACHE[ref]
elif ref.startswith('@'):
parsed_ref = ref
elif ref.startswith('url:'):
# uses arbitrary key
url = ref.split('url:')[1]
parsed_ref = """@misc{{url:{0},
url = {{{1}}}
}}""".format(str(abs(url.__hash__()))[0:6], url)
elif ref.startswith('doi:'):
doi = ref.split('doi:')[1]
parsed_ref = content_negotiation(doi, format='bibentry')
elif ref.startswith('isbn:'):
isbn = ref.split('isbn:')[1]
parsed_ref = bibformatters['bibtex'](meta(isbn))
else:
raise ValueError('Unknown reference style for '
'reference: {} (please either '
'supply a BibTeX string, or a string '
'starting with url: followed by a URL or '
'starting with doi: followed by a DOI)'.format(ref))
if check_if_valid_citation:
try:
_ = references_to_markdown(parsed_ref)
except Exception as ex:
raise ValueError("Reference '{}' returned the following error.\n"
"You may need to manually generate a bibtex string:\n"
self.logger.debug(
f"Retrieved {len(refs)} formatted references from Crossref."
)
md = " \n\n".join(
f"> [{refs[doi]}](https://dx.doi.org/{doi}) "
f"Cited by {dois_to_item[doi]['cited-by']}."
for doi in sorted_dois
)
formatted_references = dcc.Markdown(md, className="mpc-markdown")
else:
# else retrieve BibTeX entries to extract a nice author list
# and perform our own formatting
entries = {
doi: content_negotiation(ids=doi, format="bibtex")
for doi in sorted_dois
}
formatted_entries = []
for doi, entry in entries.items():
author_string = self._bibtex_entry_to_author_text(entry)
journal_div = self._item_to_journal_div(dois_to_item[doi])
formatted_entries.append(
html.Blockquote(
[
html.A(
[
html.Div(
[
html.I(