Changed definition of notFunky to include extended characters that might not be printable in my locale.

This commit is contained in:
Jeremy Fincher 2003-04-17 10:11:34 +00:00
parent 73a5de98eb
commit 7fa59b0f35

View File

@ -34,6 +34,7 @@ from fix import *
import re import re
import string import string
import fnmatch import fnmatch
import operator
import debug import debug
import world import world
@ -190,7 +191,7 @@ def bold(s):
def isValidArgument(s): def isValidArgument(s):
return '\r' not in s and '\n' not in s and '\x00' not in 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): def safeArgument(s):
if isValidArgument(s) and s.translate(string.ascii, notFunky) == '': if isValidArgument(s) and s.translate(string.ascii, notFunky) == '':
return s return s
@ -203,6 +204,21 @@ def replyTo(msg):
else: else:
return msg.nick 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): class nick(str):
"""This class does case-insensitive comparisons of nicks.""" """This class does case-insensitive comparisons of nicks."""