configtypes: Use YAML for loading List/Dict from a string
This allows for a more lightweight syntax (like "{a: b}").
This commit is contained in:
parent
41565fcfd4
commit
51a29468be
@ -20,7 +20,6 @@
|
|||||||
"""Setting options used for qutebrowser."""
|
"""Setting options used for qutebrowser."""
|
||||||
|
|
||||||
import re
|
import re
|
||||||
import json
|
|
||||||
import shlex
|
import shlex
|
||||||
import codecs
|
import codecs
|
||||||
import os.path
|
import os.path
|
||||||
@ -29,6 +28,7 @@ import collections
|
|||||||
import warnings
|
import warnings
|
||||||
import datetime
|
import datetime
|
||||||
|
|
||||||
|
import yaml
|
||||||
from PyQt5.QtCore import QUrl, Qt
|
from PyQt5.QtCore import QUrl, Qt
|
||||||
from PyQt5.QtGui import QColor, QFont
|
from PyQt5.QtGui import QColor, QFont
|
||||||
from PyQt5.QtWidgets import QTabWidget, QTabBar
|
from PyQt5.QtWidgets import QTabWidget, QTabBar
|
||||||
@ -370,13 +370,13 @@ class List(BaseType):
|
|||||||
return None
|
return None
|
||||||
|
|
||||||
try:
|
try:
|
||||||
json_val = json.loads(value)
|
yaml_val = utils.yaml_load(value)
|
||||||
except ValueError as e:
|
except yaml.YAMLError as e:
|
||||||
raise configexc.ValidationError(value, str(e))
|
raise configexc.ValidationError(value, str(e))
|
||||||
|
|
||||||
# For the values, we actually want to call from_py, as we did parse them
|
# For the values, we actually want to call from_py, as we did parse them
|
||||||
# from JSON, so they are numbers/booleans/... already.
|
# from YAML, so they are numbers/booleans/... already.
|
||||||
return self.from_py(json_val)
|
return self.from_py(yaml_val)
|
||||||
|
|
||||||
def from_py(self, value):
|
def from_py(self, value):
|
||||||
self._basic_validation(value, pytype=list)
|
self._basic_validation(value, pytype=list)
|
||||||
@ -917,13 +917,13 @@ class Dict(BaseType):
|
|||||||
return None
|
return None
|
||||||
|
|
||||||
try:
|
try:
|
||||||
json_val = json.loads(value)
|
yaml_val = utils.yaml_load(value)
|
||||||
except ValueError as e:
|
except yaml.YAMLError as e:
|
||||||
raise configexc.ValidationError(value, str(e))
|
raise configexc.ValidationError(value, str(e))
|
||||||
|
|
||||||
# For the values, we actually want to call from_py, as we did parse them
|
# For the values, we actually want to call from_py, as we did parse them
|
||||||
# from JSON, so they are numbers/booleans/... already.
|
# from YAML, so they are numbers/booleans/... already.
|
||||||
return self.from_py(json_val)
|
return self.from_py(yaml_val)
|
||||||
|
|
||||||
def from_py(self, value):
|
def from_py(self, value):
|
||||||
self._basic_validation(value, pytype=dict)
|
self._basic_validation(value, pytype=dict)
|
||||||
|
Loading…
Reference in New Issue
Block a user