Implement __str__ for Config, delete unneeded __str__'s
This commit is contained in:
parent
98d15de460
commit
b2b23e032a
@ -123,6 +123,16 @@ class NewConfig:
|
||||
"""Get a section from the config."""
|
||||
return self.config[key]
|
||||
|
||||
def __str__(self):
|
||||
"""Get the whole config as a string."""
|
||||
# FIXME this should also generate nice comments
|
||||
lines = []
|
||||
for secname, section in self.config.items():
|
||||
lines.append('[{}]'.format(secname))
|
||||
for optname, option in section.items():
|
||||
lines.append('{} = {}'.format(optname, option))
|
||||
return '\n'.join(lines)
|
||||
|
||||
def get(self, section, option, fallback=_UNSET):
|
||||
"""Get the real (transformed) value from a section/option."""
|
||||
try:
|
||||
|
@ -49,13 +49,6 @@ class KeyValue:
|
||||
if args:
|
||||
self.values = OrderedDict(args)
|
||||
|
||||
def __str__(self):
|
||||
"""Get the key = value pairs as a string."""
|
||||
# FIXME implement that in some toini() method
|
||||
#return '\n'.join('{} = {}'.format(key, val.rawvalue)
|
||||
# for key, val in self.values.items())
|
||||
return str(self.values)
|
||||
|
||||
def __getitem__(self, key):
|
||||
"""Get the value for key.
|
||||
|
||||
@ -83,6 +76,10 @@ class KeyValue:
|
||||
# FIXME using a custon iterator this could be done more efficiently
|
||||
return self.values.__iter__()
|
||||
|
||||
def items(self):
|
||||
"""Get dict item tuples."""
|
||||
return self.values.items()
|
||||
|
||||
|
||||
class SearchEngines(template.ValueListSection):
|
||||
|
||||
|
@ -61,7 +61,11 @@ class SettingValue:
|
||||
|
||||
def __str__(self):
|
||||
"""Get raw string value."""
|
||||
return self.rawvalue if self.rawvalue is not None else ''
|
||||
if self.rawvalue is not None:
|
||||
val = self.rawvalue
|
||||
else:
|
||||
val = self.default
|
||||
return val
|
||||
|
||||
@property
|
||||
def value(self):
|
||||
@ -254,11 +258,6 @@ class ValueListSection:
|
||||
self.default = {self.types[0](key): self.types[1](value)
|
||||
for key, value in self.default.items()}
|
||||
|
||||
def __str__(self):
|
||||
"""Get the key = value pairs as a string."""
|
||||
return '\n'.join('{} = {}'.format(key.rawvalue, val.rawvalue)
|
||||
for key, val in self.values)
|
||||
|
||||
def __getitem__(self, key):
|
||||
"""Get the value for key.
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user