Remove fallback values from config
This commit is contained in:
parent
c5ca0e56be
commit
175eabdc80
@ -64,9 +64,9 @@ class SearchParser(QObject):
|
||||
self.do_search.emit('', 0)
|
||||
self._text = text
|
||||
self._flags = 0
|
||||
if config.config.get('general', 'ignorecase', fallback=True):
|
||||
if config.config.get('general', 'ignorecase'):
|
||||
self._flags |= QWebPage.FindCaseSensitively
|
||||
if config.config.get('general', 'wrapsearch', fallback=True):
|
||||
if config.config.get('general', 'wrapsearch'):
|
||||
self._flags |= QWebPage.FindWrapsAroundDocument
|
||||
if rev:
|
||||
self._flags |= QWebPage.FindBackward
|
||||
|
@ -39,9 +39,6 @@ from qutebrowser.config.conftypes import ValidationError
|
||||
config = None
|
||||
state = None
|
||||
|
||||
# Special value for an unset fallback, so None can be passed as fallback.
|
||||
_UNSET = object()
|
||||
|
||||
|
||||
class NoSectionError(configparser.NoSectionError):
|
||||
|
||||
@ -225,30 +222,23 @@ class Config:
|
||||
val = self.get(section, option)
|
||||
message.info("{} {} = {}".format(section, option, val))
|
||||
|
||||
def get(self, section, option, fallback=_UNSET, raw=False):
|
||||
def get(self, section, option, raw=False):
|
||||
"""Get the value from a section/option.
|
||||
|
||||
Arguments:
|
||||
section: The section to get the option from.
|
||||
option: The option name
|
||||
fallback: A fallback value.
|
||||
raw: Whether to get the uninterpolated, untransformed value.
|
||||
"""
|
||||
logging.debug("getting {} -> {}".format(section, option))
|
||||
try:
|
||||
sect = self.config[section]
|
||||
except KeyError:
|
||||
if fallback is _UNSET:
|
||||
raise NoSectionError(section)
|
||||
else:
|
||||
return fallback
|
||||
try:
|
||||
val = sect[option]
|
||||
except KeyError:
|
||||
if fallback is _UNSET:
|
||||
raise NoOptionError(option, section)
|
||||
else:
|
||||
return fallback
|
||||
if raw:
|
||||
return val.value
|
||||
mapping = {key: val.value for key, val in sect.values.items()}
|
||||
@ -409,15 +399,18 @@ class SectionProxy(MutableMapping):
|
||||
"""Get the option keys from this section."""
|
||||
return self._conf.config[self._name].values.keys()
|
||||
|
||||
def get(self, option, fallback=_UNSET, *, raw=False):
|
||||
def get(self, option, *, raw=False):
|
||||
"""Get a value from this section.
|
||||
|
||||
We deliberately don't support the default argument here, but have a raw
|
||||
argument instead.
|
||||
|
||||
Arguments:
|
||||
option: The option name to get.
|
||||
fallback: A fallback value.
|
||||
raw: Whether to get a raw value or not.
|
||||
"""
|
||||
return self._conf.get(self._name, option, raw=raw, fallback=fallback)
|
||||
# pylint: disable=arguments-differ
|
||||
return self._conf.get(self._name, option, raw=raw)
|
||||
|
||||
@property
|
||||
def conf(self):
|
||||
|
@ -27,6 +27,13 @@ from PyQt5.QtCore import QUrl
|
||||
import qutebrowser.config.config as config
|
||||
|
||||
|
||||
class SearchEngineError(Exception):
|
||||
|
||||
"""Exception raised when a search engine wasn't found."""
|
||||
|
||||
pass
|
||||
|
||||
|
||||
def _get_search_url(txt):
|
||||
"""Get a search engine URL for a text.
|
||||
|
||||
@ -37,26 +44,26 @@ def _get_search_url(txt):
|
||||
The search URL as a QUrl.
|
||||
|
||||
Raise:
|
||||
ValueError if there is no template or no search term was found.
|
||||
SearchEngineError if there is no template or no search term was found.
|
||||
"""
|
||||
logging.debug('Finding search engine for "{}"'.format(txt))
|
||||
r = re.compile(r'(^|\s+)!(\w+)($|\s+)')
|
||||
m = r.search(txt)
|
||||
if m:
|
||||
engine = m.group(2)
|
||||
# FIXME why doesn't fallback work?!
|
||||
template = config.config.get('searchengines', engine, fallback=None)
|
||||
try:
|
||||
template = config.config.get('searchengines', engine)
|
||||
except config.NoOptionError:
|
||||
raise SearchEngineError("Search engine {} not found!".format(
|
||||
engine))
|
||||
term = r.sub('', txt)
|
||||
logging.debug('engine {}, term "{}"'.format(engine, term))
|
||||
else:
|
||||
template = config.config.get('searchengines', 'DEFAULT',
|
||||
fallback=None)
|
||||
template = config.config.get('searchengines', 'DEFAULT')
|
||||
term = txt
|
||||
logging.debug('engine: default, term "{}"'.format(txt))
|
||||
if template is None:
|
||||
raise ValueError("Search template is None")
|
||||
if not term:
|
||||
raise ValueError("No search term given")
|
||||
raise SearchEngineError("No search term given")
|
||||
return QUrl.fromUserInput(template.format(urllib.parse.quote(term)))
|
||||
|
||||
|
||||
|
@ -26,6 +26,7 @@ from PyQt5.QtWebKitWidgets import QWebView, QWebPage
|
||||
|
||||
import qutebrowser.utils.url as urlutils
|
||||
import qutebrowser.config.config as config
|
||||
import qutebrowser.utils.message as message
|
||||
from qutebrowser.widgets.browserpage import BrowserPage
|
||||
from qutebrowser.utils.signals import SignalCache
|
||||
from qutebrowser.utils.usertypes import NeighborList
|
||||
@ -93,7 +94,11 @@ class BrowserTab(QWebView):
|
||||
Emit:
|
||||
titleChanged and urlChanged
|
||||
"""
|
||||
try:
|
||||
u = urlutils.fuzzy_url(url)
|
||||
except urlutils.SearchEngineError as e:
|
||||
message.error(str(e))
|
||||
return
|
||||
logging.debug('New title: {}'.format(urlutils.urlstring(u)))
|
||||
self.titleChanged.emit(urlutils.urlstring(u))
|
||||
self.urlChanged.emit(urlutils.qurl(u))
|
||||
|
Loading…
Reference in New Issue
Block a user