Changed channel capabilities to use commas.

This commit is contained in:
Jeremy Fincher 2004-01-20 21:53:13 +00:00
parent 23c2640a87
commit 4b1083931d
2 changed files with 27 additions and 26 deletions

View File

@ -48,36 +48,34 @@ from structures import PersistentDictionary
def fromChannelCapability(capability): def fromChannelCapability(capability):
"""Returns a (channel, capability) tuple from a channel capability.""" """Returns a (channel, capability) tuple from a channel capability."""
if not isChannelCapability(capability): assert isChannelCapability(capability)
raise ValueError, '%s is not a channel capability' % capability return capability.split(',', 1)
#return capability.rsplit('.', 1)
return rsplit(capability, '.', 1)
def isChannelCapability(capability): def isChannelCapability(capability):
"""Returns True if capability is a channel capability; False otherwise.""" """Returns True if capability is a channel capability; False otherwise."""
if '.' in capability: if ',' in capability:
(channel, capability) = capability.split('.', 1) (channel, capability) = capability.split(',', 1)
return ircutils.isChannel(channel) return ircutils.isChannel(channel)
else: else:
return False return False
def makeChannelCapability(channel, capability): def makeChannelCapability(channel, capability):
"""Makes a channel capability given a channel and a capability.""" """Makes a channel capability given a channel and a capability."""
return '%s.%s' % (channel, capability) return '%s,%s' % (channel, capability)
def isAntiCapability(capability): def isAntiCapability(capability):
"""Returns True if capability is an anticapability; False otherwise.""" """Returns True if capability is an anticapability; False otherwise."""
if isChannelCapability(capability): if isChannelCapability(capability):
(_, capability) = fromChannelCapability(capability) (_, capability) = fromChannelCapability(capability)
return capability[0] == '-' return capability and capability[0] == '-'
def makeAntiCapability(capability): def makeAntiCapability(capability):
"""Returns the anticapability of a given capability.""" """Returns the anticapability of a given capability."""
assert not isAntiCapability(capability), 'makeAntiCapability does not ' \ assert not isAntiCapability(capability), 'makeAntiCapability does not ' \
'work on anticapabilities; you probably want invertCapability.' 'work on anticapabilities; you probably want invertCapability.'
if '.' in capability: if isChannelCapability(capability):
(channel, capability) = fromChannelCapability(capability) (channel, capability) = fromChannelCapability(capability)
return '%s.-%s' % (channel, capability) return makeChannelCapability(channel, '-' + capability)
else: else:
return '-' + capability return '-' + capability
@ -87,7 +85,7 @@ def unAntiCapability(capability):
raise ValueError, '%s is not an anti capability' % capability raise ValueError, '%s is not an anti capability' % capability
if isChannelCapability(capability): if isChannelCapability(capability):
(channel, capability) = fromChannelCapability(capability) (channel, capability) = fromChannelCapability(capability)
return '.'.join((channel, capability[1:])) return ','.join((channel, capability[1:]))
else: else:
return capability[1:] return capability[1:]

View File

@ -51,41 +51,44 @@ class IrcdbTestCase(unittest.TestCase):
class FunctionsTestCase(IrcdbTestCase): class FunctionsTestCase(IrcdbTestCase):
def testIsAntiCapability(self): def testIsAntiCapability(self):
self.failIf(ircdb.isAntiCapability('foo')) 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'))
self.failUnless(ircdb.isAntiCapability('#foo.-bar')) self.failUnless(ircdb.isAntiCapability('#foo,-bar'))
self.failUnless(ircdb.isAntiCapability('#foo.bar.-baz')) self.failUnless(ircdb.isAntiCapability('#foo.bar,-baz'))
def testIsChannelCapability(self): def testIsChannelCapability(self):
self.failIf(ircdb.isChannelCapability('foo')) self.failIf(ircdb.isChannelCapability('foo'))
self.failUnless(ircdb.isChannelCapability('#foo.bar')) self.failUnless(ircdb.isChannelCapability('#foo,bar'))
self.failUnless(ircdb.isChannelCapability('#foo.bar.baz')) self.failUnless(ircdb.isChannelCapability('#foo.bar,baz'))
self.failUnless(ircdb.isChannelCapability('#foo,bar.baz'))
def testMakeAntiCapability(self): def testMakeAntiCapability(self):
self.assertEqual(ircdb.makeAntiCapability('foo'), '-foo') 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): 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): def testFromChannelCapability(self):
self.assertEqual(ircdb.fromChannelCapability('#foo.bar'), self.assertEqual(ircdb.fromChannelCapability('#foo,bar'),
['#foo', 'bar']) ['#foo', 'bar'])
self.assertEqual(ircdb.fromChannelCapability('#foo.bar.baz'), self.assertEqual(ircdb.fromChannelCapability('#foo.bar,baz'),
['#foo.bar', 'baz']) ['#foo.bar', 'baz'])
self.assertEqual(ircdb.fromChannelCapability('#foo,bar.baz'),
['#foo', 'bar.baz'])
def testUnAntiCapability(self): def testUnAntiCapability(self):
self.assertEqual(ircdb.unAntiCapability('-bar'), 'bar') self.assertEqual(ircdb.unAntiCapability('-bar'), 'bar')
self.assertEqual(ircdb.unAntiCapability('#foo.-bar'), '#foo.bar') self.assertEqual(ircdb.unAntiCapability('#foo,-bar'), '#foo,bar')
self.assertEqual(ircdb.unAntiCapability('#foo.bar.-baz'), self.assertEqual(ircdb.unAntiCapability('#foo.bar,-baz'),
'#foo.bar.baz') '#foo.bar,baz')
def testInvertCapability(self): def testInvertCapability(self):
self.assertEqual(ircdb.invertCapability('bar'), '-bar') self.assertEqual(ircdb.invertCapability('bar'), '-bar')
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): class CapabilitySetTestCase(unittest.TestCase):