mirror of
https://github.com/Mikaela/Limnoria.git
synced 2024-11-19 08:59:27 +01:00
Changed channel capabilities to use commas.
This commit is contained in:
parent
23c2640a87
commit
4b1083931d
20
src/ircdb.py
20
src/ircdb.py
@ -48,36 +48,34 @@ from structures import PersistentDictionary
|
||||
|
||||
def fromChannelCapability(capability):
|
||||
"""Returns a (channel, capability) tuple from a channel capability."""
|
||||
if not isChannelCapability(capability):
|
||||
raise ValueError, '%s is not a channel capability' % capability
|
||||
#return capability.rsplit('.', 1)
|
||||
return rsplit(capability, '.', 1)
|
||||
assert isChannelCapability(capability)
|
||||
return capability.split(',', 1)
|
||||
|
||||
def isChannelCapability(capability):
|
||||
"""Returns True if capability is a channel capability; False otherwise."""
|
||||
if '.' in capability:
|
||||
(channel, capability) = capability.split('.', 1)
|
||||
if ',' in capability:
|
||||
(channel, capability) = capability.split(',', 1)
|
||||
return ircutils.isChannel(channel)
|
||||
else:
|
||||
return False
|
||||
|
||||
def makeChannelCapability(channel, capability):
|
||||
"""Makes a channel capability given a channel and a capability."""
|
||||
return '%s.%s' % (channel, capability)
|
||||
return '%s,%s' % (channel, capability)
|
||||
|
||||
def isAntiCapability(capability):
|
||||
"""Returns True if capability is an anticapability; False otherwise."""
|
||||
if isChannelCapability(capability):
|
||||
(_, capability) = fromChannelCapability(capability)
|
||||
return capability[0] == '-'
|
||||
return capability and capability[0] == '-'
|
||||
|
||||
def makeAntiCapability(capability):
|
||||
"""Returns the anticapability of a given capability."""
|
||||
assert not isAntiCapability(capability), 'makeAntiCapability does not ' \
|
||||
'work on anticapabilities; you probably want invertCapability.'
|
||||
if '.' in capability:
|
||||
if isChannelCapability(capability):
|
||||
(channel, capability) = fromChannelCapability(capability)
|
||||
return '%s.-%s' % (channel, capability)
|
||||
return makeChannelCapability(channel, '-' + capability)
|
||||
else:
|
||||
return '-' + capability
|
||||
|
||||
@ -87,7 +85,7 @@ def unAntiCapability(capability):
|
||||
raise ValueError, '%s is not an anti capability' % capability
|
||||
if isChannelCapability(capability):
|
||||
(channel, capability) = fromChannelCapability(capability)
|
||||
return '.'.join((channel, capability[1:]))
|
||||
return ','.join((channel, capability[1:]))
|
||||
else:
|
||||
return capability[1:]
|
||||
|
||||
|
@ -51,41 +51,44 @@ class IrcdbTestCase(unittest.TestCase):
|
||||
class FunctionsTestCase(IrcdbTestCase):
|
||||
def testIsAntiCapability(self):
|
||||
self.failIf(ircdb.isAntiCapability('foo'))
|
||||
self.failIf(ircdb.isAntiCapability('#foo.bar'))
|
||||
self.failIf(ircdb.isAntiCapability('#foo,bar'))
|
||||
self.failUnless(ircdb.isAntiCapability('-foo'))
|
||||
self.failUnless(ircdb.isAntiCapability('#foo.-bar'))
|
||||
self.failUnless(ircdb.isAntiCapability('#foo.bar.-baz'))
|
||||
self.failUnless(ircdb.isAntiCapability('#foo,-bar'))
|
||||
self.failUnless(ircdb.isAntiCapability('#foo.bar,-baz'))
|
||||
|
||||
def testIsChannelCapability(self):
|
||||
self.failIf(ircdb.isChannelCapability('foo'))
|
||||
self.failUnless(ircdb.isChannelCapability('#foo.bar'))
|
||||
self.failUnless(ircdb.isChannelCapability('#foo.bar.baz'))
|
||||
self.failUnless(ircdb.isChannelCapability('#foo,bar'))
|
||||
self.failUnless(ircdb.isChannelCapability('#foo.bar,baz'))
|
||||
self.failUnless(ircdb.isChannelCapability('#foo,bar.baz'))
|
||||
|
||||
def testMakeAntiCapability(self):
|
||||
self.assertEqual(ircdb.makeAntiCapability('foo'), '-foo')
|
||||
self.assertEqual(ircdb.makeAntiCapability('#foo.bar'), '#foo.-bar')
|
||||
self.assertEqual(ircdb.makeAntiCapability('#foo,bar'), '#foo,-bar')
|
||||
|
||||
def testMakeChannelCapability(self):
|
||||
self.assertEqual(ircdb.makeChannelCapability('#f', 'b'), '#f.b')
|
||||
self.assertEqual(ircdb.makeChannelCapability('#f', '-b'), '#f.-b')
|
||||
self.assertEqual(ircdb.makeChannelCapability('#f', 'b'), '#f,b')
|
||||
self.assertEqual(ircdb.makeChannelCapability('#f', '-b'), '#f,-b')
|
||||
|
||||
def testFromChannelCapability(self):
|
||||
self.assertEqual(ircdb.fromChannelCapability('#foo.bar'),
|
||||
self.assertEqual(ircdb.fromChannelCapability('#foo,bar'),
|
||||
['#foo', 'bar'])
|
||||
self.assertEqual(ircdb.fromChannelCapability('#foo.bar.baz'),
|
||||
self.assertEqual(ircdb.fromChannelCapability('#foo.bar,baz'),
|
||||
['#foo.bar', 'baz'])
|
||||
self.assertEqual(ircdb.fromChannelCapability('#foo,bar.baz'),
|
||||
['#foo', 'bar.baz'])
|
||||
|
||||
def testUnAntiCapability(self):
|
||||
self.assertEqual(ircdb.unAntiCapability('-bar'), 'bar')
|
||||
self.assertEqual(ircdb.unAntiCapability('#foo.-bar'), '#foo.bar')
|
||||
self.assertEqual(ircdb.unAntiCapability('#foo.bar.-baz'),
|
||||
'#foo.bar.baz')
|
||||
self.assertEqual(ircdb.unAntiCapability('#foo,-bar'), '#foo,bar')
|
||||
self.assertEqual(ircdb.unAntiCapability('#foo.bar,-baz'),
|
||||
'#foo.bar,baz')
|
||||
|
||||
def testInvertCapability(self):
|
||||
self.assertEqual(ircdb.invertCapability('bar'), '-bar')
|
||||
self.assertEqual(ircdb.invertCapability('-bar'), 'bar')
|
||||
self.assertEqual(ircdb.invertCapability('#foo.bar'), '#foo.-bar')
|
||||
self.assertEqual(ircdb.invertCapability('#foo.-bar'), '#foo.bar')
|
||||
self.assertEqual(ircdb.invertCapability('#foo,bar'), '#foo,-bar')
|
||||
self.assertEqual(ircdb.invertCapability('#foo,-bar'), '#foo,bar')
|
||||
|
||||
|
||||
class CapabilitySetTestCase(unittest.TestCase):
|
||||
|
Loading…
Reference in New Issue
Block a user