def read_cnf_json(cnfdata):
+ """
+ Read json data from cnf data bytes.
+
+ :param bytes cnfdata: config data
+ :return: the parsed json data
+ :rtype: str
+
+ .. note:: The JSON module does not decode data for all versions
+ of Python 3 so we handle the decoding ourselves.
+ """
+ cnfdata = cnfdata.decode('iso-8859-1')
cnf_json = json.loads(cnfdata)
if is_cnf(cnf_json) is False:
raise TypeError("Invalid CNF_VAR.")
def prepare(raw):
"""
- :type raw: str
+ :type raw: bytes
:rtype: (str * str option * str list) option
"""
lines = raw.splitlines()
second = None
first = first.strip()
- if first == "":
+ if first == b"":
return advance((first, second, lines))
return (first, second, lines)
def read_base_line(line):
if len(line.strip()) == 0:
return None # ignore empty lines
- if line[0] == "#":
+ if line[0] == b"#":
return None # ignore comments
match = re.match(base_line_pattern, line)
def read_cnf(data):
+ """
+ Read cnf data from data bytes.
+
+ :param bytes data: raw data
+ :return: the parsed cnf data
+ :rtype: {str, {str, str or int}}
+ """
state = prepare(data)
if state is None:
raise InvalidCNF("Empty input string.")