diff options
| author | Alexandre Flament <alex@al-f.net> | 2021-07-21 14:27:49 +0200 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2021-07-21 14:27:49 +0200 |
| commit | 4f0d232a3dc95042be809d6fa6e93ca746156658 (patch) | |
| tree | 4155de82568afd651558cb91a5d59aa256577a19 /searx/__init__.py | |
| parent | 17e028e57928f7925a2d1ee1177d28ff33ff8487 (diff) | |
| parent | 19abaf272def8faee5e7d3652d95413c3256d638 (diff) | |
Merge pull request #213 from return42/drop-brand
[mod] drop searx.brand namespace
Diffstat (limited to 'searx/__init__.py')
| -rw-r--r-- | searx/__init__.py | 70 |
1 files changed, 21 insertions, 49 deletions
diff --git a/searx/__init__.py b/searx/__init__.py index 8452dd7b4..0b73d5204 100644 --- a/searx/__init__.py +++ b/searx/__init__.py @@ -32,52 +32,24 @@ if max_request_timeout is None: else: logger.info('max_request_timeout=%i second(s)', max_request_timeout) - -class _brand_namespace: # pylint: disable=invalid-name - - @classmethod - def get_val(cls, group, name, default=''): - return settings.get(group, {}).get(name) or default - - @property - def SEARX_URL(self): - return self.get_val('server', 'base_url') - - @property - def CONTACT_URL(self): - return self.get_val('general', 'contact_url') - - @property - def GIT_URL(self): - return self.get_val('brand', 'git_url') - - @property - def GIT_BRANCH(self): - return self.get_val('brand', 'git_branch') - - @property - def ISSUE_URL(self): - return self.get_val('brand', 'issue_url') - - @property - def NEW_ISSUE_URL(self): - return self.get_val('brand', 'new_issue_url') - - @property - def DOCS_URL(self): - return self.get_val('brand', 'docs_url') - - @property - def PUBLIC_INSTANCES(self): - return self.get_val('brand', 'public_instances') - - @property - def WIKI_URL(self): - return self.get_val('brand', 'wiki_url') - - @property - def TWITTER_URL(self): - return self.get_val('brand', 'twitter_url') - - -brand = _brand_namespace() +_unset = object() + +def get_setting(name, default=_unset): + """Returns the value to which ``name`` point. If there is no such name in the + settings and the ``default`` is unset, a :py:obj:`KeyError` is raised. + + """ + value = settings + for a in name.split('.'): + if isinstance(value, dict): + value = value.get(a, _unset) + else: + value = _unset + + if value is _unset: + if default is _unset: + raise KeyError(name) + value = default + break + + return value |