From 50740b2828a453076ddd279d311bf3d90d74c732 Mon Sep 17 00:00:00 2001 From: Florian Bruhin Date: Mon, 7 Apr 2014 17:05:51 +0200 Subject: [PATCH] ValueList fixes --- qutebrowser/config/config.py | 2 +- qutebrowser/config/configdata.py | 42 +------------------------------- qutebrowser/config/conftypes.py | 41 +++++++++++++++++++++++++++++++ qutebrowser/config/sections.py | 6 ++--- 4 files changed, 45 insertions(+), 46 deletions(-) diff --git a/qutebrowser/config/config.py b/qutebrowser/config/config.py index da6fc2cc1..d98119ea5 100644 --- a/qutebrowser/config/config.py +++ b/qutebrowser/config/config.py @@ -125,7 +125,7 @@ class Config: subsequent_indent='#' + ' ' * 5, **self._wrapper_args) lines = [] - if not section.descriptions: + if not getattr(section, 'descriptions', None): return lines for optname, option in section.items(): lines.append('#') diff --git a/qutebrowser/config/configdata.py b/qutebrowser/config/configdata.py index f4bf5a802..28695666d 100644 --- a/qutebrowser/config/configdata.py +++ b/qutebrowser/config/configdata.py @@ -19,6 +19,7 @@ from collections import OrderedDict +from qutebrowser.config.conftypes import SettingValue import qutebrowser.config.conftypes as types import qutebrowser.config.sections as sect @@ -293,44 +294,3 @@ def configdata(): )), ]) - - -class SettingValue: - - """Base class for setting values. - - Intended to be subclassed by config value "types". - - Attributes: - typ: A BaseType subclass. - default: Default value if the user has not overridden it, as a string. - value: (property) The currently valid, most important value. - rawvalue: The current value as a raw string. - - """ - - def __init__(self, typ, default): - """Constructor. - - Args: - typ: The BaseType to use. - default: Raw value to set. - - """ - self.typ = typ() - self.rawvalue = None - self.default = default - - def __str__(self): - """Get raw string value.""" - return self.value - - def transformed(self): - """Get the transformed value.""" - v = self.value - return self.typ.transform(v) - - @property - def value(self): - """Get the currently valid value.""" - return self.rawvalue if self.rawvalue is not None else self.default diff --git a/qutebrowser/config/conftypes.py b/qutebrowser/config/conftypes.py index 0a48d121f..823a5c15c 100644 --- a/qutebrowser/config/conftypes.py +++ b/qutebrowser/config/conftypes.py @@ -56,6 +56,47 @@ class ValidValues: return self.values.__iter__() +class SettingValue: + + """Base class for setting values. + + Intended to be subclassed by config value "types". + + Attributes: + typ: A BaseType subclass. + default: Default value if the user has not overridden it, as a string. + value: (property) The currently valid, most important value. + rawvalue: The current value as a raw string. + + """ + + def __init__(self, typ, default): + """Constructor. + + Args: + typ: The BaseType to use. + default: Raw value to set. + + """ + self.typ = typ() + self.rawvalue = None + self.default = default + + def __str__(self): + """Get raw string value.""" + return self.value + + def transformed(self): + """Get the transformed value.""" + v = self.value + return self.typ.transform(v) + + @property + def value(self): + """Get the currently valid value.""" + return self.rawvalue if self.rawvalue is not None else self.default + + class BaseType: """A type used for a setting value. diff --git a/qutebrowser/config/sections.py b/qutebrowser/config/sections.py index 477dfb14e..83936ec4d 100644 --- a/qutebrowser/config/sections.py +++ b/qutebrowser/config/sections.py @@ -125,10 +125,8 @@ class ValueList: def __init__(self): """Wrap types over default values. Take care when overriding this.""" self.values = OrderedDict() - keytype = self.types[0]() - valtype = self.types[1]() self.default = OrderedDict( - [(keytype.transform(key), valtype.transform(value)) + [(key, conftypes.SettingValue(self.types[1], value)) for key, value in self.default.items()]) self.valdict = OrderedDict() @@ -177,7 +175,7 @@ class ValueList: for k, v in sect.items(): keytype.validate(k) valtype.validate(v) - self.values[keytype.transform(k)] = valtype.transform(v) + self.values[k] = conftypes.SettingValue(self.types[1], v) class SearchEngines(ValueList):