bootleg.utils.classes package¶
Submodules¶
bootleg.utils.classes.aliasmention_trie module¶
bootleg.utils.classes.comment_json module¶
JSON with comments class.
An example of how to remove comments and trailing commas from JSON before parsing. You only need the two functions below, remove_comments() and remove_trailing_commas() to accomplish this. This script serves as an example of how to use them but feel free to just copy & paste them into your own code/projects. Usage:: json_cleaner.py some_file.json Alternatively, you can pipe JSON into this script and it’ll clean it up:: cat some_file.json | json_cleaner.py Why would you do this? So you can have human-generated .json files (say, for configuration) that include comments and, really, who wants to deal with catching all those trailing commas that might be present? Here’s an example of a file that will be successfully cleaned up and JSON-parseable:
FYI: This script will also pretty-print the JSON after it’s cleaned up (if using it from the command line) with an indentation level of 4 (that is, four spaces).
- bootleg.utils.classes.comment_json.remove_comments(json_like)[source]¶
Remove C-style comments from json_like and returns the result.
Example:
>>> test_json = '''\ { "foo": "bar", // This is a single-line comment "baz": "blah" /* Multi-line Comment */ }''' >>> remove_comments('{"foo":"bar","baz":"blah",}') '{\n "foo":"bar",\n "baz":"blah"\n}'
bootleg.utils.classes.dotted_dict module¶
Dotted dict class.
- class bootleg.utils.classes.dotted_dict.DottedDict(*args, **kwargs)[source]¶
Bases:
dict
Dotted dictionary.
Override for the dict object to allow referencing of keys as attributes, i.e. dict.key.
- class bootleg.utils.classes.dotted_dict.PreserveKeysDottedDict(*args, **kwargs)[source]¶
Bases:
dict
Override auto correction of key names to safe attr names.
Can result in errors when using attr name resolution.
Module contents¶
Classes init.