ValueList fixes

This commit is contained in:
Florian Bruhin 2014-04-07 17:05:51 +02:00
parent 7312a284a3
commit 50740b2828
4 changed files with 45 additions and 46 deletions

View File

@ -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('#')

View File

@ -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

View File

@ -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.

View File

@ -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):