Merge None{Int,String} with Int/String conftype

This commit is contained in:
Florian Bruhin 2014-05-06 13:00:49 +02:00
parent a0e71dc86e
commit cbc363912e
2 changed files with 31 additions and 43 deletions

View File

@ -155,14 +155,22 @@ class String(BaseType):
Attributes:
minlen: Minimum length (inclusive).
maxlen: Maximum length (inclusive).
forbidden: Forbidden chars in the string.
none: Whether to convert to None for an empty string.
"""
typestr = 'string'
def __init__(self, minlen=None, maxlen=None, forbidden=None):
def __init__(self, minlen=None, maxlen=None, forbidden=None, none=False):
self.minlen = minlen
self.maxlen = maxlen
self.forbidden = forbidden
self.none = none
def transform(self, value):
if self.none and not value:
return None
return value
def validate(self, value):
if self.forbidden is not None and any(c in value
@ -177,16 +185,6 @@ class String(BaseType):
self.maxlen))
class NoneString(String):
"""String which returns None if it's empty."""
def transform(self, value):
if not value:
return None
return super().transform(value)
class ShellCommand(String):
"""A shellcommand which is split via shlex.
@ -252,18 +250,24 @@ class Int(BaseType):
Attributes:
minval: Minimum value (inclusive).
maxval: Maximum value (inclusive).
none: Whether to accept empty values as None.
"""
typestr = 'int'
def __init__(self, minval=None, maxval=None):
def __init__(self, minval=None, maxval=None, none=False):
self.minval = minval
self.maxval = maxval
self.none = none
def transform(self, value):
if self.none and not value:
return None
return int(value)
def validate(self, value):
if self.none and not value:
return
try:
intval = int(value)
except ValueError:
@ -276,22 +280,6 @@ class Int(BaseType):
self.maxval))
class NoneInt(BaseType):
"""Int or None."""
def transform(self, value):
if value == '':
return None
else:
return super().transform(value)
def validate(self, value):
if value == '':
return
super().validate(value)
class Float(BaseType):
"""Base class for an float setting.

View File

@ -203,11 +203,11 @@ DATA = OrderedDict([
"Value to send in the DNT header."),
('accept-language',
SettingValue(types.NoneString(), 'en-US,en'),
SettingValue(types.String(none=True), 'en-US,en'),
"Value to send in the accept-language header."),
('user-agent',
SettingValue(types.NoneString(), ''),
SettingValue(types.String(none=True), ''),
"User agent to send. Empty to send the default."),
('accept-cookies',
@ -422,55 +422,55 @@ DATA = OrderedDict([
"User stylesheet to set."),
('css-media-type',
SettingValue(types.NoneString(), ''),
SettingValue(types.String(none=True), ''),
"Set the CSS media type."),
('default-encoding',
SettingValue(types.NoneString(), ''),
SettingValue(types.String(none=True), ''),
"Default encoding to use for websites."),
('font-family-standard',
SettingValue(types.NoneString(), ''),
SettingValue(types.String(none=True), ''),
"Font family for standard fonts."),
('font-family-fixed',
SettingValue(types.NoneString(), ''),
SettingValue(types.String(none=True), ''),
"Font family for fixed fonts."),
('font-family-serif',
SettingValue(types.NoneString(), ''),
SettingValue(types.String(none=True), ''),
"Font family for serif fonts."),
('font-family-sans-serif',
SettingValue(types.NoneString(), ''),
SettingValue(types.String(none=True), ''),
"Font family for sans-serif fonts."),
('font-family-cursive',
SettingValue(types.NoneString(), ''),
SettingValue(types.String(none=True), ''),
"Font family for cursive fonts."),
('font-family-fantasy',
SettingValue(types.NoneString(), ''),
SettingValue(types.String(none=True), ''),
"Font family for fantasy fonts."),
('font-size-minimum',
SettingValue(types.NoneString(), ''),
SettingValue(types.String(none=True), ''),
"The hard minimum font size."),
('font-size-minimum-logical',
SettingValue(types.NoneString(), ''),
SettingValue(types.String(none=True), ''),
"The minimum logical font size that is applied when zooming out."),
('font-size-default',
SettingValue(types.NoneString(), ''),
SettingValue(types.String(none=True), ''),
"The default font size for regular text."),
('font-size-default-fixed',
SettingValue(types.NoneString(), ''),
SettingValue(types.String(none=True), ''),
"The default font size for fixed-pitch text."),
('maximum-pages-in-cache',
SettingValue(types.NoneInt(), ''),
SettingValue(types.Int(none=True), ''),
"The default font size for fixed-pitch text."),
('object-cache-capacities',