mirror of
https://github.com/searxng/searxng.git
synced 2024-11-22 12:10:11 +01:00
Updates to naming, pylint fixing
This commit is contained in:
parent
118a748fba
commit
27aa9c4cb1
@ -3,10 +3,10 @@
|
|||||||
|
|
||||||
import typing
|
import typing
|
||||||
import inspect
|
import inspect
|
||||||
|
import logging
|
||||||
from json import JSONDecodeError
|
from json import JSONDecodeError
|
||||||
from urllib.parse import urlparse
|
from urllib.parse import urlparse
|
||||||
from httpx import HTTPError, HTTPStatusError
|
from httpx import HTTPError, HTTPStatusError
|
||||||
import logging
|
|
||||||
from searx.exceptions import (
|
from searx.exceptions import (
|
||||||
SearxXPathSyntaxException,
|
SearxXPathSyntaxException,
|
||||||
SearxEngineXPathException,
|
SearxEngineXPathException,
|
||||||
|
@ -357,7 +357,7 @@ class Checker: # pylint: disable=missing-class-docstring
|
|||||||
|
|
||||||
def __init__(self, processor: EngineProcessor):
|
def __init__(self, processor: EngineProcessor):
|
||||||
self.processor = processor
|
self.processor = processor
|
||||||
self.processor.engine_exc_info = False # Remove exception information from errors to reduce verbosity
|
self.processor.log_engine_exc_info = False # Remove exception information from errors to reduce verbosity
|
||||||
self.tests = self.processor.get_tests()
|
self.tests = self.processor.get_tests()
|
||||||
self.test_results = TestResults()
|
self.test_results = TestResults()
|
||||||
|
|
||||||
@ -422,7 +422,7 @@ class Checker: # pylint: disable=missing-class-docstring
|
|||||||
def run_test(self, test_name: str):
|
def run_test(self, test_name: str):
|
||||||
test_parameters = self.tests[test_name]
|
test_parameters = self.tests[test_name]
|
||||||
# Not really a warning, but an info log will not appear
|
# Not really a warning, but an info log will not appear
|
||||||
logger.warning('running test: %s', test_name)
|
logger.warning('---%s---', test_name)
|
||||||
search_query_list = list(Checker.search_query_matrix_iterator(self.engineref_list, test_parameters['matrix']))
|
search_query_list = list(Checker.search_query_matrix_iterator(self.engineref_list, test_parameters['matrix']))
|
||||||
rct_list = [self.get_result_container_tests(test_name, search_query) for search_query in search_query_list]
|
rct_list = [self.get_result_container_tests(test_name, search_query) for search_query in search_query_list]
|
||||||
stop_test = False
|
stop_test = False
|
||||||
|
@ -60,13 +60,13 @@ class SuspendedStatus:
|
|||||||
class EngineProcessor(ABC):
|
class EngineProcessor(ABC):
|
||||||
"""Base classes used for all types of request processors."""
|
"""Base classes used for all types of request processors."""
|
||||||
|
|
||||||
__slots__ = 'engine', 'engine_name', 'lock', 'suspended_status', 'logger', 'engine_exc_info'
|
__slots__ = 'engine', 'engine_name', 'lock', 'suspended_status', 'logger', 'log_engine_exc_info'
|
||||||
|
|
||||||
def __init__(self, engine, engine_name: str):
|
def __init__(self, engine, engine_name: str):
|
||||||
self.engine = engine
|
self.engine = engine
|
||||||
self.engine_name = engine_name
|
self.engine_name = engine_name
|
||||||
self.logger: Logger = engines[engine_name].logger
|
self.logger: Logger = engines[engine_name].logger
|
||||||
self.engine_exc_info = True
|
self.log_engine_exc_info = True
|
||||||
key = get_network(self.engine_name)
|
key = get_network(self.engine_name)
|
||||||
key = id(key) if key else self.engine_name
|
key = id(key) if key else self.engine_name
|
||||||
self.suspended_status = SUSPENDED_STATUS.setdefault(key, SuspendedStatus())
|
self.suspended_status = SUSPENDED_STATUS.setdefault(key, SuspendedStatus())
|
||||||
@ -85,6 +85,10 @@ class EngineProcessor(ABC):
|
|||||||
def has_initialize_function(self):
|
def has_initialize_function(self):
|
||||||
return hasattr(self.engine, 'init')
|
return hasattr(self.engine, 'init')
|
||||||
|
|
||||||
|
@property
|
||||||
|
def metrics_log_level(self) -> int:
|
||||||
|
return logging.WARN if self.log_engine_exc_info else logging.NOTSET
|
||||||
|
|
||||||
def handle_exception(self, result_container, exception_or_message, suspend=False):
|
def handle_exception(self, result_container, exception_or_message, suspend=False):
|
||||||
# update result_container
|
# update result_container
|
||||||
if isinstance(exception_or_message, BaseException):
|
if isinstance(exception_or_message, BaseException):
|
||||||
@ -97,11 +101,10 @@ class EngineProcessor(ABC):
|
|||||||
result_container.add_unresponsive_engine(self.engine_name, error_message)
|
result_container.add_unresponsive_engine(self.engine_name, error_message)
|
||||||
# metrics
|
# metrics
|
||||||
counter_inc('engine', self.engine_name, 'search', 'count', 'error')
|
counter_inc('engine', self.engine_name, 'search', 'count', 'error')
|
||||||
log_level = logging.WARN if self.engine_exc_info else logging.NOTSET
|
|
||||||
if isinstance(exception_or_message, BaseException):
|
if isinstance(exception_or_message, BaseException):
|
||||||
count_exception(self.engine_name, exception_or_message, log_level=log_level)
|
count_exception(self.engine_name, exception_or_message, log_level=self.metrics_log_level)
|
||||||
else:
|
else:
|
||||||
count_error(self.engine_name, exception_or_message, log_level=log_level)
|
count_error(self.engine_name, exception_or_message, log_level=self.metrics_log_level)
|
||||||
# suspend the engine ?
|
# suspend the engine ?
|
||||||
if suspend:
|
if suspend:
|
||||||
suspended_time = None
|
suspended_time = None
|
||||||
|
@ -126,8 +126,8 @@ class OnlineProcessor(EngineProcessor):
|
|||||||
self.engine_name,
|
self.engine_name,
|
||||||
'{} redirects, maximum: {}'.format(len(response.history), soft_max_redirects),
|
'{} redirects, maximum: {}'.format(len(response.history), soft_max_redirects),
|
||||||
(status_code, reason, hostname),
|
(status_code, reason, hostname),
|
||||||
self.engine_exc_info,
|
|
||||||
secondary=True,
|
secondary=True,
|
||||||
|
log_level=self.metrics_log_level,
|
||||||
)
|
)
|
||||||
|
|
||||||
return response
|
return response
|
||||||
@ -182,20 +182,20 @@ class OnlineProcessor(EngineProcessor):
|
|||||||
"requests exception (search duration : {0} s, timeout: {1} s) : {2}".format(
|
"requests exception (search duration : {0} s, timeout: {1} s) : {2}".format(
|
||||||
default_timer() - start_time, timeout_limit, e
|
default_timer() - start_time, timeout_limit, e
|
||||||
),
|
),
|
||||||
exc_info=self.engine_exc_info,
|
exc_info=self.log_engine_exc_info,
|
||||||
)
|
)
|
||||||
except SearxEngineCaptchaException as e:
|
except SearxEngineCaptchaException as e:
|
||||||
self.handle_exception(result_container, e, suspend=True)
|
self.handle_exception(result_container, e, suspend=True)
|
||||||
self.logger.exception('CAPTCHA', exc_info=self.engine_exc_info)
|
self.logger.exception('CAPTCHA', exc_info=self.log_engine_exc_info)
|
||||||
except SearxEngineTooManyRequestsException as e:
|
except SearxEngineTooManyRequestsException as e:
|
||||||
self.handle_exception(result_container, e, suspend=True)
|
self.handle_exception(result_container, e, suspend=True)
|
||||||
self.logger.exception('Too many requests', exc_info=self.engine_exc_info)
|
self.logger.exception('Too many requests', exc_info=self.log_engine_exc_info)
|
||||||
except SearxEngineAccessDeniedException as e:
|
except SearxEngineAccessDeniedException as e:
|
||||||
self.handle_exception(result_container, e, suspend=True)
|
self.handle_exception(result_container, e, suspend=True)
|
||||||
self.logger.exception('SearXNG is blocked', exc_info=self.engine_exc_info)
|
self.logger.exception('SearXNG is blocked', exc_info=self.log_engine_exc_info)
|
||||||
except Exception as e: # pylint: disable=broad-except
|
except Exception as e: # pylint: disable=broad-except
|
||||||
self.handle_exception(result_container, e)
|
self.handle_exception(result_container, e)
|
||||||
self.logger.exception('exception : {0}'.format(e), exc_info=self.engine_exc_info)
|
self.logger.exception('exception : {0}'.format(e), exc_info=self.log_engine_exc_info)
|
||||||
|
|
||||||
def get_default_tests(self):
|
def get_default_tests(self):
|
||||||
tests = {}
|
tests = {}
|
||||||
|
Loading…
Reference in New Issue
Block a user