mirror of
https://github.com/pewdiepie-archdaemon/odysseus.git
synced 2026-10-20 05:42:20 +02:00
bound optional search fallback latency
This commit is contained in:
@@ -453,7 +453,11 @@ def duckduckgo_search(query: str, count: Optional[int] = None, time_filter: Opti
|
|||||||
"https://html.duckduckgo.com/html/",
|
"https://html.duckduckgo.com/html/",
|
||||||
params={"q": query, "kp": _safesearch_for("duckduckgo_html")},
|
params={"q": query, "kp": _safesearch_for("duckduckgo_html")},
|
||||||
headers={"User-Agent": WEB_FETCH_USER_AGENT},
|
headers={"User-Agent": WEB_FETCH_USER_AGENT},
|
||||||
timeout=REQUEST_TIMEOUT,
|
# This is a last-resort compatibility path when the declared
|
||||||
|
# optional ``ddgs`` dependency is absent. Keep it short so a
|
||||||
|
# blocked public endpoint cannot consume the full search SLA
|
||||||
|
# across provider and query-relaxation retries.
|
||||||
|
timeout=min(REQUEST_TIMEOUT, 5),
|
||||||
)
|
)
|
||||||
response.raise_for_status()
|
response.raise_for_status()
|
||||||
soup = BeautifulSoup(response.text, "html.parser")
|
soup = BeautifulSoup(response.text, "html.parser")
|
||||||
|
|||||||
@@ -684,6 +684,7 @@ def test_service_ddg_html_fallback_sends_safesearch(monkeypatch):
|
|||||||
|
|
||||||
def fake_get(url, **kwargs):
|
def fake_get(url, **kwargs):
|
||||||
seen["params"] = kwargs["params"]
|
seen["params"] = kwargs["params"]
|
||||||
|
seen["timeout"] = kwargs["timeout"]
|
||||||
return _Response()
|
return _Response()
|
||||||
|
|
||||||
monkeypatch.setattr(providers, "_get_search_settings", lambda: {"search_safesearch": "off"})
|
monkeypatch.setattr(providers, "_get_search_settings", lambda: {"search_safesearch": "off"})
|
||||||
@@ -693,4 +694,5 @@ def test_service_ddg_html_fallback_sends_safesearch(monkeypatch):
|
|||||||
results = providers.duckduckgo_search("odysseus", count=1)
|
results = providers.duckduckgo_search("odysseus", count=1)
|
||||||
|
|
||||||
assert seen["params"]["kp"] == "-2"
|
assert seen["params"]["kp"] == "-2"
|
||||||
|
assert seen["timeout"] <= 5
|
||||||
assert results[0]["url"].startswith("https://notduckduckgo.com/")
|
assert results[0]["url"].startswith("https://notduckduckgo.com/")
|
||||||
|
|||||||
Reference in New Issue
Block a user