From 7fa59b0f351ead7a17000ed937c8a9704f13a6bb Mon Sep 17 00:00:00 2001 From: Jeremy Fincher Date: Thu, 17 Apr 2003 10:11:34 +0000 Subject: [PATCH] Changed definition of notFunky to include extended characters that might not be printable in my locale. --- src/ircutils.py | 18 +++++++++++++++++- 1 file changed, 17 insertions(+), 1 deletion(-) diff --git a/src/ircutils.py b/src/ircutils.py index e2b95e8df..521551466 100644 --- a/src/ircutils.py +++ b/src/ircutils.py @@ -34,6 +34,7 @@ from fix import * import re import string import fnmatch +import operator import debug import world @@ -190,7 +191,7 @@ def bold(s): def isValidArgument(s): return '\r' not in s and '\n' not in s and '\x00' not in s -notFunky = string.printable+'\x02' +notFunky = string.ascii[32:]+'\x02' def safeArgument(s): if isValidArgument(s) and s.translate(string.ascii, notFunky) == '': return s @@ -203,6 +204,21 @@ def replyTo(msg): else: return msg.nick +def privmsgPayload(L, sep, limit=450): + """Returns a valid privmsg payload given a list of strings and a separator. + + Items are popped from the back of the list until the payload is small + enough to fit into a single PRIVMSG payload. + """ + shrinkList(L, sep, limit) + return sep.join(L) + +def shrinkList(L, sep='', limit=450): + """Shrinks a list of strings to a given combined length of limit.""" + length = len(sep) + while reduce(operator.add, map(length.__add__, map(len, L)), 0)> limit: + L.pop() + class nick(str): """This class does case-insensitive comparisons of nicks."""