Tons of differences, moved some registry values around, also changed some internal attributes of registry thingies.

This commit is contained in:
Jeremy Fincher 2004-07-31 05:00:43 +00:00
parent f3ed778040
commit 9250d3ab32
8 changed files with 64 additions and 61 deletions

View File

@ -308,9 +308,8 @@ class Admin(privmsgs.CapabilityCheckingPrivmsg):
# Thus, the owner capability can't be given in the bot. Admin users # Thus, the owner capability can't be given in the bot. Admin users
# can only give out capabilities they have themselves (which will # can only give out capabilities they have themselves (which will
# depend on both conf.supybot.defaultAllow and # depend on supybot.capabilities and its child default) but generally
# conf.supybot.defaultCapabilities), but generally means they can't # means they can't mess with channel capabilities.
# mess with channel capabilities.
(name, capability) = privmsgs.getArgs(args, required=2) (name, capability) = privmsgs.getArgs(args, required=2)
if capability == 'owner': if capability == 'owner':
irc.error('The "owner" capability can\'t be added in the bot. ' irc.error('The "owner" capability can\'t be added in the bot. '

View File

@ -170,7 +170,7 @@ class Config(callbacks.Privmsg):
name = self._canonicalizeName(name) name = self._canonicalizeName(name)
wrapper = getWrapper(name) wrapper = getWrapper(name)
if hasattr(wrapper, 'value'): if hasattr(wrapper, 'value'):
if not wrapper.private: if not wrapper._private:
irc.reply(str(wrapper)) irc.reply(str(wrapper))
else: else:
capability = getCapability(name) capability = getCapability(name)

View File

@ -471,10 +471,10 @@ class User(callbacks.Privmsg):
irc.errorNoUser() irc.errorNoUser()
return return
list = False list = False
while '--list' in args: (optlist, args) = getopt.getopt(args, '', ['list'])
# XXX: Case-sensitive. for (option, arg) in optlist:
list = True if option == '--list':
args.remove('--list') list = True
if len(args) >= 2: if len(args) >= 2:
# We're setting. # We're setting.
pass pass

View File

@ -337,7 +337,7 @@ def checkCommandCapability(msg, cb, command):
checkCapability(antiCommand) checkCapability(antiCommand)
checkCapability(antiPluginCommand) checkCapability(antiPluginCommand)
checkAtEnd = [command, pluginCommand] checkAtEnd = [command, pluginCommand]
default = conf.supybot.defaultAllow() default = conf.supybot.capabilities.default()
if ircutils.isChannel(msg.args[0]): if ircutils.isChannel(msg.args[0]):
channel = msg.args[0] channel = msg.args[0]
checkCapability(ircdb.makeChannelCapability(channel, antiCommand)) checkCapability(ircdb.makeChannelCapability(channel, antiCommand))

View File

@ -257,7 +257,10 @@ class DefaultCapabilities(registry.SpaceSeparatedListOfStrings):
print '*** in your configuration file before start the bot.' print '*** in your configuration file before start the bot.'
self.value.add('-owner') self.value.add('-owner')
registerGlobalValue(supybot, 'defaultCapabilities', ###
# supybot.capabilities
###
registerGlobalValue(supybot, 'capabilities',
DefaultCapabilities(['-owner', '-admin', '-trusted'], """These are the DefaultCapabilities(['-owner', '-admin', '-trusted'], """These are the
capabilities that are given to everyone by default. If they are normal capabilities that are given to everyone by default. If they are normal
capabilities, then the user will have to have the appropriate capabilities, then the user will have to have the appropriate
@ -266,36 +269,11 @@ registerGlobalValue(supybot, 'defaultCapabilities',
to override these capabilities. See docs/CAPABILITIES if you don't to override these capabilities. See docs/CAPABILITIES if you don't
understand why these default to what they do.""")) understand why these default to what they do."""))
registerGlobalValue(supybot, 'defaultAllow', registerGlobalValue(supybot.capabilities, 'default',
registry.Boolean(True, """Determines whether the bot by default will allow registry.Boolean(True, """Determines whether the bot by default will allow
users to run commands. If this is disabled, a user will have to explicitly users to have a capability. If this is disabled, a user must explicitly
have the capability for whatever command he wishes to run.""")) have the capability for whatever command he wishes to run."""))
registerGlobalValue(supybot, 'defaultIgnore',
registry.Boolean(False, """Determines whether the bot will ignore
unregistered users by default. Of course, that'll make it particularly
hard for those users to register with the bot, but that's your problem to
solve."""))
registerGlobalValue(supybot, 'humanTimestampFormat',
registry.String('%I:%M %p, %B %d, %Y', """Determines how timestamps printed
for human reading should be formatted. Refer to the Python documentation
for the time module to see valid formatting characteres for time
formats."""))
class IP(registry.String):
"""Value must be a valid IP."""
def setValue(self, v):
if v and not (utils.isIP(v) or utils.isIPV6(v)):
self.error()
else:
registry.String.setValue(self, v)
registerGlobalValue(supybot, 'externalIP',
IP('', """A string that is the external IP of the bot. If this is the empty
string, the bot will attempt to find out its IP dynamically (though
sometimes that doesn't work, hence this variable)."""))
### ###
# Reply/error tweaking. # Reply/error tweaking.
### ###
@ -409,7 +387,7 @@ registerGlobalValue(supybot, 'alwaysJoinOnInvite',
a channel if the user inviting it has the 'admin' capability (or if it's a channel if the user inviting it has the 'admin' capability (or if it's
explicitly told to join the channel using the Admin.join command)""")) explicitly told to join the channel using the Admin.join command)"""))
# XXX: ChannelValue not respected for this. # XXX: ChannelValue-ishness is not respected for this yet.
registerChannelValue(supybot.reply, 'showSimpleSyntax', registerChannelValue(supybot.reply, 'showSimpleSyntax',
registry.Boolean(False, """Supybot normally replies with the full help registry.Boolean(False, """Supybot normally replies with the full help
whenever a user misuses a command. If this value is set to True, the bot whenever a user misuses a command. If this value is set to True, the bot
@ -657,6 +635,31 @@ registerGlobalValue(supybot.protocols.http, 'proxy',
### ###
# Especially boring stuff. # Especially boring stuff.
### ###
registerGlobalValue(supybot, 'defaultIgnore',
registry.Boolean(False, """Determines whether the bot will ignore
unregistered users by default. Of course, that'll make it particularly
hard for those users to register with the bot, but that's your problem to
solve."""))
registerGlobalValue(supybot, 'humanTimestampFormat',
registry.String('%I:%M %p, %B %d, %Y', """Determines how timestamps printed
for human reading should be formatted. Refer to the Python documentation
for the time module to see valid formatting characteres for time
formats."""))
class IP(registry.String):
"""Value must be a valid IP."""
def setValue(self, v):
if v and not (utils.isIP(v) or utils.isIPV6(v)):
self.error()
else:
registry.String.setValue(self, v)
registerGlobalValue(supybot, 'externalIP',
IP('', """A string that is the external IP of the bot. If this is the empty
string, the bot will attempt to find out its IP dynamically (though
sometimes that doesn't work, hence this variable)."""))
class SocketTimeout(registry.PositiveInteger): class SocketTimeout(registry.PositiveInteger):
"""Value must be an integer greater than supybot.drivers.poll and must be """Value must be an integer greater than supybot.drivers.poll and must be
greater than or equal to 1.""" greater than or equal to 1."""

View File

@ -926,12 +926,13 @@ def _checkCapabilityForUnknownUser(capability, users=users, channels=channels):
return _x(capability, c.defaultAllow) return _x(capability, c.defaultAllow)
except KeyError: except KeyError:
pass pass
if capability in conf.supybot.defaultCapabilities(): defaultCapabilities = conf.supybot.capabilities()
if capability in defaultCapabilities:
return True return True
elif invertCapability(capability) in conf.supybot.defaultCapabilities(): elif invertCapability(capability) in defaultCapabilities:
return False return False
else: else:
return _x(capability, conf.supybot.defaultAllow()) return _x(capability, conf.supybot.capabilities.default())
def checkCapability(hostmask, capability, users=users, channels=channels): def checkCapability(hostmask, capability, users=users, channels=channels):
"""Checks that the user specified by name/hostmask has the capabilty given. """Checks that the user specified by name/hostmask has the capabilty given.
@ -967,13 +968,13 @@ def checkCapability(hostmask, capability, users=users, channels=channels):
return c.checkCapability(capability) return c.checkCapability(capability)
else: else:
return _x(capability, c.defaultAllow) return _x(capability, c.defaultAllow)
defaultCapabilities = conf.supybot.defaultCapabilities() defaultCapabilities = conf.supybot.capabilities()
if capability in defaultCapabilities: if capability in defaultCapabilities:
return True return True
elif invertCapability(capability) in defaultCapabilities: elif invertCapability(capability) in defaultCapabilities:
return False return False
else: else:
return _x(capability, conf.supybot.defaultAllow()) return _x(capability, conf.supybot.capabilities.default())
def checkCapabilities(hostmask, capabilities, requireAll=False): def checkCapabilities(hostmask, capabilities, requireAll=False):

View File

@ -96,7 +96,7 @@ def close(registry, filename, annotated=True, helpOnceOnly=False):
lines.append('#\n') lines.append('#\n')
try: try:
original = value.value original = value.value
value.value = value.default value.value = value._default
lines.append('# Default value: %s\n' % value) lines.append('# Default value: %s\n' % value)
finally: finally:
value.value = original value.value = original
@ -121,7 +121,7 @@ def join(names):
class Group(object): class Group(object):
def __init__(self, supplyDefault=False): def __init__(self, supplyDefault=False):
self.name = 'unset' self._name = 'unset'
self.added = [] self.added = []
self.children = utils.InsensitivePreservingDict() self.children = utils.InsensitivePreservingDict()
self._lastModified = 0 self._lastModified = 0
@ -142,11 +142,11 @@ class Group(object):
raise ValueError, 'Groups have no value.' raise ValueError, 'Groups have no value.'
def __nonExistentEntry(self, attr): def __nonExistentEntry(self, attr):
s = '%s is not a valid entry in %s' % (attr, self.name) s = '%s is not a valid entry in %s' % (attr, self._name)
raise NonExistentRegistryEntry, s raise NonExistentRegistryEntry, s
def __makeChild(self, attr, s): def __makeChild(self, attr, s):
v = self.__class__(self.default, self.help) v = self.__class__(self._default, self.help)
v.set(s) v.set(s)
v.__class__ = self.X v.__class__ = self.X
v.supplyDefault = False v.supplyDefault = False
@ -168,12 +168,12 @@ class Group(object):
return self.__getattr__(attr) return self.__getattr__(attr)
def setName(self, name): def setName(self, name):
self.name = name self._name = name
if name in _cache and self._lastModified < _lastModified: if name in _cache and self._lastModified < _lastModified:
self.set(_cache[name]) self.set(_cache[name])
if self.supplyDefault: if self.supplyDefault:
for (k, v) in _cache.iteritems(): for (k, v) in _cache.iteritems():
if k.startswith(self.name): if k.startswith(self._name):
group = split(k)[-1] group = split(k)[-1]
try: try:
self.__makeChild(group, v) self.__makeChild(group, v)
@ -189,7 +189,7 @@ class Group(object):
if name not in self.children: # XXX Is this right? if name not in self.children: # XXX Is this right?
self.children[name] = node self.children[name] = node
self.added.append(name) self.added.append(name)
fullname = join([self.name, name]) fullname = join([self._name, name])
node.setName(fullname) node.setName(fullname)
return node return node
@ -212,7 +212,7 @@ class Group(object):
node = self.children[name] node = self.children[name]
if hasattr(node, 'value') or hasattr(node, 'help'): if hasattr(node, 'value') or hasattr(node, 'help'):
if node.__class__ is not self.X: if node.__class__ is not self.X:
L.append((node.name, node)) L.append((node._name, node))
if getChildren: if getChildren:
L.extend(node.getValues(getChildren, fullNames)) L.extend(node.getValues(getChildren, fullNames))
if not fullNames: if not fullNames:
@ -226,8 +226,8 @@ class Value(Group):
def __init__(self, default, help, def __init__(self, default, help,
private=False, showDefault=True, **kwargs): private=False, showDefault=True, **kwargs):
Group.__init__(self, **kwargs) Group.__init__(self, **kwargs)
self.default = default self._default = default
self.private = private self._private = private
self.showDefault = showDefault self.showDefault = showDefault
self.help = utils.normalizeWhitespace(help.strip()) self.help = utils.normalizeWhitespace(help.strip())
self.setValue(default) self.setValue(default)
@ -241,7 +241,7 @@ class Value(Group):
raise InvalidRegistryValue, utils.normalizeWhitespace(s) raise InvalidRegistryValue, utils.normalizeWhitespace(s)
def setName(self, *args): def setName(self, *args):
if self.name == 'unset': if self._name == 'unset':
self._lastModified = 0 self._lastModified = 0
Group.setName(self, *args) Group.setName(self, *args)
self._lastModified = time.time() self._lastModified = time.time()
@ -270,8 +270,8 @@ class Value(Group):
# This is simply prettier than naming this function get(self) # This is simply prettier than naming this function get(self)
def __call__(self): def __call__(self):
if _lastModified > self._lastModified: if _lastModified > self._lastModified:
if self.name in _cache: if self._name in _cache:
self.set(_cache[self.name]) self.set(_cache[self._name])
return self.value return self.value
class Boolean(Value): class Boolean(Value):

View File

@ -479,9 +479,9 @@ class CheckCapabilityTestCase(IrcdbTestCase):
def testNothing(self): def testNothing(self):
self.assertEqual(self.checkCapability(self.nothing, self.cap), self.assertEqual(self.checkCapability(self.nothing, self.cap),
conf.supybot.defaultAllow()) conf.supybot.capabilities.default())
self.assertEqual(self.checkCapability(self.nothing, self.anticap), self.assertEqual(self.checkCapability(self.nothing, self.anticap),
not conf.supybot.defaultAllow()) not conf.supybot.capabilities.default())
def testJustFoo(self): def testJustFoo(self):
self.failUnless(self.checkCapability(self.justfoo, self.cap)) self.failUnless(self.checkCapability(self.justfoo, self.cap))
@ -527,11 +527,11 @@ class CheckCapabilityTestCase(IrcdbTestCase):
u.setAuth(self.securefoo) u.setAuth(self.securefoo)
self.users.setUser(id, u) self.users.setUser(id, u)
try: try:
originalConfDefaultAllow = conf.supybot.defaultAllow() originalConfDefaultAllow = conf.supybot.capabilities.default()
conf.supybot.defaultAllow.set('False') conf.supybot.capabilities.default.set('False')
self.failIf(self.checkCapability('a' + self.securefoo, self.cap)) self.failIf(self.checkCapability('a' + self.securefoo, self.cap))
finally: finally:
conf.supybot.defaultAllow.set(str(originalConfDefaultAllow)) conf.supybot.capabilities.default.set(str(originalConfDefaultAllow))
# vim:set shiftwidth=4 tabstop=8 expandtab textwidth=78: # vim:set shiftwidth=4 tabstop=8 expandtab textwidth=78: