SearXNG is a free internet metasearch engine which aggregates results from various search services and databases. Users are neither tracked nor profiled.
Python bingbravedegoogleduckduckgogooglemetasearchprivacypythonqwantsearchsearch-enginesearxsearxngstartpageyahoo
[mod] engines: replace [random.choice(...) for ... in range(..)] with random.choices
Bnyroa449518ed410
diff --git a/searx/answerers/random.py b/searx/answerers/random.pyindex 44b94a0e2..4f7ed515f 100644--- a/searx/answerers/random.py+++ b/searx/answerers/random.py@@ -16,7 +16,7 @@ from . import Answerer, AnswererInfodef random_characters():random_string_letters = string.ascii_lowercase + string.digits + string.ascii_uppercase- return [random.choice(random_string_letters) for _ in range(random.randint(8, 32))]+ return random.choices(random_string_letters, k=random.randint(8, 32))def random_string():diff --git a/searx/autocomplete.py b/searx/autocomplete.pyindex 9e0c0d84f..2063aec7b 100644--- a/searx/autocomplete.py+++ b/searx/autocomplete.py@@ -62,7 +62,7 @@ def bing(query: str, _sxng_locale: str) -> list[str]:# bing search autocompleterbase_url = "https://www.bing.com/AS/Suggestions?"# cvid has to be a 32 character long string consisting of numbers and uppsercase characters- cvid = ''.join(random.choice(string.ascii_uppercase + string.digits) for _ in range(32))+ cvid = ''.join(random.choices(string.ascii_uppercase + string.digits, k=32))response = get(base_url + urlencode({'qry': query, 'csr': 1, 'cvid': cvid}))results: list[str] = []diff --git a/searx/engines/500px.py b/searx/engines/500px.pyindex 99596c144..583995948 100644--- a/searx/engines/500px.py+++ b/searx/engines/500px.py@@ -82,7 +82,7 @@ fragment SXNG_query on Query {def setup(_) -> bool:global SXNG_query # pylint: disable=global-statement- rand_str: str = "".join(random.choice(string.ascii_letters) for _ in range(5))+ rand_str: str = "".join(random.choices(string.ascii_letters, k=5))SXNG_query = SXNG_query.replace("SXNG_query", "PhotoSearchPaginationContainer_query_1" + rand_str)return Truediff --git a/searx/engines/bilibili.py b/searx/engines/bilibili.pyindex 9168bf733..dbd7c6bea 100644--- a/searx/engines/bilibili.py+++ b/searx/engines/bilibili.py@@ -32,7 +32,7 @@ base_url = "https://api.bilibili.com/x/web-interface/search/type"cookie = {"innersign": "0",- "buvid3": "".join(random.choice(string.hexdigits) for _ in range(16)) + "infoc",+ "buvid3": "".join(random.choices(string.hexdigits, k=16)) + "infoc","i-wanna-go-back": "-1","b_ut": "7","FEED_LIVE_VERSION": "V8",diff --git a/searx/engines/swisscows.py b/searx/engines/swisscows.pyindex 68f1d0bb5..ae10b065b 100644--- a/searx/engines/swisscows.py+++ b/searx/engines/swisscows.py@@ -92,7 +92,7 @@ def generate_nonce(length: int = 32) -> str:"""Generate a random char sequence with the given length."""- return "".join([random.choice(NONCE_ALPHABET) for _ in range(length)])+ return "".join(random.choices(NONCE_ALPHABET, k=length))def caesar_shift_with_switch_case(s: str, offset: int = 13) -> str:diff --git a/tests/unit/test_utils.py b/tests/unit/test_utils.pyindex 271ec629b..fc30ac33a 100644--- a/tests/unit/test_utils.py+++ b/tests/unit/test_utils.py@@ -13,7 +13,7 @@ from tests import SearxTestCasedef random_string(length, choices=string.ascii_letters):- return ''.join(random.choice(choices) for _ in range(length))+ return ''.join(random.choices(choices, k=length))class TestUtils(SearxTestCase):