22 lines
561 B
Python
22 lines
561 B
Python
"""Replaceable local event sinks."""
|
|
|
|
from __future__ import annotations
|
|
|
|
import json
|
|
from typing import Protocol, TextIO
|
|
|
|
from .models import InternalEventCandidate
|
|
|
|
|
|
class EventSink(Protocol):
|
|
def write(self, candidate: InternalEventCandidate) -> None: ...
|
|
|
|
|
|
class JsonLinesSink:
|
|
def __init__(self, stream: TextIO) -> None:
|
|
self._stream = stream
|
|
|
|
def write(self, candidate: InternalEventCandidate) -> None:
|
|
self._stream.write(json.dumps(candidate.to_dict(), ensure_ascii=False, sort_keys=True) + "\n")
|
|
self._stream.flush()
|