Skip to content

Commit

Permalink
manubot#337 Single timeout value for arxiv.
Browse files Browse the repository at this point in the history
  • Loading branch information
xihh87 committed Jun 16, 2022
1 parent c19ad5d commit 93c5281
Showing 1 changed file with 20 additions and 11 deletions.
31 changes: 20 additions & 11 deletions manubot/cite/arxiv.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,14 +9,18 @@
from .csl_item import CSL_Item
from .handlers import Handler

default_timeout = 3

class Handler_arXiv(Handler):

standard_prefix = "arxiv"
class Handler_arXiv(Handler):
def __init__(self):
self.upper().__init__(
standard_prefix="arxiv",
prefixes=[
"arxiv",
],
)

prefixes = [
"arxiv",
]
accession_pattern = re.compile(
r"(?P<versionless_id>[0-9]{4}\.[0-9]{4,5}|[a-z\-]+(\.[A-Z]{2})?/[0-9]{7})(?P<version>v[0-9]+)?"
)
Expand All @@ -26,8 +30,13 @@ def inspect(self, citekey):
if not self._get_pattern().fullmatch(citekey.accession):
return "arXiv identifiers must conform to syntax described at https://arxiv.org/help/arxiv_identifier."

def get_csl_item(self, citekey, timeout: int = 3):
return get_arxiv_csl_item(citekey.standard_accession, timeout=timeout)
def get_csl_item(self, citekey, timeout: int):
if timeout:
return get_arxiv_csl_item(citekey.standard_accession, timeout=timeout)
else:
return get_arxiv_csl_item(
citekey.standard_accession, timeout=self.timeout_seconds
)


class CSL_Item_arXiv(CSL_Item):
Expand Down Expand Up @@ -77,15 +86,15 @@ def get_arxiv_csl_item(arxiv_id: str):
return get_arxiv_csl_item_oai(arxiv_id)


def query_arxiv_api(url, params, timeout: int = 3):
def query_arxiv_api(url, params, timeout: int = default_timeout):
headers = {"User-Agent": get_manubot_user_agent()}
response = requests.get(url, params, headers=headers, timeout=timeout)
response.raise_for_status()
xml_tree = xml.etree.ElementTree.fromstring(response.text)
return xml_tree


def get_arxiv_csl_item_export_api(arxiv_id, timeout: int = 3):
def get_arxiv_csl_item_export_api(arxiv_id, timeout: int = default_timeout):
"""
Return csl_item item for an arXiv record.
Expand Down Expand Up @@ -158,7 +167,7 @@ def get_arxiv_csl_item_export_api(arxiv_id, timeout: int = 3):
return csl_item


def get_arxiv_csl_item_oai(arxiv_id, timeout: int = 3):
def get_arxiv_csl_item_oai(arxiv_id, timeout: int = default_timeout):
"""
Generate a CSL Item for an unversioned arXiv identifier
using arXiv's OAI_PMH v2.0 API <https://arxiv.org/help/oa>.
Expand Down Expand Up @@ -239,7 +248,7 @@ def remove_newlines(text):
return re.sub(pattern=r"\n(?!\s)", repl=" ", string=text)


def get_arxiv_csl_item_zotero(arxiv_id, timeout: int = 3):
def get_arxiv_csl_item_zotero(arxiv_id, timeout: int = default_timeout):
"""
Generate CSL JSON Data for an arXiv ID using Zotero's translation-server.
"""
Expand Down

0 comments on commit 93c5281

Please sign in to comment.