Fix previous commit.

This commit is contained in:
Valentin Lorentz 2018-02-01 22:37:24 +01:00
parent 63a17f7491
commit 030ce5e6d4
5 changed files with 28 additions and 4 deletions

View File

@ -36,7 +36,7 @@ class GamesTestCase(ChannelPluginTestCase):
self.irc.feedMsg(ircmsgs.op(self.channel, self.irc.nick)) self.irc.feedMsg(ircmsgs.op(self.channel, self.irc.nick))
sawKick = False sawKick = False
for i in range(100): for i in range(100):
m = self.getMsg('roulette', frm='someoneElse') m = self.getMsg('roulette', frm='someoneElse!foo@bar')
if m.command == 'PRIVMSG': if m.command == 'PRIVMSG':
self.failUnless(self._nonKickRe.search(m.args[1]), self.failUnless(self._nonKickRe.search(m.args[1]),
'Got a msg without bang|click|spin: %r' % m) 'Got a msg without bang|click|spin: %r' % m)

View File

@ -926,7 +926,7 @@ class NestedCommandsIrcProxy(ReplyIrcProxy):
maximumLength, len(s)) maximumLength, len(s))
s = s[:maximumLength] s = s[:maximumLength]
s_size = len(s.encode()) if minisix.PY3 else len(s) s_size = len(s.encode()) if minisix.PY3 else len(s)
if s_size > allowedLength or \ if s_size <= allowedLength or \
not conf.get(conf.supybot.reply.mores, target): not conf.get(conf.supybot.reply.mores, target):
# In case we're truncating, we add 20 to allowedLength, # In case we're truncating, we add 20 to allowedLength,
# because our allowedLength is shortened for the # because our allowedLength is shortened for the

View File

@ -598,7 +598,8 @@ class FormatParser(object):
def wrap(s, length, break_on_hyphens = False, break_long_words = False): def wrap(s, length, break_on_hyphens = False, break_long_words = False):
processed = [] processed = []
chunks = utils.str.byteTextWrap(s, length) chunks = utils.str.byteTextWrap(s, length,
break_long_words=break_long_words)
context = None context = None
for chunk in chunks: for chunk in chunks:
if context is not None: if context is not None:

View File

@ -306,7 +306,7 @@ def perlVariableSubstitute(vars, text):
return '$' + unbraced return '$' + unbraced
return _perlVarSubstituteRe.sub(replacer, text) return _perlVarSubstituteRe.sub(replacer, text)
def byteTextWrap(text, size): def byteTextWrap(text, size, break_on_hyphens=False, break_long_words=True):
"""Similar to textwrap.wrap(), but considers the size of strings (in bytes) """Similar to textwrap.wrap(), but considers the size of strings (in bytes)
instead of their length (in characters).""" instead of their length (in characters)."""
words = textwrap.TextWrapper()._split_chunks(text) words = textwrap.TextWrapper()._split_chunks(text)
@ -316,6 +316,9 @@ def byteTextWrap(text, size):
lines = [b''] lines = [b'']
while words: while words:
word = words.pop(-1) word = words.pop(-1)
if len(word) > size:
words.append(word[size:])
word = word[0:size]
if len(lines[-1]) + len(word) <= size: if len(lines[-1]) + len(word) <= size:
lines[-1] += word lines[-1] += word
else: else:

View File

@ -195,6 +195,26 @@ class FunctionsTestCase(SupyTestCase):
self.assertTrue(max(map(pred, r)) <= 100) self.assertTrue(max(map(pred, r)) <= 100)
self.assertEqual(''.join(r), s) self.assertEqual(''.join(r), s)
s = ('foobarbazqux ' * 100)[0:-1]
r = ircutils.wrap(s, 10)
self.assertTrue(max(map(pred, r)) <= 10)
self.assertEqual(''.join(r), s)
r = ircutils.wrap(s, 100)
self.assertTrue(max(map(pred, r)) <= 100)
self.assertEqual(''.join(r), s)
s = ('foobarbazqux' * 100)[0:-1]
r = ircutils.wrap(s, 10)
self.assertTrue(max(map(pred, r)) <= 10)
self.assertEqual(''.join(r), s)
r = ircutils.wrap(s, 100)
self.assertTrue(max(map(pred, r)) <= 100)
self.assertEqual(''.join(r), s)
def testSafeArgument(self): def testSafeArgument(self):
s = 'I have been running for 9 seconds' s = 'I have been running for 9 seconds'