mirror of
https://github.com/Mikaela/Limnoria.git
synced 2025-01-30 14:14:37 +01:00
Changed bold and mircColor to use the right ender \x0F.
This commit is contained in:
parent
fd57203a67
commit
f0816d56a7
@ -205,7 +205,15 @@ def joinModes(modes):
|
||||
|
||||
def bold(s):
|
||||
"""Returns the string s, bolded."""
|
||||
return "\x02%s\x02" % s
|
||||
return '\x02%s\x0F' % s
|
||||
|
||||
def reverse(s):
|
||||
"""Returns the string s, reverse-videoed."""
|
||||
return '\x16%s\x0F' % s
|
||||
|
||||
def underline(s):
|
||||
"""Returns the string s, underlined."""
|
||||
return '\x1F%s\x0F' % s
|
||||
|
||||
mircColors = {
|
||||
None: '',
|
||||
@ -239,11 +247,11 @@ def mircColor(s, fg=None, bg=None):
|
||||
if fg is None or isinstance(fg, str):
|
||||
fg = mircColors[fg]
|
||||
if bg is None:
|
||||
return '\x03%s%s\x03' % (fg, s)
|
||||
return '\x03%s%s\x0F' % (fg, s)
|
||||
else:
|
||||
if isinstance(bg, str):
|
||||
bg = mircColors[bg]
|
||||
return '\x03%s,%s%s\x03' % (fg, bg, s)
|
||||
return '\x03%s,%s%s\x0F' % (fg, bg, s)
|
||||
|
||||
def canonicalColor(s, bg=False, shift=0):
|
||||
h = hash(s) >> shift
|
||||
@ -258,7 +266,7 @@ def canonicalColor(s, bg=False, shift=0):
|
||||
else:
|
||||
return (fg, None)
|
||||
|
||||
_unColorRe = re.compile('\x03(?:\\d+|\\d+,\\d+)?')
|
||||
_unColorRe = re.compile('(\x0F|\x03(?:\\d+|\\d+,\\d+)?)')
|
||||
def unColor(s):
|
||||
return _unColorRe.sub('', s)
|
||||
|
||||
@ -266,7 +274,7 @@ def isValidArgument(s):
|
||||
"""Returns if 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
|
||||
|
||||
notFunky = string.ascii[32:]+'\x02'+'\x03'
|
||||
notFunky = string.ascii[32:]+'\x02\x03\x0F\x16\x1F'
|
||||
def safeArgument(s):
|
||||
"""If s is unsafe for IRC, returns a safe version."""
|
||||
if isValidArgument(s) and s.translate(string.ascii, notFunky) == '':
|
||||
|
@ -69,20 +69,20 @@ class FunctionsTestCase(unittest.TestCase):
|
||||
def testBold(self):
|
||||
s = ircutils.bold('foo')
|
||||
self.assertEqual(s[0], '\x02')
|
||||
self.assertEqual(s[-1], '\x02')
|
||||
self.assertEqual(s[-1], '\x0F')
|
||||
|
||||
def testMircColor(self):
|
||||
# No colors provided should return the same string
|
||||
s = 'foo'
|
||||
self.assertEqual(s, ircutils.mircColor(s))
|
||||
# Test positional args
|
||||
self.assertEqual('\x030foo\x03', ircutils.mircColor(s, 'white'))
|
||||
self.assertEqual('\x031,2foo\x03',ircutils.mircColor(s,'black','blue'))
|
||||
self.assertEqual('\x03,3foo\x03', ircutils.mircColor(s, None, 'green'))
|
||||
self.assertEqual('\x030foo\x0F', ircutils.mircColor(s, 'white'))
|
||||
self.assertEqual('\x031,2foo\x0F',ircutils.mircColor(s,'black','blue'))
|
||||
self.assertEqual('\x03,3foo\x0F', ircutils.mircColor(s, None, 'green'))
|
||||
# Test keyword args
|
||||
self.assertEqual('\x034foo\x03', ircutils.mircColor(s, fg='red'))
|
||||
self.assertEqual('\x03,5foo\x03', ircutils.mircColor(s, bg='brown'))
|
||||
self.assertEqual('\x036,7foo\x03',
|
||||
self.assertEqual('\x034foo\x0F', ircutils.mircColor(s, fg='red'))
|
||||
self.assertEqual('\x03,5foo\x0F', ircutils.mircColor(s, bg='brown'))
|
||||
self.assertEqual('\x036,7foo\x0F',
|
||||
ircutils.mircColor(s, bg='orange', fg='purple'))
|
||||
|
||||
def testMircColors(self):
|
||||
@ -163,6 +163,14 @@ class FunctionsTestCase(unittest.TestCase):
|
||||
self.assertEqual(ircutils.joinModes(modes),
|
||||
['+be-l', plusB[1], plusE[1]])
|
||||
|
||||
def testUnColor(self):
|
||||
self.assertEqual(ircutils.unColor('\x03foo\x03'), 'foo')
|
||||
self.assertEqual(ircutils.unColor('\x03foo\x0F'), 'foo')
|
||||
self.assertEqual(ircutils.unColor('\x0312foo\x03'), 'foo')
|
||||
self.assertEqual(ircutils.unColor('\x0312,14foo\x03'), 'foo')
|
||||
self.assertEqual(ircutils.unColor('\x0312foo\x0F'), 'foo')
|
||||
self.assertEqual(ircutils.unColor('\x0312,14foo\x0F'), 'foo')
|
||||
|
||||
|
||||
class IrcDictTestCase(unittest.TestCase):
|
||||
def test(self):
|
||||
|
Loading…
Reference in New Issue
Block a user