def __init__(self, model, encoding='hexdump', mode='sequence', color='ansi'): self.color = color self.render = Render(color=color, encoder=encoding) self.mode = mode self.model = model model.add_listener(self)
def __init__(self, model, encoding='hexdump', mode='sequence', color='html', width='82'): self.color = color self.render = Render(color=color, encoder=encoding, width=width) self.mode = mode self.model = model model.add_listener(self)
class StreamView(): def __init__(self, model, encoding='hexdump', mode='sequence', color='ansi'): self.color = color self.render = Render(color=color, encoder=encoding) self.mode = mode self.model = model model.add_listener(self) def object_added(self, index): if index > 0: self.model.diff(index - 1, index) def diff_added(self, diff): if self.model.objects[diff.target].info != '': if self.color == 'ansi': print(Ansi.bold + self.model.objects[diff.target].info + Ansi.reset) elif self.color == 'html': print('<span style="font-weight: bold;">' + html.escape(self.model.objects[diff.target].info) + '</span>') print(self.render.render(self.model, diff)) #clean up model to not leak memory in long runs del (self.model.diffs[0]) if self.mode == 'sequence': del (self.model.objects[0]) elif self.mode == 'baseline': del (self.model.objects[1])
class StreamView(): '''A class for building UIs. Has some pretty serious side effects. Use Render instead if you're not making a long-running UI''' def __init__(self, model, encoding='hexdump', mode='sequence', color='ansi'): self.color = color self.render = Render(color=color, encoder=encoding) self.mode = mode self.model = model model.add_listener(self) def object_added(self, index): if index > 0: self.model.diff(index - 1, index) def diff_added(self, diff): if self.model.objects[diff.target].info != '': if self.color == 'ansi': print(Ansi.bold + self.model.objects[diff.target].info + Ansi.reset) elif self.color == 'html': print('<span style="font-weight: bold;">' + html.escape(self.model.objects[diff.target].info) + '</span>') print(self.render.render(self.model, diff)) #StreamView is designed to run for long times so we delete #old objects and diffs to not leak memory del(self.model.diffs[0]) if self.mode == 'sequence': del(self.model.objects[0]) elif self.mode == 'baseline': del(self.model.objects[1])
def test_sequence_ansi_utf_dump(): objs = open("test/pretty_json.txt").read(-1).split('\n\n') objs = [bytes(x, 'utf8') for x in objs] m = MultidiffModel(objs) m.diff_sequence() res = Render(encoder='utf8').dumps(m) print(res) #for visual checking when tests fail base = open("test/pretty_json_res.txt").read(-1) assert res == base
def test_baseline_html_utf_dump(): objs = open("test/minimal.txt").read(-1).split('\n')[:-1] objs = [bytes(x, 'utf8') for x in objs] m = MultidiffModel(objs) m.diff_baseline() res = Render(encoder='utf8', color='html').dumps(m) print(res) base = open("test/minimal_res.html").read(-1) assert res == base