gws.spec.generator.util¶
File, JSON and ini helpers for the generator.
Source code: gws.spec.generator.util
Module Contents¶
- gws.spec.generator.util.make_ini(dct)¶
Create an ini-style text from a dict of sections.
Keys are sorted, newlines in values are written as
\n.- Parameters:
dct – A dict of sections, each a dict of keys and values.
- Returns:
The ini text.
- gws.spec.generator.util.parse_ini(text)¶
Parse an ini-style strings file.
Lines starting with
;,#or//are comments. A line without=continues the value of the previous key.\nin values is converted to a newline.- Parameters:
text – File content.
- Returns:
A dict of sections, each a dict of keys and values.
- Raises:
ValueError – If a line cannot be parsed.
- gws.spec.generator.util.read_json(path)¶
Read a JSON file.
- Parameters:
path – File path.
- Returns:
The parsed JSON value.
- gws.spec.generator.util.write_json(path, obj)¶
Write an object to a JSON file.
Objects are written as their attribute dicts, bytes as hex strings, other values that are not JSON serializable as their
repr.- Parameters:
path – File path.
obj – Object to write.