Count number of bytes instead of number of characters for truncating messages. Closes GH-1038.

This commit is contained in:
Valentin Lorentz 2015-02-04 17:31:42 +01:00
parent b769d1067f
commit 681bd5d85d

View File

@ -926,7 +926,13 @@ class NestedCommandsIrcProxy(ReplyIrcProxy):
# In case we're truncating, we add 20 to allowedLength,
# because our allowedLength is shortened for the
# "(XX more messages)" trailer.
s = s[:allowedLength+len(_('(XX more messages)'))]
if sys.version_info[0] >= 3:
appended = _('(XX more messages)').encode()
s = s.encode()[:allowedLength+len(appended)]
s = s.decode('utf8', 'ignore')
else:
appended = _('(XX more messages)')
s = s[:allowedLength+len(appended)]
# There's no need for action=self.action here because
# action implies noLengthCheck, which has already been
# handled. Let's stick an assert in here just in case.