From cbc363912e08e3e4a231452431dd95d15c8474fe Mon Sep 17 00:00:00 2001 From: Florian Bruhin Date: Tue, 6 May 2014 13:00:49 +0200 Subject: [PATCH] Merge None{Int,String} with Int/String conftype --- qutebrowser/config/_conftypes.py | 44 ++++++++++++-------------------- qutebrowser/config/configdata.py | 30 +++++++++++----------- 2 files changed, 31 insertions(+), 43 deletions(-) diff --git a/qutebrowser/config/_conftypes.py b/qutebrowser/config/_conftypes.py index 9cf08ef20..04e0b21d5 100644 --- a/qutebrowser/config/_conftypes.py +++ b/qutebrowser/config/_conftypes.py @@ -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. diff --git a/qutebrowser/config/configdata.py b/qutebrowser/config/configdata.py index 68eed8e64..d74113bf4 100644 --- a/qutebrowser/config/configdata.py +++ b/qutebrowser/config/configdata.py @@ -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',