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