[fix] pylint: use "raise ... from ..."

This commit is contained in:
Alexandre Flament 2020-12-17 09:57:57 +01:00
parent eb33ae6893
commit 3f8ebf70b1
4 changed files with 12 additions and 12 deletions

View file

@ -46,8 +46,8 @@ def _match_query(query):
try: try:
key, value = query.split(':') key, value = query.split(':')
except: except Exception as e:
raise ValueError('query format must be "key:value"') raise ValueError('query format must be "key:value"') from e
return {"query": {"match": {key: {'query': value}}}} return {"query": {"match": {key: {'query': value}}}}
@ -71,8 +71,8 @@ def _term_query(query):
try: try:
key, value = query.split(':') key, value = query.split(':')
except: except Exception as e:
raise ValueError('query format must be key:value') raise ValueError('query format must be key:value') from e
return {'query': {'term': {key: value}}} return {'query': {'term': {key: value}}}
@ -86,8 +86,8 @@ def _terms_query(query):
try: try:
key, values = query.split(':') key, values = query.split(':')
except: except Exception as e:
raise ValueError('query format must be key:value1,value2') raise ValueError('query format must be key:value1,value2') from e
return {'query': {'terms': {key: values.split(',')}}} return {'query': {'terms': {key: values.split(',')}}}

View file

@ -24,9 +24,9 @@ def load_yaml(file_name):
with open(file_name, 'r', encoding='utf-8') as settings_yaml: with open(file_name, 'r', encoding='utf-8') as settings_yaml:
return yaml.safe_load(settings_yaml) return yaml.safe_load(settings_yaml)
except IOError as e: except IOError as e:
raise SearxSettingsException(e, file_name) raise SearxSettingsException(e, file_name) from e
except yaml.YAMLError as e: except yaml.YAMLError as e:
raise SearxSettingsException(e, file_name) raise SearxSettingsException(e, file_name) from e
def get_default_settings_path(): def get_default_settings_path():

View file

@ -522,7 +522,7 @@ def get_xpath(xpath_spec):
try: try:
result = XPath(xpath_spec) result = XPath(xpath_spec)
except XPathSyntaxError as e: except XPathSyntaxError as e:
raise SearxXPathSyntaxException(xpath_spec, str(e.msg)) raise SearxXPathSyntaxException(xpath_spec, str(e.msg)) from e
xpath_cache[xpath_spec] = result xpath_cache[xpath_spec] = result
return result return result
@ -553,7 +553,7 @@ def eval_xpath(element, xpath_spec):
return xpath(element) return xpath(element)
except XPathError as e: except XPathError as e:
arg = ' '.join([str(i) for i in e.args]) arg = ' '.join([str(i) for i in e.args])
raise SearxEngineXPathException(xpath_spec, arg) raise SearxEngineXPathException(xpath_spec, arg) from e
def eval_xpath_list(element, xpath_spec, min_len=None): def eval_xpath_list(element, xpath_spec, min_len=None):

View file

@ -105,8 +105,8 @@ def parse_timeout(form: Dict[str, str], raw_text_query: RawTextQuery) -> Optiona
return None return None
try: try:
return float(timeout_limit) return float(timeout_limit)
except ValueError: except ValueError as e:
raise SearxParameterException('timeout_limit', timeout_limit) raise SearxParameterException('timeout_limit', timeout_limit) from e
def parse_category_form(query_categories: List[str], name: str, value: str) -> None: def parse_category_form(query_categories: List[str], name: str, value: str) -> None: