Changed the needed= keyword arg in privmsgs.getArgs to required=.

This commit is contained in:
Jeremy Fincher 2003-11-11 13:20:06 +00:00
parent 86e2110010
commit 2e0b225d0c
28 changed files with 81 additions and 81 deletions

View File

@ -105,7 +105,7 @@ def makeNewAlias(name, alias):
tokens = callbacks.tokenize(alias)
if not wildcard and biggestDollar or biggestAt:
args = privmsgs.getArgs(args,
needed=biggestDollar,
required=biggestDollar,
optional=biggestAt)
# Gotta have a mutable sequence (for replace).
if biggestDollar + biggestAt == 1: # We got a string, no tuple.
@ -242,7 +242,7 @@ class Alias(callbacks.Privmsg):
format. Underscores can be used to represent arguments to the alias
itself; for instance ...
"""
(name, alias) = privmsgs.getArgs(args, needed=2)
(name, alias) = privmsgs.getArgs(args, required=2)
try:
self.addAlias(irc, name, alias)
irc.reply(msg, conf.replySuccess)

View File

@ -69,7 +69,7 @@ class Babelfish(callbacks.Privmsg):
Returns <text> translated from <from-language> into <to-language>.
"""
(fromLang, toLang, text) = privmsgs.getArgs(args, needed=3)
(fromLang, toLang, text) = privmsgs.getArgs(args, required=3)
try:
fromLang = self._abbrevs[fromLang.lower()]
toLang = self._abbrevs[toLang.lower()]
@ -92,7 +92,7 @@ class Babelfish(callbacks.Privmsg):
until it doesn't change anymore or 12 times, whichever is fewer. One
of the languages must be English.
"""
(fromLang, toLang, text) = privmsgs.getArgs(args, needed=3)
(fromLang, toLang, text) = privmsgs.getArgs(args, required=3)
try:
fromLang = self._abbrevs[fromLang.lower()]
toLang = self._abbrevs[toLang.lower()]
@ -117,7 +117,7 @@ class Babelfish(callbacks.Privmsg):
Returns a random language supported by babelfish. If <allow-english>
is provided, will include English in the list of possible languages.
"""
allowEnglish = privmsgs.getArgs(args, needed=0, optional=1)
allowEnglish = privmsgs.getArgs(args, required=0, optional=1)
language = random.choice(babelfish.available_languages)
while not allowEnglish and language == 'English':
language = random.choice(babelfish.available_languages)

View File

@ -118,7 +118,7 @@ class Bugzilla(callbacks.PrivmsgCommandAndRegexp, plugins.Configurable):
commands. <description> is the common name for the bugzilla and will
be listed with the bugzilla query.
"""
(shorthand, url, description) = privmsgs.getArgs(args, needed=3)
(shorthand, url, description) = privmsgs.getArgs(args, required=3)
cursor = self.db.cursor()
cursor.execute("""INSERT INTO bugzillas VALUES (%s, %s, %s)""",
shorthand, url, description)
@ -153,7 +153,7 @@ class Bugzilla(callbacks.PrivmsgCommandAndRegexp, plugins.Configurable):
List defined bugzillae. If <abbreviation> is specified, list the
information for that bugzilla.
"""
shorthand = privmsgs.getArgs(args, needed=0, optional=1)
shorthand = privmsgs.getArgs(args, required=0, optional=1)
if shorthand:
cursor = self.db.cursor()
cursor.execute("""SELECT url,description from bugzillas where
@ -205,7 +205,7 @@ class Bugzilla(callbacks.PrivmsgCommandAndRegexp, plugins.Configurable):
Look up bug <number> in the bugzilla associated with <abbreviation>.
"""
(shorthand, num) = privmsgs.getArgs(args, needed=2)
(shorthand, num) = privmsgs.getArgs(args, required=2)
cursor = self.db.cursor()
cursor.execute("""SELECT url,description from bugzillas where
shorthand = %s""", shorthand)

View File

@ -385,7 +385,7 @@ class ChannelDB(plugins.ChannelDBHandler, # Must be first (die).
isn't given, it defaults to the user sending the command.
"""
channel = privmsgs.getChannel(msg, args)
name = privmsgs.getArgs(args, needed=0, optional=1)
name = privmsgs.getArgs(args, required=0, optional=1)
if not name:
try:
id = ircdb.users.getUserId(msg.prefix)
@ -483,7 +483,7 @@ class ChannelDB(plugins.ChannelDBHandler, # Must be first (die).
available for that word, do we assume it's <user>.)
"""
channel = privmsgs.getChannel(msg, args)
(arg1, arg2) = privmsgs.getArgs(args, needed=0, optional=2)
(arg1, arg2) = privmsgs.getArgs(args, required=0, optional=2)
db = self.getDb(channel)
cursor = db.cursor()
if not arg1 and not arg2:

View File

@ -99,7 +99,7 @@ class Dunno(callbacks.Privmsg):
except KeyError:
irc.error(msg, conf.replyNotRegistered)
return
text = privmsgs.getArgs(args, needed=1)
text = privmsgs.getArgs(args, required=1)
cursor = self.db.cursor()
cursor.execute("""INSERT INTO dunnos
VALUES(NULL, %s, %s, %s)""",
@ -118,7 +118,7 @@ class Dunno(callbacks.Privmsg):
except KeyError:
irc.error(msg, conf.replyNotRegistered)
return
dunno_id = privmsgs.getArgs(args, needed=1)
dunno_id = privmsgs.getArgs(args, required=1)
cursor = self.db.cursor()
cursor.execute("""SELECT added_by, dunno
FROM dunnos
@ -142,7 +142,7 @@ class Dunno(callbacks.Privmsg):
Search for dunno containing the given text. Returns the ids of the
dunnos with the text in them.
"""
text = privmsgs.getArgs(args, needed=1)
text = privmsgs.getArgs(args, required=1)
glob = "%" + text + "%"
cursor = self.db.cursor()
cursor.execute("""SELECT id FROM dunnos
@ -160,7 +160,7 @@ class Dunno(callbacks.Privmsg):
Display the text of the dunno with the given id.
"""
id = privmsgs.getArgs(args, needed=1)
id = privmsgs.getArgs(args, required=1)
try:
id = int(id)
except ValueError:

View File

@ -84,7 +84,7 @@ class Enforcer(callbacks.Privmsg, plugins.Configurable):
to in other bots as 'bitch mode.') It defaults to True.
"""
self.topics = {}
(chanserv, revenge) = privmsgs.getArgs(args, needed=0, optional=2)
(chanserv, revenge) = privmsgs.getArgs(args, required=0, optional=2)
self.chanserv = chanserv or 'ChanServ'
self.started = True
revenge = revenge.capitalize()

View File

@ -321,7 +321,7 @@ class Factoids(plugins.ChannelDBHandler, callbacks.Privmsg):
<regexp>.
"""
channel = privmsgs.getChannel(msg, args)
(key, number, regexp) = privmsgs.getArgs(args, needed=3)
(key, number, regexp) = privmsgs.getArgs(args, required=3)
try:
replacer = utils.perlReToReplacer(regexp)
except ValueError, e:

View File

@ -85,7 +85,7 @@ class Fun(callbacks.Privmsg):
given, unsets the outFilter. <channel> is only necessary if the
message isn't sent in the channel itself.
"""
command = privmsgs.getArgs(args, needed=0, optional=1)
command = privmsgs.getArgs(args, required=0, optional=1)
if command:
command = callbacks.canonicalName(command)
if command in self._filterCommands:
@ -152,7 +152,7 @@ class Fun(callbacks.Privmsg):
Converts from base <base> the number <number>
"""
(base, number) = privmsgs.getArgs(args, needed=2)
(base, number) = privmsgs.getArgs(args, required=2)
irc.reply(msg, str(long(number, int(base))))
def binary(self, irc, msg, args):
@ -186,7 +186,7 @@ class Fun(callbacks.Privmsg):
available in the documentation of the Python codecs module:
<http://www.python.org/doc/lib/node126.html>.
"""
encoding, text = privmsgs.getArgs(args, needed=2)
encoding, text = privmsgs.getArgs(args, required=2)
irc.reply(msg, text.encode(encoding))
def decode(self, irc, msg, args):
@ -196,7 +196,7 @@ class Fun(callbacks.Privmsg):
available in the documentation of the Python codecs module:
<http://www.python.org/doc/lib/node126.html>.
"""
encoding, text = privmsgs.getArgs(args, needed=2)
encoding, text = privmsgs.getArgs(args, required=2)
irc.reply(msg, text.decode(encoding).encode('utf-8'))
def hexlify(self, irc, msg, args):
@ -410,7 +410,7 @@ class Fun(callbacks.Privmsg):
Returns the levenshtein distance (also known as the "edit distance"
between <string1> and <string2>
"""
(s1, s2) = privmsgs.getArgs(args, needed=2)
(s1, s2) = privmsgs.getArgs(args, required=2)
irc.reply(msg, str(utils.distance(s1, s2)))
def soundex(self, irc, msg, args):

View File

@ -184,7 +184,7 @@ class FunDB(callbacks.Privmsg):
Gives you a standard, random BOFH excuse or the excuse with the given
<id>.
"""
id = privmsgs.getArgs(args, needed=0, optional=1)
id = privmsgs.getArgs(args, required=0, optional=1)
cursor = self.db.cursor()
if id:
try:
@ -218,7 +218,7 @@ class FunDB(callbacks.Privmsg):
when it used that lart against, say, jemfinch, to say '/me slices
jemfinch in half with a free AOL cd'
"""
(table, s) = privmsgs.getArgs(args, needed=2)
(table, s) = privmsgs.getArgs(args, required=2)
table = table.lower()
try:
name = ircdb.users.getUser(msg.prefix).name
@ -250,7 +250,7 @@ class FunDB(callbacks.Privmsg):
Removes the data, referred to in the first argument, with the id
number <id> from the database.
"""
(table, id) = privmsgs.getArgs(args, needed=2)
(table, id) = privmsgs.getArgs(args, required=2)
table = table.lower()
try:
ircdb.users.getUser(msg.prefix).name
@ -280,7 +280,7 @@ class FunDB(callbacks.Privmsg):
zero-based index into the db; <regexp> is a regular expression of the
form s/regexp/replacement/flags.
"""
(table, id, regexp) = privmsgs.getArgs(args, needed=3)
(table, id, regexp) = privmsgs.getArgs(args, required=3)
table = table.lower()
try:
name = ircdb.users.getUser(msg.prefix).name
@ -341,7 +341,7 @@ class FunDB(callbacks.Privmsg):
Gets the record with id <id> from the table specified.
"""
(table, id) = privmsgs.getArgs(args, needed=2)
(table, id) = privmsgs.getArgs(args, required=2)
table = table.lower()
try:
id = int(id)
@ -366,7 +366,7 @@ class FunDB(callbacks.Privmsg):
Gets the info for the record with id <id> from the table specified.
"""
(table, id) = privmsgs.getArgs(args, needed=2)
(table, id) = privmsgs.getArgs(args, required=2)
table = table.lower()
try:
id = int(id)

View File

@ -113,7 +113,7 @@ class Lookup(callbacks.Privmsg):
for in conf.dataDir. Use 'lookup <name> <key>' to get the value of
the key in the file.
"""
(name, filename) = privmsgs.getArgs(args, needed=2)
(name, filename) = privmsgs.getArgs(args, required=2)
db = getDb()
cursor = db.cursor()
try:

View File

@ -213,7 +213,7 @@ class Math(callbacks.Privmsg):
n = args.pop(0)
else:
n = 1
(unit1, to, unit2) = privmsgs.getArgs(args, needed=3)
(unit1, to, unit2) = privmsgs.getArgs(args, required=3)
if to != 'to':
raise callbacks.ArgumentError
try:

View File

@ -368,7 +368,7 @@ class MoobotFactoids(callbacks.PrivmsgCommandAndRegexp):
Returns the literal factoid for the given factoid key. No parsing of
the factoid value is done as it is with normal retrieval.
"""
key = privmsgs.getArgs(args, needed=1)
key = privmsgs.getArgs(args, required=1)
cursor = self.db.cursor()
cursor.execute("""SELECT fact FROM factoids WHERE key LIKE %s""", key)
if cursor.rowcount == 0:
@ -383,7 +383,7 @@ class MoobotFactoids(callbacks.PrivmsgCommandAndRegexp):
Returns the various bits of info on the factoid for the given key.
"""
key = privmsgs.getArgs(args, needed=1)
key = privmsgs.getArgs(args, required=1)
# Start building the response string
s = key + ": "
# Next, get all the info and build the response piece by piece
@ -433,7 +433,7 @@ class MoobotFactoids(callbacks.PrivmsgCommandAndRegexp):
except KeyError:
irc.error(msg, conf.replyNotRegistered)
return
key = privmsgs.getArgs(args, needed=1)
key = privmsgs.getArgs(args, required=1)
cursor = self.db.cursor()
cursor.execute("""SELECT created_by, locked_by FROM factoids
WHERE key LIKE %s""", key)
@ -545,7 +545,7 @@ class MoobotFactoids(callbacks.PrivmsgCommandAndRegexp):
author has an integer name, you'll have to use that author's id to use
this function (so don't use integer usernames!).
"""
author = privmsgs.getArgs(args, needed=1)
author = privmsgs.getArgs(args, required=1)
try:
id = ircdb.users.getUserId(author)
except KeyError:
@ -568,7 +568,7 @@ class MoobotFactoids(callbacks.PrivmsgCommandAndRegexp):
Lists the keys of the factoids whose key contains the provided text.
"""
search = privmsgs.getArgs(args, needed=1)
search = privmsgs.getArgs(args, required=1)
glob = '%' + search + '%'
cursor = self.db.cursor()
cursor.execute("""SELECT key FROM factoids
@ -588,7 +588,7 @@ class MoobotFactoids(callbacks.PrivmsgCommandAndRegexp):
Lists the keys of the factoids whose value contains the provided text.
"""
search = privmsgs.getArgs(args, needed=1)
search = privmsgs.getArgs(args, required=1)
glob = '%' + search + '%'
cursor = self.db.cursor()
cursor.execute("""SELECT key FROM factoids
@ -614,7 +614,7 @@ class MoobotFactoids(callbacks.PrivmsgCommandAndRegexp):
except KeyError:
irc.error(msg, conf.replyNotRegistered)
return
key = privmsgs.getArgs(args, needed=1)
key = privmsgs.getArgs(args, required=1)
cursor = self.db.cursor()
cursor.execute("""SELECT key, locked_at FROM factoids
WHERE key LIKE %s""", key)

View File

@ -153,7 +153,7 @@ class News(plugins.ChannelDBHandler, callbacks.Privmsg):
in the channel itself.
"""
channel = privmsgs.getChannel(msg, args)
number = privmsgs.getArgs(args, needed=0, optional=1)
number = privmsgs.getArgs(args, required=0, optional=1)
if number:
self._readnews(irc, msg, [channel, number])
return
@ -195,7 +195,7 @@ class News(plugins.ChannelDBHandler, callbacks.Privmsg):
s/text/replacement/flags. <channel> is only necessary if the message
isn't sent on the channel itself.
"""
(id, regexp) = privmsgs.getArgs(args, needed=2)
(id, regexp) = privmsgs.getArgs(args, required=2)
try:
replacer = utils.perlReToReplacer(regexp)
except ValueError, e:
@ -224,7 +224,7 @@ class News(plugins.ChannelDBHandler, callbacks.Privmsg):
is only necessary if the message isn't sent in the channel itself.
"""
channel = privmsgs.getChannel(msg, args)
id = privmsgs.getArgs(args, needed=0, optional=1)
id = privmsgs.getArgs(args, required=0, optional=1)
db = self.getDb(channel)
cursor = db.cursor()
if id:

View File

@ -114,7 +114,7 @@ class Note(callbacks.Privmsg):
Sends a new note to the user specified.
"""
(name, note) = privmsgs.getArgs(args, needed=2)
(name, note) = privmsgs.getArgs(args, required=2)
if ircdb.users.hasUser(name):
toId = ircdb.users.getUserId(name)
else:

View File

@ -179,7 +179,7 @@ class Poll(callbacks.Privmsg):
Vote yes or no on an active poll with the given id. This command can
also be used to override the previous vote.
"""
(id, vote) = privmsgs.getArgs(args, needed=2)
(id, vote) = privmsgs.getArgs(args, required=2)
try:
id = int(id)
except ValueError:

View File

@ -167,7 +167,7 @@ class Relay(callbacks.Privmsg, plugins.Configurable):
if not self.started:
irc.error(msg, 'You must use the start command first.')
return
abbreviation, server = privmsgs.getArgs(args, needed=2)
abbreviation, server = privmsgs.getArgs(args, required=2)
if isinstance(irc, irclib.Irc):
realIrc = irc
else:

View File

@ -78,7 +78,7 @@ class Services(privmsgs.CapabilityCheckingPrivmsg):
irc.error(msg, conf.replyRequiresPrivacy)
return
(self.nick, self.password, nickserv, chanserv) = \
privmsgs.getArgs(args, needed=2, optional=2)
privmsgs.getArgs(args, required=2, optional=2)
self.nick = ircutils.IrcString(self.nick)
self.nickserv = ircutils.IrcString(nickserv or 'NickServ')
self.chanserv = ircutils.IrcString(chanserv or 'ChanServ')

View File

@ -177,7 +177,7 @@ class Sourceforge(callbacks.PrivmsgCommandAndRegexp, plugins.Configurable):
Returns a list of the most recent bugs filed against <project>.
Defaults to searching for bugs in the project set by defaultproject.
"""
project = privmsgs.getArgs(args, needed=0, optional=1)
project = privmsgs.getArgs(args, required=0, optional=1)
if not project:
project = self.configurables.get('default-project', msg.args[0])
if not project:
@ -221,7 +221,7 @@ class Sourceforge(callbacks.PrivmsgCommandAndRegexp, plugins.Configurable):
Returns a list of the most recent RFEs filed against <project>.
Defaults to searching for RFEs in the project set by defaultproject.
"""
project = privmsgs.getArgs(args, needed=0, optional=1)
project = privmsgs.getArgs(args, required=0, optional=1)
if not project:
project = self.configurables.get('default-project', msg.args[0])
if not project:

View File

@ -95,7 +95,7 @@ class Todo(callbacks.Privmsg):
will return a list of task ids that that user has added to their todo
list.
"""
arg = privmsgs.getArgs(args, needed=0, optional=1)
arg = privmsgs.getArgs(args, required=0, optional=1)
userid = None
taskid = None
@ -186,7 +186,7 @@ class Todo(callbacks.Privmsg):
except ValueError, e:
irc.error(msg, '%r is an invalid priority' % arg)
return
text = privmsgs.getArgs(rest, needed=1)
text = privmsgs.getArgs(rest, required=1)
cursor = self.db.cursor()
cursor.execute("""INSERT INTO todo
VALUES (NULL, %s, %s, %s, %s, 1)""",
@ -205,7 +205,7 @@ class Todo(callbacks.Privmsg):
irc.error(msg, conf.replyNotRegistered)
return
taskid = privmsgs.getArgs(args, needed=1)
taskid = privmsgs.getArgs(args, required=1)
cursor = self.db.cursor()
cursor.execute("""SELECT * FROM todo
WHERE id = %s AND userid = %s
@ -277,7 +277,7 @@ class Todo(callbacks.Privmsg):
except KeyError:
irc.error(msg, conf.replyNotRegistered)
return
(id, priority) = privmsgs.getArgs(args, needed=2)
(id, priority) = privmsgs.getArgs(args, required=2)
cursor = self.db.cursor()
cursor.execute("""SELECT userid, priority FROM todo
WHERE id = %s AND active = 1""", id)
@ -304,7 +304,7 @@ class Todo(callbacks.Privmsg):
except KeyError:
irc.error(msg, conf.replyNotRegistered)
return
taskid, regexp = privmsgs.getArgs(args, needed=2)
taskid, regexp = privmsgs.getArgs(args, required=2)
# Check the regexp first, it's easier and doesn't require a db query
try:
replacer = utils.perlReToReplacer(regexp)

View File

@ -138,7 +138,7 @@ class Topic(callbacks.Privmsg):
s/regexp/replacement/flags. <channel> is only necessary if the message
isn't sent in the channel itself.
"""
(number, regexp) = privmsgs.getArgs(args, needed=2)
(number, regexp) = privmsgs.getArgs(args, required=2)
try:
number = int(number)
if number > 0:

View File

@ -71,7 +71,7 @@ class Utilities(callbacks.Privmsg):
<text>. The first and second arguments must necessarily be the same
length.
"""
(bad, good, text) = privmsgs.getArgs(args, needed=3)
(bad, good, text) = privmsgs.getArgs(args, required=3)
irc.reply(msg, text.translate(string.maketrans(bad, good)))
def strupper(self, irc, msg, args):
@ -114,7 +114,7 @@ class Utilities(callbacks.Privmsg):
thing as strjoin "", since if <string 2> contains spaces, they won't be
removed by strconcat.
"""
(first, second) = privmsgs.getArgs(args, needed=2)
(first, second) = privmsgs.getArgs(args, required=2)
irc.reply(msg, first+second)
def echo(self, irc, msg, args):
@ -134,7 +134,7 @@ class Utilities(callbacks.Privmsg):
s/regexp/replacement/flags, returns the result of applying such a
regexp to <text>
"""
(regexp, text) = privmsgs.getArgs(args, needed=2)
(regexp, text) = privmsgs.getArgs(args, required=2)
f = None
try:
r = utils.perlReToPythonRe(regexp)

View File

@ -94,7 +94,7 @@ class Channel(callbacks.Privmsg):
this will cause the bot to "cycle", or PART and then JOIN the channel.
If <key> is given, join the channel using that key.
"""
key = privmsgs.getArgs(args, needed=0, optional=1)
key = privmsgs.getArgs(args, required=0, optional=1)
if not key:
key = None
irc.queueMsg(ircmsgs.part(channel))
@ -249,7 +249,7 @@ class Channel(callbacks.Privmsg):
The <channel> argument is only necessary if the message isn't being
sent in the channel itself.
"""
channelarg = privmsgs.getArgs(args, needed=0, optional=1)
channelarg = privmsgs.getArgs(args, required=0, optional=1)
channel = channelarg or channel
c = ircdb.channels.getChannel(channel)
if len(c.ignores) == 0:

View File

@ -72,7 +72,7 @@ class Misc(callbacks.Privmsg):
for (option, argument) in optlist:
if option == '--private':
evenPrivate = True
name = privmsgs.getArgs(rest, needed=0, optional=1)
name = privmsgs.getArgs(rest, required=0, optional=1)
name = name.lower()
if not name:
names = [cb.name() for cb in irc.callbacks
@ -172,7 +172,7 @@ class Misc(callbacks.Privmsg):
Returns the hostmask of <nick>. If <nick> isn't given, return the
hostmask of the person giving the command.
"""
nick = privmsgs.getArgs(args, needed=0, optional=1)
nick = privmsgs.getArgs(args, required=0, optional=1)
try:
if nick:
irc.reply(msg, irc.state.nickToHostmask(nick))
@ -201,7 +201,7 @@ class Misc(callbacks.Privmsg):
Returns the size of the various logfiles in use. If given a specific
logfile, returns only the size of that logfile.
"""
filename = privmsgs.getArgs(args, needed=0, optional=1)
filename = privmsgs.getArgs(args, required=0, optional=1)
if filename:
if not filename.endswith('.log'):
irc.error(msg, 'That filename doesn\'t appear to be a log.')
@ -243,7 +243,7 @@ class Misc(callbacks.Privmsg):
If <nick> is given, it takes the continuation of the last command from
<nick> instead of the person sending this message.
"""
nick = privmsgs.getArgs(args, needed=0, optional=1)
nick = privmsgs.getArgs(args, required=0, optional=1)
userHostmask = msg.prefix.split('!', 1)[1]
if nick:
try:
@ -330,7 +330,7 @@ class Misc(callbacks.Privmsg):
Tells the <nick|channel> whatever <text> is. Use nested commands to
your benefit here.
"""
(target, text) = privmsgs.getArgs(args, needed=2)
(target, text) = privmsgs.getArgs(args, required=2)
s = '%s wants me to tell you: %s' % (msg.nick, text)
irc.queueMsg(ircmsgs.privmsg(target, s))
raise callbacks.CannotNest

View File

@ -202,7 +202,7 @@ class Owner(privmsgs.CapabilityCheckingPrivmsg):
variable type with only the <name> argument and sets the value of the
variable to <value> when both arguments are given.
"""
(name, value) = privmsgs.getArgs(args, needed=0, optional=2)
(name, value) = privmsgs.getArgs(args, required=0, optional=2)
if name and value:
if conf.allowEval:
try:

View File

@ -60,7 +60,7 @@ class User(callbacks.Privmsg):
on disk, rather than being stored in plaintext.
"""
(optlist, rest) = getopt.getopt(args, '', ['hashed'])
(name, password) = privmsgs.getArgs(rest, needed=2)
(name, password) = privmsgs.getArgs(rest, required=2)
hashed = False
for (option, arg) in optlist:
if option == '--hashed':
@ -94,7 +94,7 @@ class User(callbacks.Privmsg):
Unregisters <name> from the user database.
"""
(name, password) = privmsgs.getArgs(args, needed=2)
(name, password) = privmsgs.getArgs(args, required=2)
if not self._checkNotChannel(irc, msg, password):
return
try:
@ -117,7 +117,7 @@ class User(callbacks.Privmsg):
If you include the <password> parameter, this message must be sent
to the bot privately (not on a channel).
"""
(name, newname, password) = privmsgs.getArgs(args, needed=2,optional=1)
(name, newname, password) = privmsgs.getArgs(args, required=2,optional=1)
if not self._checkNotChannel(irc, msg, password):
return
try:

View File

@ -312,7 +312,7 @@ class Configurable(object):
if not ircdb.checkCapability(msg.prefix, capability):
irc.error(msg, conf.replyNoCapability % capability)
return
(name, value) = privmsgs.getArgs(args, needed=0, optional=2)
(name, value) = privmsgs.getArgs(args, required=0, optional=2)
if not name:
irc.reply(msg, utils.commaAndify(self.configurables.names()))
return

View File

@ -58,22 +58,22 @@ def getChannel(msg, args):
raise callbacks.Error, 'Command must be sent in a channel or ' \
'include a channel in its arguments.'
def getArgs(args, needed=1, optional=0):
"""Take the needed arguments from args.
def getArgs(args, required=1, optional=0):
"""Take the required/optional arguments from args.
Always returns a list of size needed + optional, filling it with however
Always returns a list of size required + optional, filling it with however
many empty strings is necessary to fill the tuple to the right size.
If there aren't enough args even to satisfy needed, raise an error and
If there aren't enough args even to satisfy required, raise an error and
let the caller handle sending the help message.
"""
if len(args) < needed:
if len(args) < required:
raise callbacks.ArgumentError
if len(args) < needed + optional:
ret = list(args) + ([''] * (needed + optional - len(args)))
elif len(args) >= needed + optional:
ret = list(args[:needed + optional - 1])
ret.append(' '.join(args[needed + optional - 1:]))
if len(args) < required + optional:
ret = list(args) + ([''] * (required + optional - len(args)))
elif len(args) >= required + optional:
ret = list(args[:required + optional - 1])
ret.append(' '.join(args[required + optional - 1:]))
if len(ret) == 1:
return ret[0]
else:

View File

@ -52,14 +52,14 @@ class FunctionsTest(unittest.TestCase):
def testGetArgs(self):
args = ['foo', 'bar', 'baz']
self.assertEqual(privmsgs.getArgs(args), ' '.join(args))
self.assertEqual(privmsgs.getArgs(args, needed=2),
self.assertEqual(privmsgs.getArgs(args, required=2),
[args[0], ' '.join(args[1:])])
self.assertEqual(privmsgs.getArgs(args, needed=3), args)
self.assertEqual(privmsgs.getArgs(args, required=3), args)
self.assertRaises(callbacks.ArgumentError,
privmsgs.getArgs, args, needed=4)
self.assertEqual(privmsgs.getArgs(args, needed=3, optional=1),
privmsgs.getArgs, args, required=4)
self.assertEqual(privmsgs.getArgs(args, required=3, optional=1),
args + [''])
self.assertEqual(privmsgs.getArgs(args, needed=0, optional=1),
self.assertEqual(privmsgs.getArgs(args, required=0, optional=1),
' '.join(args))