Replace List with BaseList and rename GenList to List
This commit is contained in:
parent
d77145a5b8
commit
9e86933913
@ -135,7 +135,7 @@ def data(readonly=False):
|
|||||||
"Whether to find text on a page case-insensitively."),
|
"Whether to find text on a page case-insensitively."),
|
||||||
|
|
||||||
('startpage',
|
('startpage',
|
||||||
SettingValue(typ.List(), 'https://duckduckgo.com'),
|
SettingValue(typ.BaseList(), 'https://duckduckgo.com'),
|
||||||
"The default page(s) to open at the start, separated by commas."),
|
"The default page(s) to open at the start, separated by commas."),
|
||||||
|
|
||||||
('default-page',
|
('default-page',
|
||||||
@ -352,7 +352,7 @@ def data(readonly=False):
|
|||||||
"(requires restart)"),
|
"(requires restart)"),
|
||||||
|
|
||||||
('keyhint-blacklist',
|
('keyhint-blacklist',
|
||||||
SettingValue(typ.List(none_ok=True), ''),
|
SettingValue(typ.BaseList(none_ok=True), ''),
|
||||||
"Keychains that shouldn't be shown in the keyhint dialog\n\n"
|
"Keychains that shouldn't be shown in the keyhint dialog\n\n"
|
||||||
"Globs are supported, so ';*' will blacklist all keychains"
|
"Globs are supported, so ';*' will blacklist all keychains"
|
||||||
"starting with ';'. Use '*' to disable keyhints"),
|
"starting with ';'. Use '*' to disable keyhints"),
|
||||||
@ -845,7 +845,7 @@ def data(readonly=False):
|
|||||||
"Whether host blocking is enabled."),
|
"Whether host blocking is enabled."),
|
||||||
|
|
||||||
('host-blocking-whitelist',
|
('host-blocking-whitelist',
|
||||||
SettingValue(typ.List(none_ok=True), 'piwik.org'),
|
SettingValue(typ.BaseList(none_ok=True), 'piwik.org'),
|
||||||
"List of domains that should always be loaded, despite being "
|
"List of domains that should always be loaded, despite being "
|
||||||
"ad-blocked.\n\n"
|
"ad-blocked.\n\n"
|
||||||
"Domains may contain * and ? wildcards and are otherwise "
|
"Domains may contain * and ? wildcards and are otherwise "
|
||||||
|
@ -299,7 +299,7 @@ class UniqueCharString(String):
|
|||||||
value, "String contains duplicate values!")
|
value, "String contains duplicate values!")
|
||||||
|
|
||||||
|
|
||||||
class GenList(BaseType):
|
class List(BaseType):
|
||||||
|
|
||||||
"""Base class for a (string-)list setting."""
|
"""Base class for a (string-)list setting."""
|
||||||
|
|
||||||
@ -311,19 +311,20 @@ class GenList(BaseType):
|
|||||||
if not value:
|
if not value:
|
||||||
return None
|
return None
|
||||||
else:
|
else:
|
||||||
return [self.inner_type.transform(v) for v in value.split(',')]
|
return [self.inner_type.transform(v.strip())
|
||||||
|
for v in value.split(',')]
|
||||||
|
|
||||||
def validate(self, value):
|
def validate(self, value):
|
||||||
self._basic_validation(value)
|
self._basic_validation(value)
|
||||||
if not value:
|
if not value:
|
||||||
return
|
return
|
||||||
for val in value.split(','):
|
for val in value.split(','):
|
||||||
self.inner_type.validate(val)
|
self.inner_type.validate(val.strip())
|
||||||
|
|
||||||
|
|
||||||
class List(GenList):
|
class BaseList(List):
|
||||||
|
|
||||||
"""Base class for a (string-)list setting."""
|
"""Base class for a list using BaseType."""
|
||||||
|
|
||||||
def __init__(self, none_ok=False, valid_values=None):
|
def __init__(self, none_ok=False, valid_values=None):
|
||||||
super().__init__(BaseType(), none_ok)
|
super().__init__(BaseType(), none_ok)
|
||||||
@ -334,13 +335,9 @@ class List(GenList):
|
|||||||
super().validate(value)
|
super().validate(value)
|
||||||
else:
|
else:
|
||||||
self._basic_validation(value)
|
self._basic_validation(value)
|
||||||
if value:
|
|
||||||
vals = super().transform(value)
|
|
||||||
if None in vals:
|
|
||||||
raise configexc.ValidationError(value, "may not be empty!")
|
|
||||||
|
|
||||||
|
|
||||||
class FlagList(GenList):
|
class FlagList(BaseList):
|
||||||
|
|
||||||
"""Base class for a list setting that contains one or more flags.
|
"""Base class for a list setting that contains one or more flags.
|
||||||
|
|
||||||
@ -348,17 +345,10 @@ class FlagList(GenList):
|
|||||||
self.valid_values (if not empty).
|
self.valid_values (if not empty).
|
||||||
"""
|
"""
|
||||||
|
|
||||||
def __init__(self, none_ok=False, valid_values=None):
|
|
||||||
super().__init__(BaseType(), none_ok)
|
|
||||||
self.inner_type.valid_values = valid_values
|
|
||||||
|
|
||||||
combinable_values = None
|
combinable_values = None
|
||||||
|
|
||||||
def validate(self, value):
|
def validate(self, value):
|
||||||
if self.inner_type.valid_values is not None:
|
super().validate(value)
|
||||||
super().validate(value)
|
|
||||||
else:
|
|
||||||
self._basic_validation(value)
|
|
||||||
if not value:
|
if not value:
|
||||||
return
|
return
|
||||||
vals = super().transform(value)
|
vals = super().transform(value)
|
||||||
@ -471,7 +461,7 @@ class Int(BaseType):
|
|||||||
"smaller!".format(self.maxval))
|
"smaller!".format(self.maxval))
|
||||||
|
|
||||||
|
|
||||||
class IntList(GenList):
|
class IntList(List):
|
||||||
|
|
||||||
"""Base class for an int-list setting."""
|
"""Base class for an int-list setting."""
|
||||||
|
|
||||||
@ -560,7 +550,7 @@ class Perc(BaseType):
|
|||||||
"less!".format(self.maxval))
|
"less!".format(self.maxval))
|
||||||
|
|
||||||
|
|
||||||
class PercList(GenList):
|
class PercList(List):
|
||||||
|
|
||||||
"""Base class for a list of percentages.
|
"""Base class for a list of percentages.
|
||||||
|
|
||||||
@ -855,7 +845,7 @@ class Regex(BaseType):
|
|||||||
return re.compile(value, self.flags)
|
return re.compile(value, self.flags)
|
||||||
|
|
||||||
|
|
||||||
class RegexList(GenList):
|
class RegexList(List):
|
||||||
|
|
||||||
"""A list of regexes."""
|
"""A list of regexes."""
|
||||||
|
|
||||||
@ -1009,7 +999,7 @@ class WebKitBytes(BaseType):
|
|||||||
return int(val) * multiplicator
|
return int(val) * multiplicator
|
||||||
|
|
||||||
|
|
||||||
class WebKitBytesList(GenList):
|
class WebKitBytesList(List):
|
||||||
|
|
||||||
"""A size with an optional suffix.
|
"""A size with an optional suffix.
|
||||||
|
|
||||||
@ -1361,7 +1351,7 @@ class Url(BaseType):
|
|||||||
"{}".format(val.errorString()))
|
"{}".format(val.errorString()))
|
||||||
|
|
||||||
|
|
||||||
class UrlList(GenList):
|
class UrlList(List):
|
||||||
|
|
||||||
"""A list of URLs."""
|
"""A list of URLs."""
|
||||||
|
|
||||||
|
@ -354,18 +354,31 @@ class TestString:
|
|||||||
assert klass(valid_values=valid_values).complete() == expected
|
assert klass(valid_values=valid_values).complete() == expected
|
||||||
|
|
||||||
|
|
||||||
|
class ListSubclass(configtypes.List):
|
||||||
|
|
||||||
|
"""A subclass of List which we use in tests. Similar to FlagList.
|
||||||
|
|
||||||
|
Valid values are 'foo', 'bar' and 'baz'.
|
||||||
|
"""
|
||||||
|
|
||||||
|
def __init__(self, none_ok_inner=False, none_ok_outer=False):
|
||||||
|
super().__init__(configtypes.BaseType(none_ok_inner), none_ok_outer)
|
||||||
|
self.inner_type.valid_values = configtypes.ValidValues('foo',
|
||||||
|
'bar', 'baz')
|
||||||
|
|
||||||
|
|
||||||
class TestList:
|
class TestList:
|
||||||
|
|
||||||
"""Test List."""
|
"""Test List."""
|
||||||
|
|
||||||
@pytest.fixture
|
@pytest.fixture
|
||||||
def klass(self):
|
def klass(self):
|
||||||
return configtypes.List
|
return ListSubclass
|
||||||
|
|
||||||
@pytest.mark.parametrize('val',
|
@pytest.mark.parametrize('val',
|
||||||
['', 'foo', 'foo,bar', 'foo, bar'])
|
['', 'foo', 'foo,bar', 'foo, bar'])
|
||||||
def test_validate_valid(self, klass, val):
|
def test_validate_valid(self, klass, val):
|
||||||
klass(none_ok=True).validate(val)
|
klass(none_ok_outer=True).validate(val)
|
||||||
|
|
||||||
@pytest.mark.parametrize('val', ['', 'foo,,bar'])
|
@pytest.mark.parametrize('val', ['', 'foo,,bar'])
|
||||||
def test_validate_invalid(self, klass, val):
|
def test_validate_invalid(self, klass, val):
|
||||||
@ -374,14 +387,14 @@ class TestList:
|
|||||||
|
|
||||||
def test_invalid_empty_value_none_ok(self, klass):
|
def test_invalid_empty_value_none_ok(self, klass):
|
||||||
with pytest.raises(configexc.ValidationError):
|
with pytest.raises(configexc.ValidationError):
|
||||||
klass(none_ok=True).validate('foo,,bar')
|
klass(none_ok_outer=True).validate('foo,,bar')
|
||||||
|
klass(none_ok_inner=True).validate('')
|
||||||
|
|
||||||
@pytest.mark.parametrize('val, expected', [
|
@pytest.mark.parametrize('val, expected', [
|
||||||
('foo', ['foo']),
|
('foo', ['foo']),
|
||||||
('foo,bar,baz', ['foo', 'bar', 'baz']),
|
('foo,bar,baz', ['foo', 'bar', 'baz']),
|
||||||
('', None),
|
('', None),
|
||||||
# Not implemented yet
|
('foo, bar', ['foo', 'bar'])
|
||||||
pytest.mark.xfail(('foo, bar', ['foo', 'bar'])),
|
|
||||||
])
|
])
|
||||||
def test_transform(self, klass, val, expected):
|
def test_transform(self, klass, val, expected):
|
||||||
assert klass().transform(val) == expected
|
assert klass().transform(val) == expected
|
||||||
|
@ -36,7 +36,7 @@ def gen_classes():
|
|||||||
pass
|
pass
|
||||||
elif member is configtypes.MappingType:
|
elif member is configtypes.MappingType:
|
||||||
pass
|
pass
|
||||||
elif member is configtypes.GenList:
|
elif member is configtypes.List:
|
||||||
pass
|
pass
|
||||||
elif member is configtypes.FormatString:
|
elif member is configtypes.FormatString:
|
||||||
yield functools.partial(member, fields=['a', 'b'])
|
yield functools.partial(member, fields=['a', 'b'])
|
||||||
|
Loading…
Reference in New Issue
Block a user