From 2737b6bbfc54802fbe253dd5089e6ae37a0cc358 Mon Sep 17 00:00:00 2001 From: James Lu Date: Sat, 27 May 2017 02:21:12 -0700 Subject: [PATCH] Irc: simplify _send() code and replace unencodable characters --- classes.py | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/classes.py b/classes.py index 0111a95..34cb576 100644 --- a/classes.py +++ b/classes.py @@ -511,14 +511,14 @@ class Irc(utils.DeprecatedAttributesObject): # treated as a separate command, which is particularly nasty. data = data.replace('\n', ' ') encoding = self.serverdata.get('encoding') or 'utf-8' - data = data.encode(encoding) + b"\n" - stripped_data = data.decode(encoding).strip("\n") - log.debug("(%s) -> %s", self.name, stripped_data) + encoded_data = data.encode(encoding, 'replace') + b"\n" + + log.debug("(%s) -> %s", self.name, data) try: - self.socket.send(data) + self.socket.send(encoded_data) except (OSError, AttributeError): - log.exception("(%s) Failed to send message %r; did the network disconnect?", self.name, stripped_data) + log.exception("(%s) Failed to send message %r; did the network disconnect?", self.name, data) def send(self, data, queue=True): """send() wrapper with optional queueing support."""