mirror of
https://github.com/jlu5/PyLink.git
synced 2024-12-28 05:32:51 +01:00
Irc: simplify _send() code and replace unencodable characters
This commit is contained in:
parent
1246edaf2c
commit
2737b6bbfc
10
classes.py
10
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."""
|
||||
|
Loading…
Reference in New Issue
Block a user