36 lines
716 B
Python
36 lines
716 B
Python
|
|
from __future__ import annotations
|
||
|
|
|
||
|
|
import logging
|
||
|
|
|
||
|
|
logger = logging.getLogger(__name__)
|
||
|
|
|
||
|
|
|
||
|
|
class IrcStreamBuffer:
|
||
|
|
|
||
|
|
def __init__(self):
|
||
|
|
self._chunks: list[str] = []
|
||
|
|
self._finished = False
|
||
|
|
|
||
|
|
def feed(self, chunk: str) -> None:
|
||
|
|
self._chunks.append(chunk)
|
||
|
|
|
||
|
|
def flush(self) -> str:
|
||
|
|
content = "".join(self._chunks)
|
||
|
|
self._chunks.clear()
|
||
|
|
return content
|
||
|
|
|
||
|
|
@property
|
||
|
|
def content(self) -> str:
|
||
|
|
return "".join(self._chunks)
|
||
|
|
|
||
|
|
@property
|
||
|
|
def is_empty(self) -> bool:
|
||
|
|
return len(self._chunks) == 0
|
||
|
|
|
||
|
|
def mark_finished(self) -> None:
|
||
|
|
self._finished = True
|
||
|
|
|
||
|
|
@property
|
||
|
|
def finished(self) -> bool:
|
||
|
|
return self._finished
|