mirror of
https://github.com/jlu5/PyLink.git
synced 2024-11-30 14:49:28 +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.
|
# treated as a separate command, which is particularly nasty.
|
||||||
data = data.replace('\n', ' ')
|
data = data.replace('\n', ' ')
|
||||||
encoding = self.serverdata.get('encoding') or 'utf-8'
|
encoding = self.serverdata.get('encoding') or 'utf-8'
|
||||||
data = data.encode(encoding) + b"\n"
|
encoded_data = data.encode(encoding, 'replace') + b"\n"
|
||||||
stripped_data = data.decode(encoding).strip("\n")
|
|
||||||
log.debug("(%s) -> %s", self.name, stripped_data)
|
log.debug("(%s) -> %s", self.name, data)
|
||||||
|
|
||||||
try:
|
try:
|
||||||
self.socket.send(data)
|
self.socket.send(encoded_data)
|
||||||
except (OSError, AttributeError):
|
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):
|
def send(self, data, queue=True):
|
||||||
"""send() wrapper with optional queueing support."""
|
"""send() wrapper with optional queueing support."""
|
||||||
|
Loading…
Reference in New Issue
Block a user