mirror of
https://github.com/searxng/searxng.git
synced 2026-07-31 04:11:26 +00:00
[mod] engines: replace [random.choice(...) for ... in range(..)] with random.choices
This commit is contained in:
@@ -16,7 +16,7 @@ from . import Answerer, AnswererInfo
|
|||||||
|
|
||||||
def random_characters():
|
def random_characters():
|
||||||
random_string_letters = string.ascii_lowercase + string.digits + string.ascii_uppercase
|
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():
|
def random_string():
|
||||||
|
|||||||
@@ -62,7 +62,7 @@ def bing(query: str, _sxng_locale: str) -> list[str]:
|
|||||||
# bing search autocompleter
|
# bing search autocompleter
|
||||||
base_url = "https://www.bing.com/AS/Suggestions?"
|
base_url = "https://www.bing.com/AS/Suggestions?"
|
||||||
# cvid has to be a 32 character long string consisting of numbers and uppsercase characters
|
# 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}))
|
response = get(base_url + urlencode({'qry': query, 'csr': 1, 'cvid': cvid}))
|
||||||
results: list[str] = []
|
results: list[str] = []
|
||||||
|
|
||||||
|
|||||||
@@ -82,7 +82,7 @@ fragment SXNG_query on Query {
|
|||||||
|
|
||||||
def setup(_) -> bool:
|
def setup(_) -> bool:
|
||||||
global SXNG_query # pylint: disable=global-statement
|
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)
|
SXNG_query = SXNG_query.replace("SXNG_query", "PhotoSearchPaginationContainer_query_1" + rand_str)
|
||||||
return True
|
return True
|
||||||
|
|
||||||
|
|||||||
@@ -32,7 +32,7 @@ base_url = "https://api.bilibili.com/x/web-interface/search/type"
|
|||||||
|
|
||||||
cookie = {
|
cookie = {
|
||||||
"innersign": "0",
|
"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",
|
"i-wanna-go-back": "-1",
|
||||||
"b_ut": "7",
|
"b_ut": "7",
|
||||||
"FEED_LIVE_VERSION": "V8",
|
"FEED_LIVE_VERSION": "V8",
|
||||||
|
|||||||
@@ -92,7 +92,7 @@ def generate_nonce(length: int = 32) -> str:
|
|||||||
"""
|
"""
|
||||||
Generate a random char sequence with the given length.
|
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:
|
def caesar_shift_with_switch_case(s: str, offset: int = 13) -> str:
|
||||||
|
|||||||
@@ -13,7 +13,7 @@ from tests import SearxTestCase
|
|||||||
|
|
||||||
|
|
||||||
def random_string(length, choices=string.ascii_letters):
|
def 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):
|
class TestUtils(SearxTestCase):
|
||||||
|
|||||||
Reference in New Issue
Block a user