configtypes: Add new UrlList type.
This commit is contained in:
parent
142e90cdd3
commit
c29ae9e1d3
@ -1161,6 +1161,34 @@ class Position(BaseType):
|
|||||||
return self.MAPPING[value]
|
return self.MAPPING[value]
|
||||||
|
|
||||||
|
|
||||||
|
class UrlList(List):
|
||||||
|
|
||||||
|
"""A list of URLs."""
|
||||||
|
|
||||||
|
typestr = 'url-list'
|
||||||
|
|
||||||
|
def transform(self, value):
|
||||||
|
if not value:
|
||||||
|
return None
|
||||||
|
else:
|
||||||
|
return [QUrl.fromUserInput(v) if v else None
|
||||||
|
for v in value.split(',')]
|
||||||
|
|
||||||
|
def validate(self, value):
|
||||||
|
if not value:
|
||||||
|
if self._none_ok:
|
||||||
|
return
|
||||||
|
else:
|
||||||
|
raise ValidationError(value, "list may not be empty!")
|
||||||
|
vals = self.transform(value)
|
||||||
|
for val in vals:
|
||||||
|
if val is None:
|
||||||
|
raise ValidationError(value, "values may not be empty!")
|
||||||
|
elif not val.isValid():
|
||||||
|
raise ValidationError(value, "invalid URL - {}".format(
|
||||||
|
val.errorString()))
|
||||||
|
|
||||||
|
|
||||||
class SelectOnRemove(BaseType):
|
class SelectOnRemove(BaseType):
|
||||||
|
|
||||||
"""Which tab to select when the focused tab is removed."""
|
"""Which tab to select when the focused tab is removed."""
|
||||||
|
@ -1896,5 +1896,24 @@ class EncodingTests(unittest.TestCase):
|
|||||||
self.assertIsNone(self.t.transform(''))
|
self.assertIsNone(self.t.transform(''))
|
||||||
|
|
||||||
|
|
||||||
|
class UrlListTests(unittest.TestCase):
|
||||||
|
|
||||||
|
"""Test UrlList."""
|
||||||
|
|
||||||
|
def setUp(self):
|
||||||
|
self.t = configtypes.UrlList()
|
||||||
|
|
||||||
|
def test_transform_single(self):
|
||||||
|
"""Test transform with a single value."""
|
||||||
|
self.assertEqual(self.t.transform('http://qutebrowser.org/'),
|
||||||
|
[QUrl('http://qutebrowser.org/')])
|
||||||
|
|
||||||
|
def test_transform_more(self):
|
||||||
|
"""Test transform with multiple values."""
|
||||||
|
self.assertEqual(
|
||||||
|
self.t.transform('http://qutebrowser.org/,http://heise.de/'),
|
||||||
|
[QUrl('http://qutebrowser.org/'), QUrl('http://heise.de/')])
|
||||||
|
|
||||||
|
|
||||||
if __name__ == '__main__':
|
if __name__ == '__main__':
|
||||||
unittest.main()
|
unittest.main()
|
||||||
|
Loading…
Reference in New Issue
Block a user