From 606741deb999598175bf8dcb5515f78b15bb3888 Mon Sep 17 00:00:00 2001 From: Laurent Pinchart Date: Fri, 3 Jul 2020 01:43:57 +0300 Subject: 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 Reviewed-by: David Plowman Tested-by: David Plowman --- utils/raspberrypi/ctt/ctt_pretty_print_json.py | 25 ++++++++++++++----------- 1 file changed, 14 insertions(+), 11 deletions(-) (limited to 'utils') 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): -- cgit v1.2.1