Ejemplo n.º 1
0
def file(input_file: IO, out: Output) -> Iterator[Tuple[str, wl.Message]]:
    parse = True
    while True:
        try:
            line = input_file.readline()
        except KeyboardInterrupt:
            break
        if line == '':
            break
        line = line.strip()  # be sure to strip after the empty check
        try:
            conn_id, msg = message(line)
            if parse:
                yield conn_id, msg
        except RuntimeError as e:
            out.unprocessed(str(e))
        except:
            import traceback
            out.show(traceback.format_exc())
            parse = False
Ejemplo n.º 2
0
def show_help(out: Output) -> None:
    path = os.path.join(
        os.path.dirname(os.path.dirname(os.path.abspath(__file__))),
        'matchers.md')
    text = open(path, 'r').read()
    text = re.sub(r'# Matchers\n\n', '', text, flags=re.MULTILINE)
    text = re.sub(r'\| Matcher\s*\| Description \|\n',
                  '',
                  text,
                  flags=re.MULTILINE)
    text = re.sub(r'\| ---\s*\| --- \|\n', '', text, flags=re.MULTILINE)
    matches = re.findall(r'^\|\s*`(.*)`\s*\|(.*)\|$', text, flags=re.MULTILINE)
    parts = re.split(r'^\|.*\|$', text, flags=re.MULTILINE)
    assert len(matches) + 1 == len(parts)
    result = parts[0]
    for i, match in enumerate(matches):
        result += color(object_type_color, match[0])
        result += ' ' * (32 - len(match[0]))
        result += color(object_id_color, match[1])
        result += parts[i + 1]
    out.show(result)
Ejemplo n.º 3
0
 def show(self, out: Output) -> None:
     out.show(
         color(timestamp_color, '{:7.4f}'.format(self.timestamp)) + ' ' +
         str(self))
Ejemplo n.º 4
0
 def test_show_multi(self):
     o = Output(True, True, self.out, self.err)
     o.show('abc', 24, True)
     self.assertEqual(self.out.buffer, 'abc 24 True\n')
     self.assertEqual(self.err.buffer, '')
Ejemplo n.º 5
0
 def test_show(self):
     o = Output(True, True, self.out, self.err)
     o.show('abc')
     o.show('xyz')
     self.assertEqual(self.out.buffer, 'abc\nxyz\n')
     self.assertEqual(self.err.buffer, '')