def run_event(self): args = self.args stream = Stream(id=args.id, password=args.password, generator=args.generator) encoding = sys.stdin.encoding or locale.getdefaultlocale()[1] char_count = 0 lines = [] for line in sys.stdin: sys.stdout.write(line) line = line.decode(encoding, 'replace') if char_count + len(line) <= self.MAX_CHARS: lines.append(line) char_count += len(line) text = "".join(lines)[:self.MAX_CHARS] if isinstance(text, bytes): encoding = sys.stdin.encoding or locale.getdefaultlocale()[1] text = text.decode(encoding, 'replace') event = Event(type="code", title=args.title or 'Capture Event', markup=args.markup, description=args.description, text=text) result = stream.add_event(event) return result