Skip to content

Commit

Permalink
manubot#337 add helper to make @dhimmel happy.
Browse files Browse the repository at this point in the history
  • Loading branch information
xihh87 committed Jul 26, 2022
1 parent 57e80e6 commit 82eca7f
Showing 1 changed file with 11 additions and 14 deletions.
25 changes: 11 additions & 14 deletions manubot/cite/isbn.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,14 @@
default_timeout = 3


def set_isbnlib_timeout(seconds=default_timeout):
import isbnlib

isbnlib.config.setthreadstimeout(seconds=seconds)
isbnlib.config.seturlopentimeout(seconds=seconds)
return isbnlib


class Handler_ISBN(Handler):

standard_prefix = "isbn"
Expand All @@ -16,11 +24,7 @@ class Handler_ISBN(Handler):
]

def inspect(self, citekey):
import isbnlib

isbnlib.config.setthreadstimeout(seconds=timeout_seconds)
isbnlib.config.seturlopentimeout(seconds=timeout_seconds)

isbnlib = set_isbnlib_timeout()
fail = isbnlib.notisbn(citekey.accession, level="strict")
if fail:
return f"identifier violates the ISBN syntax according to isbnlib v{isbnlib.__version__}"
Expand All @@ -44,10 +48,7 @@ def get_isbn_csl_item(isbn: str):
in order, with this function returning the metadata from the first
non-failing method.
"""
import isbnlib

isbnlib.config.setthreadstimeout(seconds=timeout_seconds)
isbnlib.config.seturlopentimeout(seconds=timeout_seconds)
isbnlib = set_isbnlib_timeout()

isbn = isbnlib.to_isbn13(isbn)
for retriever in isbn_retrievers:
Expand Down Expand Up @@ -137,11 +138,7 @@ def get_isbn_csl_item_isbnlib(isbn: str):
"""
Generate CSL JSON Data for an ISBN using isbnlib.
"""
import isbnlib

isbnlib.config.setthreadstimeout(seconds=timeout_seconds)
isbnlib.config.seturlopentimeout(seconds=timeout_seconds)

isbnlib = set_isbnlib_timeout()
metadata = isbnlib.meta(isbn)
csl_json = isbnlib.registry.bibformatters["csl"](metadata)
csl_data = json.loads(csl_json)
Expand Down

0 comments on commit 82eca7f

Please sign in to comment.