mirror of
https://github.com/Mikaela/Limnoria.git
synced 2025-02-09 02:54:13 +01:00
Removed all instances of repr()'ing (or "%r" % ...'ing) factoid values or keys,
as that mucks about with unicode input/output which is desirable to keep.
This commit is contained in:
parent
b15f12126a
commit
5aef3f2e02
@ -205,7 +205,7 @@ class MoobotFactoids(callbacks.PrivmsgCommandAndRegexp):
|
|||||||
irc.error('No factoids in the database.')
|
irc.error('No factoids in the database.')
|
||||||
return
|
return
|
||||||
(fact, key) = cursor.fetchone()
|
(fact, key) = cursor.fetchone()
|
||||||
irc.reply("%r is %r" % (key, fact))
|
irc.reply('"%s" is "%s"' % (key, fact))
|
||||||
|
|
||||||
|
|
||||||
def invalidCommand(self, irc, msg, tokens):
|
def invalidCommand(self, irc, msg, tokens):
|
||||||
@ -236,7 +236,7 @@ class MoobotFactoids(callbacks.PrivmsgCommandAndRegexp):
|
|||||||
# text here is the new key to refer to
|
# text here is the new key to refer to
|
||||||
msg.args = [s.replace(key, text) for s in msg.args]
|
msg.args = [s.replace(key, text) for s in msg.args]
|
||||||
newtokens = [s.replace(key, text) for s in tokens]
|
newtokens = [s.replace(key, text) for s in tokens]
|
||||||
self.invalidCommand(irc, wmsg, newtokens)
|
self.invalidCommand(irc, msg, newtokens)
|
||||||
else:
|
else:
|
||||||
irc.error("Spurious type from _parseFactoid.")
|
irc.error("Spurious type from _parseFactoid.")
|
||||||
return True
|
return True
|
||||||
@ -274,7 +274,7 @@ class MoobotFactoids(callbacks.PrivmsgCommandAndRegexp):
|
|||||||
# Check and make sure it's not in the DB already
|
# Check and make sure it's not in the DB already
|
||||||
cursor.execute("""SELECT * FROM factoids WHERE key LIKE %s""", key)
|
cursor.execute("""SELECT * FROM factoids WHERE key LIKE %s""", key)
|
||||||
if cursor.rowcount != 0:
|
if cursor.rowcount != 0:
|
||||||
irc.error('Factoid %r already exists.' % key)
|
irc.error('Factoid "%s" already exists.' % key)
|
||||||
return
|
return
|
||||||
# Otherwise,
|
# Otherwise,
|
||||||
cursor.execute("""INSERT INTO factoids VALUES
|
cursor.execute("""INSERT INTO factoids VALUES
|
||||||
@ -299,18 +299,18 @@ class MoobotFactoids(callbacks.PrivmsgCommandAndRegexp):
|
|||||||
cursor.execute("""SELECT locked_at, fact FROM factoids
|
cursor.execute("""SELECT locked_at, fact FROM factoids
|
||||||
WHERE key LIKE %s""", key)
|
WHERE key LIKE %s""", key)
|
||||||
if cursor.rowcount == 0:
|
if cursor.rowcount == 0:
|
||||||
irc.error("Factoid %r not found." % key)
|
irc.error('Factoid "%s" not found.' % key)
|
||||||
return
|
return
|
||||||
# No dice if it's locked, no matter who it is
|
# No dice if it's locked, no matter who it is
|
||||||
(locked_at, fact) = cursor.fetchone()
|
(locked_at, fact) = cursor.fetchone()
|
||||||
if locked_at is not None:
|
if locked_at is not None:
|
||||||
irc.error("Factoid %r is locked." % key)
|
irc.error('Factoid "%s" is locked.' % key)
|
||||||
return
|
return
|
||||||
# It's fair game if we get to here
|
# It's fair game if we get to here
|
||||||
try:
|
try:
|
||||||
r = utils.perlReToReplacer(regexp)
|
r = utils.perlReToReplacer(regexp)
|
||||||
except ValueError, e:
|
except ValueError, e:
|
||||||
irc.error("Invalid regexp: %r" % regexp)
|
irc.error('Invalid regexp: "%s"' % regexp)
|
||||||
return
|
return
|
||||||
new_fact = r(fact)
|
new_fact = r(fact)
|
||||||
cursor.execute("""UPDATE factoids
|
cursor.execute("""UPDATE factoids
|
||||||
@ -335,12 +335,12 @@ class MoobotFactoids(callbacks.PrivmsgCommandAndRegexp):
|
|||||||
cursor.execute("""SELECT locked_at, fact FROM factoids
|
cursor.execute("""SELECT locked_at, fact FROM factoids
|
||||||
WHERE key LIKE %s""", key)
|
WHERE key LIKE %s""", key)
|
||||||
if cursor.rowcount == 0:
|
if cursor.rowcount == 0:
|
||||||
irc.error("Factoid %r not found." % key)
|
irc.error('Factoid "%s" not found.' % key)
|
||||||
return
|
return
|
||||||
# No dice if it's locked, no matter who it is
|
# No dice if it's locked, no matter who it is
|
||||||
(locked_at, fact) = cursor.fetchone()
|
(locked_at, fact) = cursor.fetchone()
|
||||||
if locked_at is not None:
|
if locked_at is not None:
|
||||||
irc.error("Factoid %r is locked." % key)
|
irc.error('Factoid "%s" is locked.' % key)
|
||||||
return
|
return
|
||||||
# It's fair game if we get to here
|
# It's fair game if we get to here
|
||||||
new_fact = "%s, or %s" % (fact, new_text)
|
new_fact = "%s, or %s" % (fact, new_text)
|
||||||
@ -371,12 +371,12 @@ class MoobotFactoids(callbacks.PrivmsgCommandAndRegexp):
|
|||||||
cursor.execute("""SELECT locked_at, fact FROM factoids
|
cursor.execute("""SELECT locked_at, fact FROM factoids
|
||||||
WHERE key LIKE %s""", key)
|
WHERE key LIKE %s""", key)
|
||||||
if cursor.rowcount == 0:
|
if cursor.rowcount == 0:
|
||||||
irc.error("Factoid %r not found." % key)
|
irc.error('Factoid "%s" not found.' % key)
|
||||||
return
|
return
|
||||||
# No dice if it's locked, no matter who it is
|
# No dice if it's locked, no matter who it is
|
||||||
(locked_at, _) = cursor.fetchone()
|
(locked_at, _) = cursor.fetchone()
|
||||||
if locked_at is not None:
|
if locked_at is not None:
|
||||||
irc.error("Factoid %r is locked." % key)
|
irc.error('Factoid "%s" is locked.' % key)
|
||||||
return
|
return
|
||||||
# It's fair game if we get to here
|
# It's fair game if we get to here
|
||||||
cursor.execute("""UPDATE factoids
|
cursor.execute("""UPDATE factoids
|
||||||
@ -401,7 +401,7 @@ class MoobotFactoids(callbacks.PrivmsgCommandAndRegexp):
|
|||||||
cursor = db.cursor()
|
cursor = db.cursor()
|
||||||
cursor.execute("""SELECT fact FROM factoids WHERE key LIKE %s""", key)
|
cursor.execute("""SELECT fact FROM factoids WHERE key LIKE %s""", key)
|
||||||
if cursor.rowcount == 0:
|
if cursor.rowcount == 0:
|
||||||
irc.error("No such factoid: %r" % key)
|
irc.error('No such factoid: "%s"' % key)
|
||||||
return
|
return
|
||||||
else:
|
else:
|
||||||
fact = cursor.fetchone()[0]
|
fact = cursor.fetchone()[0]
|
||||||
@ -423,7 +423,7 @@ class MoobotFactoids(callbacks.PrivmsgCommandAndRegexp):
|
|||||||
requested_count, locked_by, locked_at FROM
|
requested_count, locked_by, locked_at FROM
|
||||||
factoids WHERE key LIKE %s""", key)
|
factoids WHERE key LIKE %s""", key)
|
||||||
if cursor.rowcount == 0:
|
if cursor.rowcount == 0:
|
||||||
irc.error("No such factoid: %r" % key)
|
irc.error('No such factoid: "%s"' % key)
|
||||||
return
|
return
|
||||||
(created_by, created_at, modified_by, modified_at, last_requested_by,
|
(created_by, created_at, modified_by, modified_at, last_requested_by,
|
||||||
last_requested_at, requested_count, locked_by,
|
last_requested_at, requested_count, locked_by,
|
||||||
@ -469,17 +469,17 @@ class MoobotFactoids(callbacks.PrivmsgCommandAndRegexp):
|
|||||||
cursor.execute("""SELECT created_by, locked_by FROM factoids
|
cursor.execute("""SELECT created_by, locked_by FROM factoids
|
||||||
WHERE key LIKE %s""", key)
|
WHERE key LIKE %s""", key)
|
||||||
if cursor.rowcount == 0:
|
if cursor.rowcount == 0:
|
||||||
irc.error("No such factoid: %r" % key)
|
irc.error('No such factoid: "%s"' % key)
|
||||||
return
|
return
|
||||||
(created_by, locked_by) = cursor.fetchone()
|
(created_by, locked_by) = cursor.fetchone()
|
||||||
# Don't perform redundant operations
|
# Don't perform redundant operations
|
||||||
if lock:
|
if lock:
|
||||||
if locked_by is not None:
|
if locked_by is not None:
|
||||||
irc.error("Factoid %r is already locked." % key)
|
irc.error('Factoid "%s" is already locked.' % key)
|
||||||
return
|
return
|
||||||
else:
|
else:
|
||||||
if locked_by is None:
|
if locked_by is None:
|
||||||
irc.error("Factoid %r is not locked." % key)
|
irc.error('Factoid "%s" is not locked.' % key)
|
||||||
return
|
return
|
||||||
# Can only lock/unlock own factoids unless you're an admin
|
# Can only lock/unlock own factoids unless you're an admin
|
||||||
if not (ircdb.checkCapability(id, 'admin') or created_by == id):
|
if not (ircdb.checkCapability(id, 'admin') or created_by == id):
|
||||||
@ -554,7 +554,7 @@ class MoobotFactoids(callbacks.PrivmsgCommandAndRegexp):
|
|||||||
def _mostRecent(self, cursor, limit):
|
def _mostRecent(self, cursor, limit):
|
||||||
cursor.execute("""SELECT key FROM factoids
|
cursor.execute("""SELECT key FROM factoids
|
||||||
ORDER by created_at DESC LIMIT %s""", limit)
|
ORDER by created_at DESC LIMIT %s""", limit)
|
||||||
L = [repr(t[0]) for t in cursor.fetchall()]
|
L = ['"%s"' % t[0] for t in cursor.fetchall()]
|
||||||
return '%s: %s' % \
|
return '%s: %s' % \
|
||||||
(utils.nItems('factoid', len(L), between='latest'),
|
(utils.nItems('factoid', len(L), between='latest'),
|
||||||
utils.commaAndify(L))
|
utils.commaAndify(L))
|
||||||
@ -565,7 +565,7 @@ class MoobotFactoids(callbacks.PrivmsgCommandAndRegexp):
|
|||||||
ORDER BY requested_count DESC LIMIT %s""", limit)
|
ORDER BY requested_count DESC LIMIT %s""", limit)
|
||||||
if cursor.rowcount == 0:
|
if cursor.rowcount == 0:
|
||||||
raise self.MostException, 'No factoids have been requested.'
|
raise self.MostException, 'No factoids have been requested.'
|
||||||
L = ['%r (%s)' % (t[0], t[1]) for t in cursor.fetchall()]
|
L = ['"%s" (%s)' % (t[0], t[1]) for t in cursor.fetchall()]
|
||||||
return 'Top %s: %s' % \
|
return 'Top %s: %s' % \
|
||||||
(utils.nItems('factoid', len(L), between='requested'),
|
(utils.nItems('factoid', len(L), between='requested'),
|
||||||
utils.commaAndify(L))
|
utils.commaAndify(L))
|
||||||
@ -589,10 +589,10 @@ class MoobotFactoids(callbacks.PrivmsgCommandAndRegexp):
|
|||||||
WHERE created_by = %s
|
WHERE created_by = %s
|
||||||
ORDER BY key""", id)
|
ORDER BY key""", id)
|
||||||
if cursor.rowcount == 0:
|
if cursor.rowcount == 0:
|
||||||
irc.reply("No factoids by %r found." % author)
|
irc.reply('No factoids by "%s" found.' % author)
|
||||||
return
|
return
|
||||||
keys = [repr(tup[0]) for tup in cursor.fetchall()]
|
keys = ['"%s"' % tup[0] for tup in cursor.fetchall()]
|
||||||
s = "Author search for %r (%s found): %s" % \
|
s = 'Author search for "%s" (%s found): %s' % \
|
||||||
(author, len(keys), utils.commaAndify(keys))
|
(author, len(keys), utils.commaAndify(keys))
|
||||||
irc.reply(s)
|
irc.reply(s)
|
||||||
|
|
||||||
@ -602,6 +602,8 @@ class MoobotFactoids(callbacks.PrivmsgCommandAndRegexp):
|
|||||||
Lists the keys of the factoids whose key contains the provided text.
|
Lists the keys of the factoids whose key contains the provided text.
|
||||||
"""
|
"""
|
||||||
search = privmsgs.getArgs(args, required=1)
|
search = privmsgs.getArgs(args, required=1)
|
||||||
|
# Don't error if we aren't in a channel, private messages are okay
|
||||||
|
channel = privmsgs.getChannel(msg, args, raiseError=False)
|
||||||
glob = '%' + search + '%'
|
glob = '%' + search + '%'
|
||||||
db = self.dbHandler.getDb()
|
db = self.dbHandler.getDb()
|
||||||
cursor = db.cursor()
|
cursor = db.cursor()
|
||||||
@ -610,14 +612,14 @@ class MoobotFactoids(callbacks.PrivmsgCommandAndRegexp):
|
|||||||
ORDER BY key""",
|
ORDER BY key""",
|
||||||
glob)
|
glob)
|
||||||
if cursor.rowcount == 0:
|
if cursor.rowcount == 0:
|
||||||
irc.reply("No keys matching %r found." % search)
|
irc.reply('No keys matching "%s" found.' % search)
|
||||||
elif cursor.rowcount == 1 and \
|
elif cursor.rowcount == 1 and \
|
||||||
self.registryValue('showFactoidIfOnlyOneMatch', msg.args[0]):
|
self.registryValue('showFactoidIfOnlyOneMatch', channel):
|
||||||
key = cursor.fetchone()[0]
|
key = cursor.fetchone()[0]
|
||||||
self.invalidCommand(irc, msg, [key])
|
self.invalidCommand(irc, msg, [key])
|
||||||
else:
|
else:
|
||||||
keys = [repr(tup[0]) for tup in cursor.fetchall()]
|
keys = ['"%s"' % tup[0] for tup in cursor.fetchall()]
|
||||||
s = "Key search for %r (%s found): %s" % \
|
s = 'Key search for "%s" (%s found): %s' % \
|
||||||
(search, len(keys), utils.commaAndify(keys))
|
(search, len(keys), utils.commaAndify(keys))
|
||||||
irc.reply(s)
|
irc.reply(s)
|
||||||
|
|
||||||
@ -635,10 +637,10 @@ class MoobotFactoids(callbacks.PrivmsgCommandAndRegexp):
|
|||||||
ORDER BY key""",
|
ORDER BY key""",
|
||||||
glob)
|
glob)
|
||||||
if cursor.rowcount == 0:
|
if cursor.rowcount == 0:
|
||||||
irc.reply("No values matching %r found." % search)
|
irc.reply('No values matching "%s" found.' % search)
|
||||||
return
|
return
|
||||||
keys = [repr(tup[0]) for tup in cursor.fetchall()]
|
keys = ['"%s"' % tup[0] for tup in cursor.fetchall()]
|
||||||
s = "Value search for %r (%s found): %s" % \
|
s = 'Value search for "%s" (%s found): %s' % \
|
||||||
(search, len(keys), utils.commaAndify(keys))
|
(search, len(keys), utils.commaAndify(keys))
|
||||||
irc.reply(s)
|
irc.reply(s)
|
||||||
|
|
||||||
@ -659,7 +661,7 @@ class MoobotFactoids(callbacks.PrivmsgCommandAndRegexp):
|
|||||||
cursor.execute("""SELECT key, locked_at FROM factoids
|
cursor.execute("""SELECT key, locked_at FROM factoids
|
||||||
WHERE key LIKE %s""", key)
|
WHERE key LIKE %s""", key)
|
||||||
if cursor.rowcount == 0:
|
if cursor.rowcount == 0:
|
||||||
irc.error("No such factoid: %r" % key)
|
irc.error('No such factoid: "%s"' % key)
|
||||||
return
|
return
|
||||||
(_, locked_at) = cursor.fetchone()
|
(_, locked_at) = cursor.fetchone()
|
||||||
if locked_at is not None:
|
if locked_at is not None:
|
||||||
@ -681,7 +683,7 @@ class MoobotFactoids(callbacks.PrivmsgCommandAndRegexp):
|
|||||||
irc.error(msg, 'No factoids in the database.')
|
irc.error(msg, 'No factoids in the database.')
|
||||||
return
|
return
|
||||||
(fact, key) = cursor.fetchone()
|
(fact, key) = cursor.fetchone()
|
||||||
irc.reply(msg, "Random factoid: %r is %r" % (key, fact))
|
irc.reply(msg, 'Random factoid: "%s" is "%s"' % (key, fact))
|
||||||
|
|
||||||
Class = MoobotFactoids
|
Class = MoobotFactoids
|
||||||
|
|
||||||
|
@ -108,6 +108,11 @@ if sqlite is not None:
|
|||||||
self.assertResponse('moo', 'foo')
|
self.assertResponse('moo', 'foo')
|
||||||
self.assertNotError('foo is bar _is_ baz')
|
self.assertNotError('foo is bar _is_ baz')
|
||||||
self.assertResponse('foo is bar', 'foo is bar is baz')
|
self.assertResponse('foo is bar', 'foo is bar is baz')
|
||||||
|
# Check the "see ..." referencing
|
||||||
|
self.assertNotError('bar is see moo')
|
||||||
|
self.assertResponse('bar', 'foo')
|
||||||
|
self.assertNotError('bar2 _is_ see foo is bar')
|
||||||
|
self.assertResponse('bar2', 'foo is bar is baz')
|
||||||
|
|
||||||
def testFactinfo(self):
|
def testFactinfo(self):
|
||||||
self.assertNotError('moo is <reply>foo')
|
self.assertNotError('moo is <reply>foo')
|
||||||
@ -226,33 +231,40 @@ if sqlite is not None:
|
|||||||
'Most prolific authors: boo (2) and moo (1)')
|
'Most prolific authors: boo (2) and moo (1)')
|
||||||
|
|
||||||
def testListkeys(self):
|
def testListkeys(self):
|
||||||
self.assertResponse('listkeys %', 'No keys matching \'%\' found.')
|
self.assertResponse('listkeys %', 'No keys matching "%" found.')
|
||||||
self.assertNotError('moo is <reply>moo')
|
self.assertNotError('moo is <reply>moo')
|
||||||
# If only one key, it should respond with the factoid
|
# If only one key, it should respond with the factoid
|
||||||
self.assertResponse('listkeys moo', 'moo')
|
self.assertResponse('listkeys moo', 'moo')
|
||||||
self.assertResponse('listkeys foo', 'No keys matching \'foo\' '
|
self.assertResponse('listkeys foo', 'No keys matching "foo" '
|
||||||
'found.')
|
'found.')
|
||||||
# Throw in a bunch more
|
# Throw in a bunch more
|
||||||
for i in range(10):
|
for i in range(10):
|
||||||
self.assertNotError('moo%s is <reply>moo' % i)
|
self.assertNotError('moo%s is <reply>moo' % i)
|
||||||
self.assertRegexp('listkeys moo',
|
self.assertRegexp('listkeys moo',
|
||||||
'^Key search for \'moo\' '
|
'^Key search for "moo" '
|
||||||
'\(11 found\): (\'moo\d*\', )+and \'moo9\'$')
|
'\(11 found\): ("moo\d*", )+and "moo9"$')
|
||||||
self.assertNotError('foo is bar')
|
self.assertNotError('foo is bar')
|
||||||
self.assertRegexp('listkeys %',
|
self.assertRegexp('listkeys %',
|
||||||
'^Key search for \'\%\' '
|
'^Key search for "\%" '
|
||||||
'\(12 found\): \'foo\', (\'moo\d*\', )+and '
|
'\(12 found\): "foo", ("moo\d*", )+and '
|
||||||
'\'moo9\'$')
|
'"moo9"$')
|
||||||
# Check quoting
|
# Check quoting
|
||||||
self.assertNotError('foo\' is bar')
|
self.assertNotError('foo\' is bar')
|
||||||
self.assertResponse('listkeys foo',
|
self.assertResponse('listkeys foo',
|
||||||
'Key search for \'foo\' '
|
'Key search for "foo" '
|
||||||
'(2 found): \'foo\' and "foo\'"')
|
'(2 found): "foo" and "foo\'"')
|
||||||
|
# Check unicode stuff
|
||||||
|
self.assertResponse('listkeys Б', 'No keys matching "Б" found.')
|
||||||
|
self.assertNotError('АБВГДЕЖ is foo')
|
||||||
|
self.assertNotError('АБВГДЕЖЗИ is foo')
|
||||||
|
self.assertResponse('listkeys Б',
|
||||||
|
'Key search for "Б" '
|
||||||
|
'(2 found): "АБВГДЕЖ" and "АБВГДЕЖЗИ"')
|
||||||
|
|
||||||
def testListvalues(self):
|
def testListvalues(self):
|
||||||
self.assertNotError('moo is moo')
|
self.assertNotError('moo is moo')
|
||||||
self.assertResponse('listvalues moo',
|
self.assertResponse('listvalues moo',
|
||||||
'Value search for \'moo\' (1 found): \'moo\'')
|
'Value search for "moo" (1 found): "moo"')
|
||||||
|
|
||||||
def testListauth(self):
|
def testListauth(self):
|
||||||
self.assertNotError('moo is <reply>moo')
|
self.assertNotError('moo is <reply>moo')
|
||||||
@ -301,4 +313,16 @@ if sqlite is not None:
|
|||||||
self.assertError('re s/Error:.*/jbm is a tard/ ]')
|
self.assertError('re s/Error:.*/jbm is a tard/ ]')
|
||||||
self.assertNoResponse(' ', 3)
|
self.assertNoResponse(' ', 3)
|
||||||
|
|
||||||
|
def testConfigShowFactoidIfOnlyOneMatch(self):
|
||||||
|
# man these are long
|
||||||
|
MFconf = conf.supybot.plugins.MoobotFactoids
|
||||||
|
self.assertNotError('foo is bar')
|
||||||
|
# Default to saying the factoid value
|
||||||
|
self.assertResponse('listkeys foo', 'foo is bar')
|
||||||
|
# Check the False setting
|
||||||
|
MFconf.showFactoidIfOnlyOneMatch.setValue(False)
|
||||||
|
self.assertResponse('listkeys foo', 'Key search for "foo" '
|
||||||
|
'(1 found): "foo"')
|
||||||
|
|
||||||
|
|
||||||
# vim:set shiftwidth=4 tabstop=8 expandtab textwidth=78:
|
# vim:set shiftwidth=4 tabstop=8 expandtab textwidth=78:
|
||||||
|
Loading…
Reference in New Issue
Block a user