From 949deee935d44078dec8da35c1bbed23810a27f0 Mon Sep 17 00:00:00 2001 From: Jeremy Fincher Date: Tue, 9 Sep 2003 08:41:16 +0000 Subject: [PATCH] Added RFE #802856, so regexps aren't required by searchfactoids. --- plugins/Factoids.py | 14 ++++++++++---- test/test_Factoids.py | 2 ++ 2 files changed, 12 insertions(+), 4 deletions(-) diff --git a/plugins/Factoids.py b/plugins/Factoids.py index 0ffcb3f4f..7748d278c 100644 --- a/plugins/Factoids.py +++ b/plugins/Factoids.py @@ -327,9 +327,11 @@ class Factoids(ChannelDBHandler, callbacks.Privmsg): _sqlTrans = string.maketrans('*?', '%_') def searchfactoids(self, irc, msg, args): - """[] + """[] - Searches the keyspace for keys matching . + Searches the keyspace for keys matching . If + isn't a regexp (i.e, it's not of the form m/foo/ or /bar/) then the + literal string is searched for. """ channel = privmsgs.getChannel(msg, args) regexp = privmsgs.getArgs(args) @@ -338,8 +340,12 @@ class Factoids(ChannelDBHandler, callbacks.Privmsg): def p(s): return int(bool(r.search(s))) except ValueError, e: - irc.error(msg, 'Invalid regular expression.') - return + if not regexp.startswith('m/') or regexp[0] == '/' == regexp[-1]: + def p(s): + return int(regexp in s) + else: + irc.error(msg, 'Invalid regular expression.') + return db = self.getDb(channel) db.create_function('p', 1, p) cursor = db.cursor() diff --git a/test/test_Factoids.py b/test/test_Factoids.py index c93569c1e..9cc9b71ec 100644 --- a/test/test_Factoids.py +++ b/test/test_Factoids.py @@ -76,6 +76,8 @@ class FactoidsTestCase(ChannelPluginTestCase, PluginDocumentation): self.assertRegexp('searchfactoids /^.+i/', 'jemfinch.*strike') self.assertNotRegexp('searchfactoids /^.+i/', 'inkedmn') self.assertRegexp('searchfactoids /^j/', 'jemfinch.*jamessan') + self.assertRegexp('searchfactoids ke', + 'inkedmn.*strike|strike.*inkedmn') # vim:set shiftwidth=4 tabstop=8 expandtab textwidth=78: