Trying something out for fixing the Jawoota unicode bug.

This commit is contained in:
Jeremy Fincher 2004-02-10 06:19:16 +00:00
parent ac74ef9819
commit d2d5f880ed

View File

@ -320,14 +320,14 @@ def unColor(s):
return _unColorRe.sub('', s) return _unColorRe.sub('', s)
def isValidArgument(s): def isValidArgument(s):
"""Returns if s is strictly a valid argument for an IRC message.""" """Returns whether s is strictly a valid argument for an IRC message."""
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.ascii[32:]+'\x02\x03\x0F\x16\x1F'
def safeArgument(s): def safeArgument(s):
"""If s is unsafe for IRC, returns a safe version.""" """If s is unsafe for IRC, returns a safe version."""
assert not isinstance(s, unicode),'Unicode strings are not allowed in IRC.' if isinstance(s, unicode):
if isValidArgument(s) and s.translate(string.ascii, notFunky) == '': s = s.encode('utf-8')
if isValidArgument(s):
return s return s
else: else:
return repr(s) return repr(s)