mirror of
https://github.com/Mikaela/Limnoria.git
synced 2024-12-23 19:22:45 +01:00
ircutils.strip{Bold,Reverse,Underline,Formatting}
This commit is contained in:
parent
38fee5b2dd
commit
e87c31aea4
@ -1,3 +1,7 @@
|
|||||||
|
* Added ircutils.strip{Bold,Reverse,Underline,Formatting}, which
|
||||||
|
will remove the specified formatting or all forms of formatting
|
||||||
|
in the case of stripFormatting.
|
||||||
|
|
||||||
* Replaced Sourceforge.{rfe,bug} with Sourceforge.tracker, which
|
* Replaced Sourceforge.{rfe,bug} with Sourceforge.tracker, which
|
||||||
can query any tracker type (not just RFEs and bugs) and responds
|
can query any tracker type (not just RFEs and bugs) and responds
|
||||||
with more information, a la trackerSnarfer.
|
with more information, a la trackerSnarfer.
|
||||||
|
@ -321,11 +321,31 @@ def canonicalColor(s, bg=False, shift=0):
|
|||||||
else:
|
else:
|
||||||
return (fg, None)
|
return (fg, None)
|
||||||
|
|
||||||
|
def stripBold(s):
|
||||||
|
"""Returns the string s, with bold removed."""
|
||||||
|
return s.replace('\x02', '')
|
||||||
|
|
||||||
_unColorRe = re.compile(r'\x03(?:\d{1,2},\d{1,2}|\d{1,2}|,\d{1,2}|)')
|
_unColorRe = re.compile(r'\x03(?:\d{1,2},\d{1,2}|\d{1,2}|,\d{1,2}|)')
|
||||||
def unColor(s):
|
def stripColor(s):
|
||||||
"""Removes the color from a string."""
|
"""Returns the string s, with color removed."""
|
||||||
return _unColorRe.sub('', s)
|
return _unColorRe.sub('', s)
|
||||||
|
|
||||||
|
def stripReverse(s):
|
||||||
|
"""Returns the string s, with reverse-video removed."""
|
||||||
|
return s.replace('\x16', '')
|
||||||
|
|
||||||
|
def stripUnderline(s):
|
||||||
|
"""Returns the string s, with underlining removed."""
|
||||||
|
return s.replace('\x1f', '').replace('\x1F', '')
|
||||||
|
|
||||||
|
def stripFormatting(s):
|
||||||
|
"""Returns the string s, with all formatting removed."""
|
||||||
|
s = stripBold(s)
|
||||||
|
s = stripColor(s)
|
||||||
|
s = stripReverse(s)
|
||||||
|
s = stripUnderline(s)
|
||||||
|
return s.replace('\x0f', '').replace('\x0F', '')
|
||||||
|
|
||||||
def isValidArgument(s):
|
def isValidArgument(s):
|
||||||
"""Returns whether 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
|
||||||
|
@ -93,6 +93,16 @@ class FunctionsTestCase(SupyTestCase):
|
|||||||
self.assertEqual(s[0], '\x02')
|
self.assertEqual(s[0], '\x02')
|
||||||
self.assertEqual(s[-1], '\x02')
|
self.assertEqual(s[-1], '\x02')
|
||||||
|
|
||||||
|
def testUnderline(self):
|
||||||
|
s = ircutils.underline('foo')
|
||||||
|
self.assertEqual(s[0], '\x1f')
|
||||||
|
self.assertEqual(s[-1], '\x1f')
|
||||||
|
|
||||||
|
def testReverse(self):
|
||||||
|
s = ircutils.reverse('foo')
|
||||||
|
self.assertEqual(s[0], '\x16')
|
||||||
|
self.assertEqual(s[-1], '\x16')
|
||||||
|
|
||||||
def testMircColor(self):
|
def testMircColor(self):
|
||||||
# No colors provided should return the same string
|
# No colors provided should return the same string
|
||||||
s = 'foo'
|
s = 'foo'
|
||||||
@ -113,6 +123,39 @@ class FunctionsTestCase(SupyTestCase):
|
|||||||
if k:
|
if k:
|
||||||
self.assertEqual(ircutils.mircColors[v], k)
|
self.assertEqual(ircutils.mircColors[v], k)
|
||||||
|
|
||||||
|
def testStripBold(self):
|
||||||
|
self.assertEqual(ircutils.stripBold(ircutils.bold('foo')), 'foo')
|
||||||
|
|
||||||
|
def testStripColor(self):
|
||||||
|
self.assertEqual(ircutils.stripColor('\x02bold\x0302,04foo\x03bar\x0f'),
|
||||||
|
'\x02boldfoobar\x0f')
|
||||||
|
self.assertEqual(ircutils.stripColor('\x03foo\x03'), 'foo')
|
||||||
|
self.assertEqual(ircutils.stripColor('\x03foo\x0F'), 'foo\x0F')
|
||||||
|
self.assertEqual(ircutils.stripColor('\x0312foo\x03'), 'foo')
|
||||||
|
self.assertEqual(ircutils.stripColor('\x0312,14foo\x03'), 'foo')
|
||||||
|
self.assertEqual(ircutils.stripColor('\x03,14foo\x03'), 'foo')
|
||||||
|
self.assertEqual(ircutils.stripColor('\x03,foo\x03'), ',foo')
|
||||||
|
self.assertEqual(ircutils.stripColor('\x0312foo\x0F'), 'foo\x0F')
|
||||||
|
self.assertEqual(ircutils.stripColor('\x0312,14foo\x0F'), 'foo\x0F')
|
||||||
|
self.assertEqual(ircutils.stripColor('\x03,14foo\x0F'), 'foo\x0F')
|
||||||
|
self.assertEqual(ircutils.stripColor('\x03,foo\x0F'), ',foo\x0F')
|
||||||
|
|
||||||
|
def testStripReverse(self):
|
||||||
|
self.assertEqual(ircutils.stripReverse(ircutils.reverse('foo')), 'foo')
|
||||||
|
|
||||||
|
def testStripUnderline(self):
|
||||||
|
self.assertEqual(ircutils.stripUnderline(ircutils.underline('foo')),
|
||||||
|
'foo')
|
||||||
|
|
||||||
|
def testStripFormatting(self):
|
||||||
|
self.assertEqual(ircutils.stripFormatting(ircutils.bold('foo')), 'foo')
|
||||||
|
self.assertEqual(ircutils.stripFormatting(ircutils.reverse('foo')),
|
||||||
|
'foo')
|
||||||
|
self.assertEqual(ircutils.stripFormatting(ircutils.underline('foo')),
|
||||||
|
'foo')
|
||||||
|
self.assertEqual(ircutils.stripFormatting('\x02bold\x0302,04foo\x03'
|
||||||
|
'bar\x0f'),
|
||||||
|
'boldfoobar')
|
||||||
|
|
||||||
def testSafeArgument(self):
|
def testSafeArgument(self):
|
||||||
s = 'I have been running for 9 seconds'
|
s = 'I have been running for 9 seconds'
|
||||||
@ -175,20 +218,6 @@ class FunctionsTestCase(SupyTestCase):
|
|||||||
self.assertEqual(ircutils.joinModes(modes),
|
self.assertEqual(ircutils.joinModes(modes),
|
||||||
['+be-l', plusB[1], plusE[1]])
|
['+be-l', plusB[1], plusE[1]])
|
||||||
|
|
||||||
def testUnColor(self):
|
|
||||||
self.assertEqual(ircutils.unColor('\x02bold\x0302,04foo\x03bar\x0f'),
|
|
||||||
'\x02boldfoobar\x0f')
|
|
||||||
self.assertEqual(ircutils.unColor('\x03foo\x03'), 'foo')
|
|
||||||
self.assertEqual(ircutils.unColor('\x03foo\x0F'), 'foo\x0F')
|
|
||||||
self.assertEqual(ircutils.unColor('\x0312foo\x03'), 'foo')
|
|
||||||
self.assertEqual(ircutils.unColor('\x0312,14foo\x03'), 'foo')
|
|
||||||
self.assertEqual(ircutils.unColor('\x03,14foo\x03'), 'foo')
|
|
||||||
self.assertEqual(ircutils.unColor('\x03,foo\x03'), ',foo')
|
|
||||||
self.assertEqual(ircutils.unColor('\x0312foo\x0F'), 'foo\x0F')
|
|
||||||
self.assertEqual(ircutils.unColor('\x0312,14foo\x0F'), 'foo\x0F')
|
|
||||||
self.assertEqual(ircutils.unColor('\x03,14foo\x0F'), 'foo\x0F')
|
|
||||||
self.assertEqual(ircutils.unColor('\x03,foo\x0F'), ',foo\x0F')
|
|
||||||
|
|
||||||
def testDccIpStuff(self):
|
def testDccIpStuff(self):
|
||||||
def randomIP():
|
def randomIP():
|
||||||
def rand():
|
def rand():
|
||||||
@ -249,6 +278,7 @@ class IrcDictTestCase(SupyTestCase):
|
|||||||
self.failUnless(d == copy.copy(d))
|
self.failUnless(d == copy.copy(d))
|
||||||
self.failUnless(d == copy.deepcopy(d))
|
self.failUnless(d == copy.deepcopy(d))
|
||||||
|
|
||||||
|
|
||||||
class IrcSetTestCase(SupyTestCase):
|
class IrcSetTestCase(SupyTestCase):
|
||||||
def test(self):
|
def test(self):
|
||||||
s = ircutils.IrcSet()
|
s = ircutils.IrcSet()
|
||||||
@ -280,7 +310,6 @@ class IrcSetTestCase(SupyTestCase):
|
|||||||
self.failIf('FOo' in s1)
|
self.failIf('FOo' in s1)
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
class IrcStringTestCase(SupyTestCase):
|
class IrcStringTestCase(SupyTestCase):
|
||||||
def testEquality(self):
|
def testEquality(self):
|
||||||
self.assertEqual('#foo', ircutils.IrcString('#foo'))
|
self.assertEqual('#foo', ircutils.IrcString('#foo'))
|
||||||
|
Loading…
Reference in New Issue
Block a user