mirror of
https://github.com/Mikaela/Limnoria.git
synced 2024-11-27 13:19:24 +01:00
Fixed bug with reloading of sets module.
This commit is contained in:
parent
33775aea0d
commit
aae6f52c9e
33
src/ircdb.py
33
src/ircdb.py
@ -100,31 +100,32 @@ def _normalize(s):
|
|||||||
return s.translate(_normal)
|
return s.translate(_normal)
|
||||||
|
|
||||||
|
|
||||||
|
_invert = invertCapability
|
||||||
class CapabilitySet(sets.Set):
|
class CapabilitySet(sets.Set):
|
||||||
"""A subclass of set handling basic capability stuff."""
|
"""A subclass of set handling basic capability stuff."""
|
||||||
def __init__(self, capabilities=()):
|
def __init__(self, capabilities=()):
|
||||||
sets.Set.__init__(self)
|
super(CapabilitySet, self).__init__()
|
||||||
for capability in capabilities:
|
for capability in capabilities:
|
||||||
self.add(capability)
|
self.add(capability)
|
||||||
|
|
||||||
def add(self, capability):
|
def add(self, capability):
|
||||||
"""Adds a capability to the set."""
|
"""Adds a capability to the set."""
|
||||||
capability = ircutils.toLower(capability)
|
capability = ircutils.toLower(capability)
|
||||||
inverted = invertCapability(capability)
|
inverted = _invert(capability)
|
||||||
if sets.Set.__contains__(self, inverted):
|
if super(CapabilitySet, self).__contains__(inverted):
|
||||||
sets.Set.remove(self, inverted)
|
super(CapabilitySet, self).remove(inverted)
|
||||||
sets.Set.add(self, capability)
|
super(CapabilitySet, self).add(capability)
|
||||||
|
|
||||||
def remove(self, capability):
|
def remove(self, capability):
|
||||||
"""Removes a capability from the set."""
|
"""Removes a capability from the set."""
|
||||||
capability = ircutils.toLower(capability)
|
capability = ircutils.toLower(capability)
|
||||||
sets.Set.remove(self, capability)
|
super(CapabilitySet, self).remove(capability)
|
||||||
|
|
||||||
def __contains__(self, capability):
|
def __contains__(self, capability):
|
||||||
capability = ircutils.toLower(capability)
|
capability = ircutils.toLower(capability)
|
||||||
if sets.Set.__contains__(self, capability):
|
if super(CapabilitySet, self).__contains__(capability):
|
||||||
return True
|
return True
|
||||||
if sets.Set.__contains__(self, invertCapability(capability)):
|
if super(CapabilitySet, self).__contains__(_invert(capability)):
|
||||||
return True
|
return True
|
||||||
else:
|
else:
|
||||||
return False
|
return False
|
||||||
@ -134,9 +135,9 @@ class CapabilitySet(sets.Set):
|
|||||||
'allowed' given its (or its anticapability's) presence in the set.
|
'allowed' given its (or its anticapability's) presence in the set.
|
||||||
"""
|
"""
|
||||||
capability = ircutils.toLower(capability)
|
capability = ircutils.toLower(capability)
|
||||||
if sets.Set.__contains__(self, capability):
|
if super(CapabilitySet, self).__contains__(capability):
|
||||||
return True
|
return True
|
||||||
elif sets.Set.__contains__(self, invertCapability(capability)):
|
elif super(CapabilitySet, self).__contains__(_invert(capability)):
|
||||||
return False
|
return False
|
||||||
else:
|
else:
|
||||||
raise KeyError, capability
|
raise KeyError, capability
|
||||||
@ -152,10 +153,10 @@ class UserCapabilitySet(CapabilitySet):
|
|||||||
capability = ircutils.toLower(capability)
|
capability = ircutils.toLower(capability)
|
||||||
if capability == 'owner' or capability == antiOwner:
|
if capability == 'owner' or capability == antiOwner:
|
||||||
return True
|
return True
|
||||||
elif CapabilitySet.__contains__(self, 'owner'):
|
elif super(UserCapabilitySet, self).__contains__('owner'):
|
||||||
return True
|
return True
|
||||||
else:
|
else:
|
||||||
return CapabilitySet.__contains__(self, capability)
|
return super(UserCapabilitySet, self).__contains__(capability)
|
||||||
|
|
||||||
def check(self, capability):
|
def check(self, capability):
|
||||||
"""Returns the appropriate boolean for whether a given capability is
|
"""Returns the appropriate boolean for whether a given capability is
|
||||||
@ -165,23 +166,23 @@ class UserCapabilitySet(CapabilitySet):
|
|||||||
"""
|
"""
|
||||||
capability = ircutils.toLower(capability)
|
capability = ircutils.toLower(capability)
|
||||||
if capability == 'owner' or capability == antiOwner:
|
if capability == 'owner' or capability == antiOwner:
|
||||||
if CapabilitySet.__contains__(self, 'owner'):
|
if super(UserCapabilitySet, self).__contains__('owner'):
|
||||||
return not isAntiCapability(capability)
|
return not isAntiCapability(capability)
|
||||||
else:
|
else:
|
||||||
return isAntiCapability(capability)
|
return isAntiCapability(capability)
|
||||||
elif CapabilitySet.__contains__(self, 'owner'):
|
elif super(UserCapabilitySet, self).__contains__('owner'):
|
||||||
if isAntiCapability(capability):
|
if isAntiCapability(capability):
|
||||||
return False
|
return False
|
||||||
else:
|
else:
|
||||||
return True
|
return True
|
||||||
else:
|
else:
|
||||||
return CapabilitySet.check(self, capability)
|
return super(UserCapabilitySet, self).check(capability)
|
||||||
|
|
||||||
def add(self, capability):
|
def add(self, capability):
|
||||||
"""Adds a capability to the set. Just make sure it's not -owner."""
|
"""Adds a capability to the set. Just make sure it's not -owner."""
|
||||||
capability = ircutils.toLower(capability)
|
capability = ircutils.toLower(capability)
|
||||||
assert capability != '-owner', '"-owner" disallowed.'
|
assert capability != '-owner', '"-owner" disallowed.'
|
||||||
CapabilitySet.add(self, capability)
|
super(UserCapabilitySet, self).add(capability)
|
||||||
|
|
||||||
class IrcUser(object):
|
class IrcUser(object):
|
||||||
"""This class holds the capabilities and authentications for a user."""
|
"""This class holds the capabilities and authentications for a user."""
|
||||||
|
Loading…
Reference in New Issue
Block a user