Skip to content

Commit 489fa1f

Browse files
committed
Reuse _validate_http_url
1 parent 92f0081 commit 489fa1f

File tree

1 file changed

+4
-7
lines changed

1 file changed

+4
-7
lines changed

planemo/lint.py

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,8 @@
2222
if TYPE_CHECKING:
2323
from planemo.cli import PlanemoCliContext
2424

25+
REQUEST_TIMEOUT = 5
26+
2527

2628
def build_lint_args(ctx: "PlanemoCliContext", **kwds) -> Dict[str, Any]:
2729
"""Handle common report, error, and skip linting arguments."""
@@ -134,20 +136,15 @@ def _validate_doi_url(url, lint_ctx):
134136

135137
doi = match.group(1)
136138
xref_url = f"https://api.crossref.org/works/{doi}"
137-
try:
138-
requests.get(xref_url, timeout=5)
139-
return True
140-
except Exception as e:
141-
lint_ctx.error(f"Error '{e}' accessing {url}")
142-
return False
139+
return _validate_http_url(xref_url, lint_ctx=lint_ctx)
143140

144141

145142
def _validate_http_url(url, lint_ctx, user_agent=None):
146143
"""Validate HTTP/HTTPS URL."""
147144
headers = {"User-Agent": user_agent, "Accept": "*/*"} if user_agent else None
148145
r = None
149146
try:
150-
r = requests.get(url, headers=headers, stream=True)
147+
r = requests.get(url, headers=headers, stream=True, timeout=REQUEST_TIMEOUT)
151148
r.raise_for_status()
152149
next(r.iter_content(1000))
153150
return True

0 commit comments

Comments
 (0)