MessageParser: remove redundant spaces

This commit is contained in:
Valentin Lorentz 2011-05-27 18:18:53 +02:00
parent ef6fe23e02
commit 865bd93244

View File

@ -78,7 +78,7 @@ class MessageParser(callbacks.Plugin, plugins.ChannelDBHandler):
def __init__(self, irc): def __init__(self, irc):
callbacks.Plugin.__init__(self, irc) callbacks.Plugin.__init__(self, irc)
plugins.ChannelDBHandler.__init__(self) plugins.ChannelDBHandler.__init__(self)
def makeDb(self, filename): def makeDb(self, filename):
"""Create the database and connect to it.""" """Create the database and connect to it."""
if os.path.exists(filename): if os.path.exists(filename):
@ -99,7 +99,7 @@ class MessageParser(callbacks.Plugin, plugins.ChannelDBHandler):
)""") )""")
db.commit() db.commit()
return db return db
# override this because sqlite3 doesn't have autocommit # override this because sqlite3 doesn't have autocommit
# use isolation_level instead. # use isolation_level instead.
def getDb(self, channel): def getDb(self, channel):
@ -113,7 +113,7 @@ class MessageParser(callbacks.Plugin, plugins.ChannelDBHandler):
db = self.dbCache[channel] db = self.dbCache[channel]
db.isolation_level = None db.isolation_level = None
return db return db
def _updateRank(self, channel, regexp): def _updateRank(self, channel, regexp):
if self.registryValue('keepRankInfo', channel): if self.registryValue('keepRankInfo', channel):
db = self.getDb(channel) db = self.getDb(channel)
@ -124,15 +124,15 @@ class MessageParser(callbacks.Plugin, plugins.ChannelDBHandler):
old_count = cursor.fetchall()[0][0] old_count = cursor.fetchall()[0][0]
cursor.execute("UPDATE triggers SET usage_count=? WHERE regexp=?", (old_count + 1, regexp,)) cursor.execute("UPDATE triggers SET usage_count=? WHERE regexp=?", (old_count + 1, regexp,))
db.commit() db.commit()
def _runCommandFunction(self, irc, msg, command): def _runCommandFunction(self, irc, msg, command):
"""Run a command from message, as if command was sent over IRC.""" """Run a command from message, as if command was sent over IRC."""
tokens = callbacks.tokenize(command) tokens = callbacks.tokenize(command)
try: try:
self.Proxy(irc.irc, msg, tokens) self.Proxy(irc.irc, msg, tokens)
except Exception, e: except Exception, e:
log.exception('Uncaught exception in function called by MessageParser:') log.exception('Uncaught exception in function called by MessageParser:')
def _checkManageCapabilities(self, irc, msg, channel): def _checkManageCapabilities(self, irc, msg, channel):
"""Check if the user has any of the required capabilities to manage """Check if the user has any of the required capabilities to manage
the regexp database.""" the regexp database."""
@ -147,7 +147,7 @@ class MessageParser(callbacks.Plugin, plugins.ChannelDBHandler):
return False return False
else: else:
return True return True
def doPrivmsg(self, irc, msg): def doPrivmsg(self, irc, msg):
channel = msg.args[0] channel = msg.args[0]
if not irc.isChannel(channel): if not irc.isChannel(channel):
@ -170,17 +170,17 @@ class MessageParser(callbacks.Plugin, plugins.ChannelDBHandler):
for (i, j) in enumerate(match.groups()): for (i, j) in enumerate(match.groups()):
thisaction = re.sub(r'\$' + str(i+1), match.group(i+1), thisaction) thisaction = re.sub(r'\$' + str(i+1), match.group(i+1), thisaction)
actions.append(thisaction) actions.append(thisaction)
for action in actions: for action in actions:
self._runCommandFunction(irc, msg, action) self._runCommandFunction(irc, msg, action)
@internationalizeDocstring @internationalizeDocstring
def add(self, irc, msg, args, channel, regexp, action): def add(self, irc, msg, args, channel, regexp, action):
"""[<channel>] <regexp> <action> """[<channel>] <regexp> <action>
Associates <regexp> with <action>. <channel> is only Associates <regexp> with <action>. <channel> is only
necessary if the message isn't sent on the channel necessary if the message isn't sent on the channel
itself. Action is echoed upon regexp match, with variables $1, $2, itself. Action is echoed upon regexp match, with variables $1, $2,
etc. being interpolated from the regexp match groups.""" etc. being interpolated from the regexp match groups."""
if not self._checkManageCapabilities(irc, msg, channel): if not self._checkManageCapabilities(irc, msg, channel):
capabilities = self.registryValue('requireManageCapability') capabilities = self.registryValue('requireManageCapability')
@ -213,12 +213,12 @@ class MessageParser(callbacks.Plugin, plugins.ChannelDBHandler):
irc.error(_('That trigger is locked.')) irc.error(_('That trigger is locked.'))
return return
add = wrap(add, ['channel', 'something', 'something']) add = wrap(add, ['channel', 'something', 'something'])
@internationalizeDocstring @internationalizeDocstring
def remove(self, irc, msg, args, channel, optlist, regexp): def remove(self, irc, msg, args, channel, optlist, regexp):
"""[<channel>] [--id] <regexp>] """[<channel>] [--id] <regexp>]
Removes the trigger for <regexp> from the triggers database. Removes the trigger for <regexp> from the triggers database.
<channel> is only necessary if <channel> is only necessary if
the message isn't sent in the channel itself. the message isn't sent in the channel itself.
If option --id specified, will retrieve by regexp id, not content. If option --id specified, will retrieve by regexp id, not content.
@ -240,11 +240,11 @@ class MessageParser(callbacks.Plugin, plugins.ChannelDBHandler):
else: else:
irc.error(_('There is no such regexp trigger.')) irc.error(_('There is no such regexp trigger.'))
return return
if locked: if locked:
irc.error(_('This regexp trigger is locked.')) irc.error(_('This regexp trigger is locked.'))
return return
cursor.execute("""DELETE FROM triggers WHERE id=?""", (id,)) cursor.execute("""DELETE FROM triggers WHERE id=?""", (id,))
db.commit() db.commit()
irc.replySuccess() irc.replySuccess()
@ -303,7 +303,7 @@ class MessageParser(callbacks.Plugin, plugins.ChannelDBHandler):
"""[<channel>] [--id] <regexp> """[<channel>] [--id] <regexp>
Looks up the value of <regexp> in the triggers database. Looks up the value of <regexp> in the triggers database.
<channel> is only necessary if the message isn't sent in the channel <channel> is only necessary if the message isn't sent in the channel
itself. itself.
If option --id specified, will retrieve by regexp id, not content. If option --id specified, will retrieve by regexp id, not content.
""" """
@ -321,9 +321,9 @@ class MessageParser(callbacks.Plugin, plugins.ChannelDBHandler):
else: else:
irc.error(_('There is no such regexp trigger.')) irc.error(_('There is no such regexp trigger.'))
return return
irc.reply("The action for regexp trigger \"%s\" is \"%s\"" % (regexp, action)) irc.reply("The action for regexp trigger \"%s\" is \"%s\"" % (regexp, action))
show = wrap(show, ['channel', show = wrap(show, ['channel',
getopts({'id': '',}), getopts({'id': '',}),
'something']) 'something'])
@ -332,7 +332,7 @@ class MessageParser(callbacks.Plugin, plugins.ChannelDBHandler):
"""[<channel>] [--id] <regexp> """[<channel>] [--id] <regexp>
Display information about <regexp> in the triggers database. Display information about <regexp> in the triggers database.
<channel> is only necessary if the message isn't sent in the channel <channel> is only necessary if the message isn't sent in the channel
itself. itself.
If option --id specified, will retrieve by regexp id, not content. If option --id specified, will retrieve by regexp id, not content.
""" """
@ -346,23 +346,23 @@ class MessageParser(callbacks.Plugin, plugins.ChannelDBHandler):
cursor.execute(sql, (regexp,)) cursor.execute(sql, (regexp,))
results = cursor.fetchall() results = cursor.fetchall()
if len(results) != 0: if len(results) != 0:
(id, regexp, added_by, added_at, usage_count, (id, regexp, added_by, added_at, usage_count,
action, locked) = results[0] action, locked) = results[0]
else: else:
irc.error(_('There is no such regexp trigger.')) irc.error(_('There is no such regexp trigger.'))
return return
irc.reply(_("The regexp id is %d, regexp is \"%s\", and action is" irc.reply(_("The regexp id is %d, regexp is \"%s\", and action is"
" \"%s\". It was added by user %s on %s, has been " " \"%s\". It was added by user %s on %s, has been "
"triggered %d times, and is %s.") % (id, "triggered %d times, and is %s.") % (id,
regexp, regexp,
action, action,
added_by, added_by,
time.strftime(conf.supybot.reply.format.time(), time.strftime(conf.supybot.reply.format.time(),
time.localtime(int(added_at))), time.localtime(int(added_at))),
usage_count, usage_count,
locked and _("locked") or _("not locked"),)) locked and _("locked") or _("not locked"),))
info = wrap(info, ['channel', info = wrap(info, ['channel',
getopts({'id': '',}), getopts({'id': '',}),
'something']) 'something'])
@ -371,7 +371,7 @@ class MessageParser(callbacks.Plugin, plugins.ChannelDBHandler):
"""[<channel>] """[<channel>]
Lists regexps present in the triggers database. Lists regexps present in the triggers database.
<channel> is only necessary if the message isn't sent in the channel <channel> is only necessary if the message isn't sent in the channel
itself. Regexp ID listed in paretheses. itself. Regexp ID listed in paretheses.
""" """
db = self.getDb(channel) db = self.getDb(channel)
@ -383,7 +383,7 @@ class MessageParser(callbacks.Plugin, plugins.ChannelDBHandler):
else: else:
irc.reply(_('There are no regexp triggers in the database.')) irc.reply(_('There are no regexp triggers in the database.'))
return return
s = [ "\"%s\" (%d)" % (regexp[0], regexp[1]) for regexp in regexps ] s = [ "\"%s\" (%d)" % (regexp[0], regexp[1]) for regexp in regexps ]
separator = self.registryValue('listSeparator', channel) separator = self.registryValue('listSeparator', channel)
irc.reply(separator.join(s)) irc.reply(separator.join(s))
@ -392,10 +392,10 @@ class MessageParser(callbacks.Plugin, plugins.ChannelDBHandler):
@internationalizeDocstring @internationalizeDocstring
def rank(self, irc, msg, args, channel): def rank(self, irc, msg, args, channel):
"""[<channel>] """[<channel>]
Returns a list of top-ranked regexps, sorted by usage count Returns a list of top-ranked regexps, sorted by usage count
(rank). The number of regexps returned is set by the (rank). The number of regexps returned is set by the
rankListLength registry value. <channel> is only necessary if the rankListLength registry value. <channel> is only necessary if the
message isn't sent in the channel itself. message isn't sent in the channel itself.
""" """
numregexps = self.registryValue('rankListLength', channel) numregexps = self.registryValue('rankListLength', channel)
@ -416,12 +416,12 @@ class MessageParser(callbacks.Plugin, plugins.ChannelDBHandler):
@internationalizeDocstring @internationalizeDocstring
def vacuum(self, irc, msg, args, channel): def vacuum(self, irc, msg, args, channel):
"""[<channel>] """[<channel>]
Vacuums the database for <channel>. Vacuums the database for <channel>.
See SQLite vacuum doc here: http://www.sqlite.org/lang_vacuum.html See SQLite vacuum doc here: http://www.sqlite.org/lang_vacuum.html
<channel> is only necessary if the message isn't sent in <channel> is only necessary if the message isn't sent in
the channel itself. the channel itself.
First check if user has the required capability specified in plugin First check if user has the required capability specified in plugin
config requireVacuumCapability. config requireVacuumCapability.
""" """
capability = self.registryValue('requireVacuumCapability') capability = self.registryValue('requireVacuumCapability')