diff options
author | Laurent Pinchart <laurent.pinchart@ideasonboard.com> | 2020-07-03 01:43:57 +0300 |
---|---|---|
committer | Laurent Pinchart <laurent.pinchart@ideasonboard.com> | 2020-07-03 18:15:45 +0300 |
commit | 606741deb999598175bf8dcb5515f78b15bb3888 (patch) | |
tree | d01278caeb5d9bb8cb08e8b3ced3864e4577e066 /utils | |
parent | e101c78e03b03c4e66098a5e115788062fc51e4c (diff) |
utils: raspberrypi: ctt: json_pretty_print: Add character write method
Add a write method to the JSONPrettyPrinter class to output a character.
This will be used to handle state updates when outputting individual
characters.
Signed-off-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
Reviewed-by: David Plowman <david.plowman@raspberrypi.com>
Tested-by: David Plowman <david.plowman@raspberrypi.com>
Diffstat (limited to 'utils')
-rw-r--r-- | utils/raspberrypi/ctt/ctt_pretty_print_json.py | 25 |
1 files changed, 14 insertions, 11 deletions
diff --git a/utils/raspberrypi/ctt/ctt_pretty_print_json.py b/utils/raspberrypi/ctt/ctt_pretty_print_json.py index dfa99a6d..9d450f6d 100644 --- a/utils/raspberrypi/ctt/ctt_pretty_print_json.py +++ b/utils/raspberrypi/ctt/ctt_pretty_print_json.py @@ -25,20 +25,23 @@ class JSONPrettyPrinter(object): self.fout.write('\n') self.fout.write(' ' * self.state["indent"] * 4) + def write(self, c): + self.fout.write(c) + def process_char(self, c): if c == '{': if not self.state["skipnewline"]: self.newline() - self.fout.write(c) + self.write(c) self.state["indent"] += 1 self.newline() elif c == '}': self.state["indent"] -= 1 self.newline() - self.fout.write(c) + self.write(c) elif c == '[': self.newline() - self.fout.write(c) + self.write(c) self.state["indent"] += 1 self.newline() self.state["inarray"] = [True] + self.state["inarray"] @@ -48,27 +51,27 @@ class JSONPrettyPrinter(object): self.newline() self.state["inarray"].pop(0) self.state["arraycount"].pop(0) - self.fout.write(c) + self.write(c) elif c == ':': - self.fout.write(c) - self.fout.write(' ') + self.write(c) + self.write(' ') elif c == ',': if not self.state["inarray"][0]: - self.fout.write(c) - self.fout.write(' ') + self.write(c) + self.write(' ') self.newline() else: - self.fout.write(c) + self.write(c) self.state["arraycount"][0] += 1 if self.state["arraycount"][0] == 16: self.state["arraycount"][0] = 0 self.newline() else: - self.fout.write(' ') + self.write(' ') elif c.isspace(): pass else: - self.fout.write(c) + self.write(c) self.state["skipnewline"] = (c == '[') def print(self, string): |