diff --git a/src/Admin.py b/src/Admin.py index 6482e8745..973f982cb 100755 --- a/src/Admin.py +++ b/src/Admin.py @@ -308,9 +308,8 @@ class Admin(privmsgs.CapabilityCheckingPrivmsg): # Thus, the owner capability can't be given in the bot. Admin users # can only give out capabilities they have themselves (which will - # depend on both conf.supybot.defaultAllow and - # conf.supybot.defaultCapabilities), but generally means they can't - # mess with channel capabilities. + # depend on supybot.capabilities and its child default) but generally + # means they can't mess with channel capabilities. (name, capability) = privmsgs.getArgs(args, required=2) if capability == 'owner': irc.error('The "owner" capability can\'t be added in the bot. ' diff --git a/src/Config.py b/src/Config.py index 82772fd6d..5cb5dcfed 100644 --- a/src/Config.py +++ b/src/Config.py @@ -170,7 +170,7 @@ class Config(callbacks.Privmsg): name = self._canonicalizeName(name) wrapper = getWrapper(name) if hasattr(wrapper, 'value'): - if not wrapper.private: + if not wrapper._private: irc.reply(str(wrapper)) else: capability = getCapability(name) diff --git a/src/User.py b/src/User.py index cbb06e2fb..edc24f5fd 100755 --- a/src/User.py +++ b/src/User.py @@ -471,10 +471,10 @@ class User(callbacks.Privmsg): irc.errorNoUser() return list = False - while '--list' in args: - # XXX: Case-sensitive. - list = True - args.remove('--list') + (optlist, args) = getopt.getopt(args, '', ['list']) + for (option, arg) in optlist: + if option == '--list': + list = True if len(args) >= 2: # We're setting. pass diff --git a/src/callbacks.py b/src/callbacks.py index 896b7b9be..6913a6f50 100644 --- a/src/callbacks.py +++ b/src/callbacks.py @@ -337,7 +337,7 @@ def checkCommandCapability(msg, cb, command): checkCapability(antiCommand) checkCapability(antiPluginCommand) checkAtEnd = [command, pluginCommand] - default = conf.supybot.defaultAllow() + default = conf.supybot.capabilities.default() if ircutils.isChannel(msg.args[0]): channel = msg.args[0] checkCapability(ircdb.makeChannelCapability(channel, antiCommand)) diff --git a/src/conf.py b/src/conf.py index f9f2f6b15..9f0953db2 100644 --- a/src/conf.py +++ b/src/conf.py @@ -257,7 +257,10 @@ class DefaultCapabilities(registry.SpaceSeparatedListOfStrings): print '*** in your configuration file before start the bot.' self.value.add('-owner') -registerGlobalValue(supybot, 'defaultCapabilities', +### +# supybot.capabilities +### +registerGlobalValue(supybot, 'capabilities', DefaultCapabilities(['-owner', '-admin', '-trusted'], """These are the capabilities that are given to everyone by default. If they are normal 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 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 - 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.""")) -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. ### @@ -409,7 +387,7 @@ registerGlobalValue(supybot, 'alwaysJoinOnInvite', 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)""")) -# XXX: ChannelValue not respected for this. +# XXX: ChannelValue-ishness is not respected for this yet. registerChannelValue(supybot.reply, 'showSimpleSyntax', 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 @@ -657,6 +635,31 @@ registerGlobalValue(supybot.protocols.http, 'proxy', ### # 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): """Value must be an integer greater than supybot.drivers.poll and must be greater than or equal to 1.""" diff --git a/src/ircdb.py b/src/ircdb.py index 74b859b5d..331b75b49 100644 --- a/src/ircdb.py +++ b/src/ircdb.py @@ -926,12 +926,13 @@ def _checkCapabilityForUnknownUser(capability, users=users, channels=channels): return _x(capability, c.defaultAllow) except KeyError: pass - if capability in conf.supybot.defaultCapabilities(): + defaultCapabilities = conf.supybot.capabilities() + if capability in defaultCapabilities: return True - elif invertCapability(capability) in conf.supybot.defaultCapabilities(): + elif invertCapability(capability) in defaultCapabilities: return False else: - return _x(capability, conf.supybot.defaultAllow()) + return _x(capability, conf.supybot.capabilities.default()) def checkCapability(hostmask, capability, users=users, channels=channels): """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) else: return _x(capability, c.defaultAllow) - defaultCapabilities = conf.supybot.defaultCapabilities() + defaultCapabilities = conf.supybot.capabilities() if capability in defaultCapabilities: return True elif invertCapability(capability) in defaultCapabilities: return False else: - return _x(capability, conf.supybot.defaultAllow()) + return _x(capability, conf.supybot.capabilities.default()) def checkCapabilities(hostmask, capabilities, requireAll=False): diff --git a/src/registry.py b/src/registry.py index e18a8156c..8308f86d0 100644 --- a/src/registry.py +++ b/src/registry.py @@ -96,7 +96,7 @@ def close(registry, filename, annotated=True, helpOnceOnly=False): lines.append('#\n') try: original = value.value - value.value = value.default + value.value = value._default lines.append('# Default value: %s\n' % value) finally: value.value = original @@ -121,7 +121,7 @@ def join(names): class Group(object): def __init__(self, supplyDefault=False): - self.name = 'unset' + self._name = 'unset' self.added = [] self.children = utils.InsensitivePreservingDict() self._lastModified = 0 @@ -142,11 +142,11 @@ class Group(object): raise ValueError, 'Groups have no value.' 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 def __makeChild(self, attr, s): - v = self.__class__(self.default, self.help) + v = self.__class__(self._default, self.help) v.set(s) v.__class__ = self.X v.supplyDefault = False @@ -168,12 +168,12 @@ class Group(object): return self.__getattr__(attr) def setName(self, name): - self.name = name + self._name = name if name in _cache and self._lastModified < _lastModified: self.set(_cache[name]) if self.supplyDefault: for (k, v) in _cache.iteritems(): - if k.startswith(self.name): + if k.startswith(self._name): group = split(k)[-1] try: self.__makeChild(group, v) @@ -189,7 +189,7 @@ class Group(object): if name not in self.children: # XXX Is this right? self.children[name] = node self.added.append(name) - fullname = join([self.name, name]) + fullname = join([self._name, name]) node.setName(fullname) return node @@ -212,7 +212,7 @@ class Group(object): node = self.children[name] if hasattr(node, 'value') or hasattr(node, 'help'): if node.__class__ is not self.X: - L.append((node.name, node)) + L.append((node._name, node)) if getChildren: L.extend(node.getValues(getChildren, fullNames)) if not fullNames: @@ -226,8 +226,8 @@ class Value(Group): def __init__(self, default, help, private=False, showDefault=True, **kwargs): Group.__init__(self, **kwargs) - self.default = default - self.private = private + self._default = default + self._private = private self.showDefault = showDefault self.help = utils.normalizeWhitespace(help.strip()) self.setValue(default) @@ -241,7 +241,7 @@ class Value(Group): raise InvalidRegistryValue, utils.normalizeWhitespace(s) def setName(self, *args): - if self.name == 'unset': + if self._name == 'unset': self._lastModified = 0 Group.setName(self, *args) self._lastModified = time.time() @@ -270,8 +270,8 @@ class Value(Group): # This is simply prettier than naming this function get(self) def __call__(self): if _lastModified > self._lastModified: - if self.name in _cache: - self.set(_cache[self.name]) + if self._name in _cache: + self.set(_cache[self._name]) return self.value class Boolean(Value): diff --git a/test/test_ircdb.py b/test/test_ircdb.py index 44e7d4423..dd8710420 100644 --- a/test/test_ircdb.py +++ b/test/test_ircdb.py @@ -479,9 +479,9 @@ class CheckCapabilityTestCase(IrcdbTestCase): def testNothing(self): self.assertEqual(self.checkCapability(self.nothing, self.cap), - conf.supybot.defaultAllow()) + conf.supybot.capabilities.default()) self.assertEqual(self.checkCapability(self.nothing, self.anticap), - not conf.supybot.defaultAllow()) + not conf.supybot.capabilities.default()) def testJustFoo(self): self.failUnless(self.checkCapability(self.justfoo, self.cap)) @@ -527,11 +527,11 @@ class CheckCapabilityTestCase(IrcdbTestCase): u.setAuth(self.securefoo) self.users.setUser(id, u) try: - originalConfDefaultAllow = conf.supybot.defaultAllow() - conf.supybot.defaultAllow.set('False') + originalConfDefaultAllow = conf.supybot.capabilities.default() + conf.supybot.capabilities.default.set('False') self.failIf(self.checkCapability('a' + self.securefoo, self.cap)) finally: - conf.supybot.defaultAllow.set(str(originalConfDefaultAllow)) + conf.supybot.capabilities.default.set(str(originalConfDefaultAllow)) # vim:set shiftwidth=4 tabstop=8 expandtab textwidth=78: