Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Verified Commit 838e5151 authored by Nivesh Krishna's avatar Nivesh Krishna
Browse files

code formatting

parent 6036f6ad
Loading
Loading
Loading
Loading
+1 −1
Original line number Original line Diff line number Diff line
@@ -12,7 +12,7 @@ services:
python:
python:
  stage: check
  stage: check
  script:
  script:
    - ./manage test.pep8
    - ./manage test.black
    - ./manage test.pylint
    - ./manage test.pylint


build:web:
build:web:

.vscode/settings.json

0 → 100644
+3 −0
Original line number Original line Diff line number Diff line
{
    "python.formatting.provider": "black"
}
 No newline at end of file
+31 −26
Original line number Original line Diff line number Diff line
@@ -14,10 +14,10 @@ from searx.settings_defaults import settings_set_defaults




# Debug
# Debug
LOG_FORMAT_DEBUG = '%(levelname)-7s %(name)-30.30s: %(message)s'
LOG_FORMAT_DEBUG = "%(levelname)-7s %(name)-30.30s: %(message)s"


# Production
# Production
LOG_FORMAT_PROD = '%(asctime)-15s %(levelname)s:%(name)s: %(message)s'
LOG_FORMAT_PROD = "%(asctime)-15s %(levelname)s:%(name)s: %(message)s"
LOG_LEVEL_PROD = logging.WARNING
LOG_LEVEL_PROD = logging.WARNING


searx_dir = abspath(dirname(__file__))
searx_dir = abspath(dirname(__file__))
@@ -36,7 +36,7 @@ def get_setting(name, default=_unset):


    """
    """
    value = settings
    value = settings
    for a in name.split('.'):
    for a in name.split("."):
        if isinstance(value, dict):
        if isinstance(value, dict):
            value = value.get(a, _unset)
            value = value.get(a, _unset)
        else:
        else:
@@ -52,7 +52,7 @@ def get_setting(name, default=_unset):




def is_color_terminal():
def is_color_terminal():
    if os.getenv('TERM') in ('dumb', 'unknown'):
    if os.getenv("TERM") in ("dumb", "unknown"):
        return False
        return False
    return sys.stdout.isatty()
    return sys.stdout.isatty()


@@ -63,44 +63,49 @@ def logging_config_debug():
    except ImportError:
    except ImportError:
        coloredlogs = None
        coloredlogs = None


    log_level = os.environ.get('SEARXNG_DEBUG_LOG_LEVEL', 'DEBUG')
    log_level = os.environ.get("SEARXNG_DEBUG_LOG_LEVEL", "DEBUG")
    if coloredlogs and is_color_terminal():
    if coloredlogs and is_color_terminal():
        level_styles = {
        level_styles = {
            'spam': {'color': 'green', 'faint': True},
            "spam": {"color": "green", "faint": True},
            'debug': {},
            "debug": {},
            'notice': {'color': 'magenta'},
            "notice": {"color": "magenta"},
            'success': {'bold': True, 'color': 'green'},
            "success": {"bold": True, "color": "green"},
            'info': {'bold': True, 'color': 'cyan'},
            "info": {"bold": True, "color": "cyan"},
            'warning': {'color': 'yellow'},
            "warning": {"color": "yellow"},
            'error': {'color': 'red'},
            "error": {"color": "red"},
            'critical': {'bold': True, 'color': 'red'},
            "critical": {"bold": True, "color": "red"},
        }
        }
        field_styles = {
        field_styles = {
            'asctime': {'color': 'green'},
            "asctime": {"color": "green"},
            'hostname': {'color': 'magenta'},
            "hostname": {"color": "magenta"},
            'levelname': {'color': 8},
            "levelname": {"color": 8},
            'name': {'color': 8},
            "name": {"color": 8},
            'programname': {'color': 'cyan'},
            "programname": {"color": "cyan"},
            'username': {'color': 'yellow'},
            "username": {"color": "yellow"},
        }
        }
        coloredlogs.install(level=log_level, level_styles=level_styles, field_styles=field_styles, fmt=LOG_FORMAT_DEBUG)
        coloredlogs.install(
            level=log_level,
            level_styles=level_styles,
            field_styles=field_styles,
            fmt=LOG_FORMAT_DEBUG,
        )
    else:
    else:
        logging.basicConfig(level=logging.getLevelName(log_level), format=LOG_FORMAT_DEBUG)
        logging.basicConfig(level=logging.getLevelName(log_level), format=LOG_FORMAT_DEBUG)




searx_debug = settings['general']['debug']
searx_debug = settings["general"]["debug"]
if searx_debug:
if searx_debug:
    logging_config_debug()
    logging_config_debug()
else:
else:
    logging.basicConfig(level=LOG_LEVEL_PROD, format=LOG_FORMAT_PROD)
    logging.basicConfig(level=LOG_LEVEL_PROD, format=LOG_FORMAT_PROD)
    logging.root.setLevel(level=LOG_LEVEL_PROD)
    logging.root.setLevel(level=LOG_LEVEL_PROD)
    logging.getLogger('werkzeug').setLevel(level=LOG_LEVEL_PROD)
    logging.getLogger("werkzeug").setLevel(level=LOG_LEVEL_PROD)
logger = logging.getLogger('searx')
logger = logging.getLogger("searx")
logger.info(settings_load_message)
logger.info(settings_load_message)


# log max_request_timeout
# log max_request_timeout
max_request_timeout = settings['outgoing']['max_request_timeout']
max_request_timeout = settings["outgoing"]["max_request_timeout"]
if max_request_timeout is None:
if max_request_timeout is None:
    logger.info('max_request_timeout=%s', repr(max_request_timeout))
    logger.info("max_request_timeout=%s", repr(max_request_timeout))
else:
else:
    logger.info('max_request_timeout=%i second(s)', max_request_timeout)
    logger.info("max_request_timeout=%i second(s)", max_request_timeout)
+3 −3
Original line number Original line Diff line number Diff line
@@ -10,10 +10,10 @@ answerers_dir = dirname(realpath(__file__))
def load_answerers():
def load_answerers():
    answerers = []
    answerers = []
    for filename in listdir(answerers_dir):
    for filename in listdir(answerers_dir):
        if not isdir(join(answerers_dir, filename)) or filename.startswith('_'):
        if not isdir(join(answerers_dir, filename)) or filename.startswith("_"):
            continue
            continue
        module = load_module('answerer.py', join(answerers_dir, filename))
        module = load_module("answerer.py", join(answerers_dir, filename))
        if not hasattr(module, 'keywords') or not isinstance(module.keywords, tuple) or not len(module.keywords):
        if not hasattr(module, "keywords") or not isinstance(module.keywords, tuple) or not len(module.keywords):
            exit(2)
            exit(2)
        answerers.append(module)
        answerers.append(module)
    return answerers
    return answerers
+12 −12
Original line number Original line Diff line number Diff line
@@ -6,7 +6,7 @@ from flask_babel import gettext


# required answerer attribute
# required answerer attribute
# specifies which search query keywords triggers this answerer
# specifies which search query keywords triggers this answerer
keywords = ('random',)
keywords = ("random",)


random_int_max = 2**31
random_int_max = 2**31
random_string_letters = string.ascii_lowercase + string.digits + string.ascii_uppercase
random_string_letters = string.ascii_lowercase + string.digits + string.ascii_uppercase
@@ -17,7 +17,7 @@ def random_characters():




def random_string():
def random_string():
    return ''.join(random_characters())
    return "".join(random_characters())




def random_float():
def random_float():
@@ -30,7 +30,7 @@ def random_int():


def random_sha256():
def random_sha256():
    m = hashlib.sha256()
    m = hashlib.sha256()
    m.update(''.join(random_characters()).encode())
    m.update("".join(random_characters()).encode())
    return str(m.hexdigest())
    return str(m.hexdigest())




@@ -39,11 +39,11 @@ def random_uuid():




random_types = {
random_types = {
    'string': random_string,
    "string": random_string,
    'int': random_int,
    "int": random_int,
    'float': random_float,
    "float": random_float,
    'sha256': random_sha256,
    "sha256": random_sha256,
    'uuid': random_uuid,
    "uuid": random_uuid,
}
}




@@ -57,14 +57,14 @@ def answer(query):
    if parts[1] not in random_types:
    if parts[1] not in random_types:
        return []
        return []


    return [{'answer': random_types[parts[1]]()}]
    return [{"answer": random_types[parts[1]]()}]




# required answerer function
# required answerer function
# returns information about the answerer
# returns information about the answerer
def self_info():
def self_info():
    return {
    return {
        'name': gettext('Random value generator'),
        "name": gettext("Random value generator"),
        'description': gettext('Generate different random values'),
        "description": gettext("Generate different random values"),
        'examples': ['random {}'.format(x) for x in random_types],
        "examples": ["random {}".format(x) for x in random_types],
    }
    }
Loading