Merge None{Int,String} with Int/String conftype
This commit is contained in:
parent
a0e71dc86e
commit
cbc363912e
@ -155,14 +155,22 @@ class String(BaseType):
|
|||||||
Attributes:
|
Attributes:
|
||||||
minlen: Minimum length (inclusive).
|
minlen: Minimum length (inclusive).
|
||||||
maxlen: Maximum length (inclusive).
|
maxlen: Maximum length (inclusive).
|
||||||
|
forbidden: Forbidden chars in the string.
|
||||||
|
none: Whether to convert to None for an empty string.
|
||||||
"""
|
"""
|
||||||
|
|
||||||
typestr = '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.minlen = minlen
|
||||||
self.maxlen = maxlen
|
self.maxlen = maxlen
|
||||||
self.forbidden = forbidden
|
self.forbidden = forbidden
|
||||||
|
self.none = none
|
||||||
|
|
||||||
|
def transform(self, value):
|
||||||
|
if self.none and not value:
|
||||||
|
return None
|
||||||
|
return value
|
||||||
|
|
||||||
def validate(self, value):
|
def validate(self, value):
|
||||||
if self.forbidden is not None and any(c in value
|
if self.forbidden is not None and any(c in value
|
||||||
@ -177,16 +185,6 @@ class String(BaseType):
|
|||||||
self.maxlen))
|
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):
|
class ShellCommand(String):
|
||||||
|
|
||||||
"""A shellcommand which is split via shlex.
|
"""A shellcommand which is split via shlex.
|
||||||
@ -252,18 +250,24 @@ class Int(BaseType):
|
|||||||
Attributes:
|
Attributes:
|
||||||
minval: Minimum value (inclusive).
|
minval: Minimum value (inclusive).
|
||||||
maxval: Maximum value (inclusive).
|
maxval: Maximum value (inclusive).
|
||||||
|
none: Whether to accept empty values as None.
|
||||||
"""
|
"""
|
||||||
|
|
||||||
typestr = 'int'
|
typestr = 'int'
|
||||||
|
|
||||||
def __init__(self, minval=None, maxval=None):
|
def __init__(self, minval=None, maxval=None, none=False):
|
||||||
self.minval = minval
|
self.minval = minval
|
||||||
self.maxval = maxval
|
self.maxval = maxval
|
||||||
|
self.none = none
|
||||||
|
|
||||||
def transform(self, value):
|
def transform(self, value):
|
||||||
|
if self.none and not value:
|
||||||
|
return None
|
||||||
return int(value)
|
return int(value)
|
||||||
|
|
||||||
def validate(self, value):
|
def validate(self, value):
|
||||||
|
if self.none and not value:
|
||||||
|
return
|
||||||
try:
|
try:
|
||||||
intval = int(value)
|
intval = int(value)
|
||||||
except ValueError:
|
except ValueError:
|
||||||
@ -276,22 +280,6 @@ class Int(BaseType):
|
|||||||
self.maxval))
|
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):
|
class Float(BaseType):
|
||||||
|
|
||||||
"""Base class for an float setting.
|
"""Base class for an float setting.
|
||||||
|
@ -203,11 +203,11 @@ DATA = OrderedDict([
|
|||||||
"Value to send in the DNT header."),
|
"Value to send in the DNT header."),
|
||||||
|
|
||||||
('accept-language',
|
('accept-language',
|
||||||
SettingValue(types.NoneString(), 'en-US,en'),
|
SettingValue(types.String(none=True), 'en-US,en'),
|
||||||
"Value to send in the accept-language header."),
|
"Value to send in the accept-language header."),
|
||||||
|
|
||||||
('user-agent',
|
('user-agent',
|
||||||
SettingValue(types.NoneString(), ''),
|
SettingValue(types.String(none=True), ''),
|
||||||
"User agent to send. Empty to send the default."),
|
"User agent to send. Empty to send the default."),
|
||||||
|
|
||||||
('accept-cookies',
|
('accept-cookies',
|
||||||
@ -422,55 +422,55 @@ DATA = OrderedDict([
|
|||||||
"User stylesheet to set."),
|
"User stylesheet to set."),
|
||||||
|
|
||||||
('css-media-type',
|
('css-media-type',
|
||||||
SettingValue(types.NoneString(), ''),
|
SettingValue(types.String(none=True), ''),
|
||||||
"Set the CSS media type."),
|
"Set the CSS media type."),
|
||||||
|
|
||||||
('default-encoding',
|
('default-encoding',
|
||||||
SettingValue(types.NoneString(), ''),
|
SettingValue(types.String(none=True), ''),
|
||||||
"Default encoding to use for websites."),
|
"Default encoding to use for websites."),
|
||||||
|
|
||||||
('font-family-standard',
|
('font-family-standard',
|
||||||
SettingValue(types.NoneString(), ''),
|
SettingValue(types.String(none=True), ''),
|
||||||
"Font family for standard fonts."),
|
"Font family for standard fonts."),
|
||||||
|
|
||||||
('font-family-fixed',
|
('font-family-fixed',
|
||||||
SettingValue(types.NoneString(), ''),
|
SettingValue(types.String(none=True), ''),
|
||||||
"Font family for fixed fonts."),
|
"Font family for fixed fonts."),
|
||||||
|
|
||||||
('font-family-serif',
|
('font-family-serif',
|
||||||
SettingValue(types.NoneString(), ''),
|
SettingValue(types.String(none=True), ''),
|
||||||
"Font family for serif fonts."),
|
"Font family for serif fonts."),
|
||||||
|
|
||||||
('font-family-sans-serif',
|
('font-family-sans-serif',
|
||||||
SettingValue(types.NoneString(), ''),
|
SettingValue(types.String(none=True), ''),
|
||||||
"Font family for sans-serif fonts."),
|
"Font family for sans-serif fonts."),
|
||||||
|
|
||||||
('font-family-cursive',
|
('font-family-cursive',
|
||||||
SettingValue(types.NoneString(), ''),
|
SettingValue(types.String(none=True), ''),
|
||||||
"Font family for cursive fonts."),
|
"Font family for cursive fonts."),
|
||||||
|
|
||||||
('font-family-fantasy',
|
('font-family-fantasy',
|
||||||
SettingValue(types.NoneString(), ''),
|
SettingValue(types.String(none=True), ''),
|
||||||
"Font family for fantasy fonts."),
|
"Font family for fantasy fonts."),
|
||||||
|
|
||||||
('font-size-minimum',
|
('font-size-minimum',
|
||||||
SettingValue(types.NoneString(), ''),
|
SettingValue(types.String(none=True), ''),
|
||||||
"The hard minimum font size."),
|
"The hard minimum font size."),
|
||||||
|
|
||||||
('font-size-minimum-logical',
|
('font-size-minimum-logical',
|
||||||
SettingValue(types.NoneString(), ''),
|
SettingValue(types.String(none=True), ''),
|
||||||
"The minimum logical font size that is applied when zooming out."),
|
"The minimum logical font size that is applied when zooming out."),
|
||||||
|
|
||||||
('font-size-default',
|
('font-size-default',
|
||||||
SettingValue(types.NoneString(), ''),
|
SettingValue(types.String(none=True), ''),
|
||||||
"The default font size for regular text."),
|
"The default font size for regular text."),
|
||||||
|
|
||||||
('font-size-default-fixed',
|
('font-size-default-fixed',
|
||||||
SettingValue(types.NoneString(), ''),
|
SettingValue(types.String(none=True), ''),
|
||||||
"The default font size for fixed-pitch text."),
|
"The default font size for fixed-pitch text."),
|
||||||
|
|
||||||
('maximum-pages-in-cache',
|
('maximum-pages-in-cache',
|
||||||
SettingValue(types.NoneInt(), ''),
|
SettingValue(types.Int(none=True), ''),
|
||||||
"The default font size for fixed-pitch text."),
|
"The default font size for fixed-pitch text."),
|
||||||
|
|
||||||
('object-cache-capacities',
|
('object-cache-capacities',
|
||||||
|
Loading…
Reference in New Issue
Block a user