diff options
| author | 2019-02-10 18:43:04 +0000 | |
|---|---|---|
| committer | 2019-02-10 18:43:04 +0000 | |
| commit | a3b9be3d3ddc666225c0aa0afb377a1ba3628ba8 (patch) | |
| tree | 198bc31701a205d4b108dc3e86d0c12754bce78c /src/IRCLine.py | |
| parent | Return truncted data from encode_truncate and hold it in IRCLine.Line (diff) | |
| signature | ||
Shift encoding/truncating IRC lines to src/IRCLine.py
Diffstat (limited to 'src/IRCLine.py')
| -rw-r--r-- | src/IRCLine.py | 20 |
1 files changed, 14 insertions, 6 deletions
diff --git a/src/IRCLine.py b/src/IRCLine.py index 88c1cfe4..e5a58707 100644 --- a/src/IRCLine.py +++ b/src/IRCLine.py @@ -1,22 +1,30 @@ import datetime, typing -from src import IRCObject +from src import IRCObject, utils + +LINE_CUTOFF = 450 class Line(IRCObject.Object): - def __init__(self, send_time: datetime.datetime, data: bytes, - truncated: str): + def __init__(self, send_time: datetime.datetime, line: str): + self._line = line self.send_time = send_time - self.data = data - self.truncated = truncated + + data, truncated = utils.encode_truncate(line, "utf8", LINE_CUTOFF) + + self._data = data + self._truncated = truncated self._on_send = [] # type: typing.List[typing.Callable[[], None]] def __repr__(self) -> str: return "IRCLine.Line(%s)" % self.__str__() def __str__(self) -> str: - return self.data + return self._data def on_send(self, func: typing.Callable[[], None]): self._on_send.append(func) def sent(self): for func in self._on_send[:]: func() + + def data(self) -> bytes: + return b"%s\r\n" % self._data |
