Skip to content

Commit

Permalink
manubot#337 Set default timeout on ISBN search.
Browse files Browse the repository at this point in the history
  • Loading branch information
xihh87 committed Jul 26, 2022
1 parent d919de2 commit 57e80e6
Showing 1 changed file with 11 additions and 0 deletions.
11 changes: 11 additions & 0 deletions manubot/cite/isbn.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@

from .handlers import Handler

default_timeout = 3


class Handler_ISBN(Handler):

Expand All @@ -16,6 +18,9 @@ class Handler_ISBN(Handler):
def inspect(self, citekey):
import isbnlib

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

fail = isbnlib.notisbn(citekey.accession, level="strict")
if fail:
return f"identifier violates the ISBN syntax according to isbnlib v{isbnlib.__version__}"
Expand All @@ -41,6 +46,9 @@ def get_isbn_csl_item(isbn: str):
"""
import isbnlib

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

isbn = isbnlib.to_isbn13(isbn)
for retriever in isbn_retrievers:
try:
Expand Down Expand Up @@ -131,6 +139,9 @@ def get_isbn_csl_item_isbnlib(isbn: str):
"""
import isbnlib

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

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

0 comments on commit 57e80e6

Please sign in to comment.