Reduced functionality, but I doubt anyone will complain. Much cleaner and clearer now that we're using flat files.

This commit is contained in:
Jeremy Fincher 2004-07-28 05:59:30 +00:00
parent 46383f9fc7
commit d594232c5c
3 changed files with 199 additions and 307 deletions

View File

@ -1,3 +1,8 @@
* Changed the URL plugin to use flatfiles rather than SQLite
database. Also reduced the functionality of the last command by
removing some options that no one ever really used, and removed
the random command (who uses that anyway?)
* Changed the Words plugin not to use SQLite. We lose the * Changed the Words plugin not to use SQLite. We lose the
anagram command, but crossword and hangman become much easier to anagram command, but crossword and hangman become much easier to
use, since all the user has to do is put a words file in use, since all the user has to do is put a words file in

View File

@ -55,12 +55,6 @@ import supybot.privmsgs as privmsgs
import supybot.registry as registry import supybot.registry as registry
import supybot.callbacks as callbacks import supybot.callbacks as callbacks
try:
import sqlite
except ImportError:
raise callbacks.Error, 'You need to have PySQLite installed to use this ' \
'plugin. Download it at <http://pysqlite.sf.net/>'
def configure(advanced): def configure(advanced):
from supybot.questions import output, expect, anything, something, yn from supybot.questions import output, expect, anything, something, yn
conf.registerPlugin('URL', True) conf.registerPlugin('URL', True)
@ -93,54 +87,57 @@ conf.registerChannelValue(conf.supybot.plugins.URL, 'nonSnarfingRegexp',
snarfed. Give the empty string if you have no URLs that you'd like to snarfed. Give the empty string if you have no URLs that you'd like to
exclude from being snarfed.""")) exclude from being snarfed."""))
class URL(callbacks.PrivmsgCommandAndRegexp, class URLDB(object):
plugins.ChannelDBHandler): def __init__(self, channel, log):
self.log = log
dataDir = conf.supybot.directories.data()
self.filename = os.path.join(dataDir, '%s-URL.db' % channel)
def addUrl(self, url, nick):
fd = file(self.filename, 'a')
fd.write('%s %s\n' % (url, nick))
fd.close()
def numUrls(self):
try:
fd = file(self.filename)
except EnvironmentError, e:
self.log.warning('Couldn\'t open %s: %s',
self.filename, utils.exnToString(e))
return 0
try:
return itertools.ilen(fd)
finally:
fd.close()
def getUrls(self, p):
L = []
try:
fd = file(self.filename)
except EnvironmentError, e:
self.log.warning('Couldn\'t open %s: %s',
self.filename, utils.exnToString(e))
return []
try:
for line in fd:
line = line.strip()
(url, nick) = line.split()
if p(url, nick):
L.append(url)
L.reverse()
return L
finally:
fd.close()
class URL(callbacks.PrivmsgCommandAndRegexp):
regexps = ['tinyurlSnarfer', 'titleSnarfer'] regexps = ['tinyurlSnarfer', 'titleSnarfer']
_titleRe = re.compile('<title>(.*?)</title>', re.I) _titleRe = re.compile('<title>(.*?)</title>', re.I | re.S)
def __init__(self): def getDb(self, channel):
self.nextMsgs = {} return URLDB(channel, self.log)
plugins.ChannelDBHandler.__init__(self)
callbacks.PrivmsgCommandAndRegexp.__init__(self)
def die(self):
plugins.ChannelDBHandler.die(self)
callbacks.PrivmsgCommandAndRegexp.die(self)
def makeDb(self, filename):
if os.path.exists(filename):
return sqlite.connect(filename)
db = sqlite.connect(filename)
cursor = db.cursor()
cursor.execute("""CREATE TABLE urls (
id INTEGER PRIMARY KEY,
url TEXT,
added TIMESTAMP,
added_by TEXT,
previous_msg TEXT,
current_msg TEXT,
next_msg TEXT,
protocol TEXT,
site TEXT,
filename TEXT
)""")
cursor.execute("""CREATE TABLE tinyurls (
id INTEGER PRIMARY KEY,
url_id INTEGER,
tinyurl TEXT
)""")
db.commit()
return db
def doPrivmsg(self, irc, msg): def doPrivmsg(self, irc, msg):
channel = msg.args[0] channel = msg.args[0]
db = self.getDb(channel) db = self.getDb(channel)
cursor = db.cursor()
if (msg.nick, channel) in self.nextMsgs:
L = self.nextMsgs.pop((msg.nick, msg.args[0]))
for (url, added) in L:
cursor.execute("""UPDATE urls SET next_msg=%s
WHERE url=%s AND added=%s""",
msg.args[1], url, added)
if ircmsgs.isAction(msg): if ircmsgs.isAction(msg):
text = ircmsgs.unAction(msg) text = ircmsgs.unAction(msg)
else: else:
@ -149,31 +146,17 @@ class URL(callbacks.PrivmsgCommandAndRegexp,
r = self.registryValue('nonSnarfingRegexp', channel) r = self.registryValue('nonSnarfingRegexp', channel)
#self.log.warning(repr(r)) #self.log.warning(repr(r))
if r and r.search(url): if r and r.search(url):
#self.log.warning('Skipping addition of URL to db.') self.log.debug('Skipping adding %r to db.', url)
continue continue
#self.log.warning('Adding URL to db.') self.log.debug('Adding %r to db.', url)
(protocol, site, filename, _, _, _) = urlparse.urlparse(url) db.addUrl(url, msg.nick)
previousMsg = '' callbacks.PrivmsgCommandAndRegexp.doPrivmsg(self, irc, msg)
for oldMsg in reversed(irc.state.history):
if oldMsg.command == 'PRIVMSG':
if oldMsg.nick == msg.nick and oldMsg.args[0] == channel:
previousMsg = oldMsg.args[1]
addedBy = msg.nick
added = int(time.time())
cursor.execute("""INSERT INTO urls VALUES
(NULL, %s, %s, %s, %s, %s, '', %s, %s, %s)""",
url, added, addedBy, msg.args[1], previousMsg,
protocol, site, filename)
key = (msg.nick, channel)
self.nextMsgs.setdefault(key, []).append((url, added))
db.commit()
super(URL, self).doPrivmsg(irc, msg)
def tinyurlSnarfer(self, irc, msg, match): def tinyurlSnarfer(self, irc, msg, match):
r"https?://[^\])>\s]{18,}" r"https?://[^\])>\s]{18,}"
if not ircutils.isChannel(msg.args[0]):
return
channel = msg.args[0] channel = msg.args[0]
if not ircutils.isChannel(channel):
return
r = self.registryValue('nonSnarfingRegexp', channel) r = self.registryValue('nonSnarfingRegexp', channel)
if self.registryValue('tinyurlSnarfer', channel): if self.registryValue('tinyurlSnarfer', channel):
url = match.group(0) url = match.group(0)
@ -181,18 +164,10 @@ class URL(callbacks.PrivmsgCommandAndRegexp,
return return
minlen = self.registryValue('tinyurlSnarfer.minimumLength',channel) minlen = self.registryValue('tinyurlSnarfer.minimumLength',channel)
if len(url) >= minlen: if len(url) >= minlen:
db = self.getDb(channel) tinyurl = self._getTinyUrl(url, channel)
cursor = db.cursor()
try:
(tinyurl, updateDb) = self._getTinyUrl(url, channel)
except sqlite.OperationalError:
irc.error('The database just decided to crap itself.')
return
if tinyurl is None: if tinyurl is None:
self.log.warning('tinyurl was None for url %r', url) self.log.warning('Couldn\'t get tinyurl for %r', url)
return return
elif updateDb:
self._updateTinyDb(url, tinyurl, channel)
domain = webutils.getDomain(url) domain = webutils.getDomain(url)
s = '%s (at %s)' % (ircutils.bold(tinyurl), domain) s = '%s (at %s)' % (ircutils.bold(tinyurl), domain)
irc.reply(s, prefixName=False) irc.reply(s, prefixName=False)
@ -200,16 +175,16 @@ class URL(callbacks.PrivmsgCommandAndRegexp,
def titleSnarfer(self, irc, msg, match): def titleSnarfer(self, irc, msg, match):
r"https?://[^\])>\s]+" r"https?://[^\])>\s]+"
if not ircutils.isChannel(msg.args[0]): channel = msg.args[0]
if not ircutils.isChannel(channel):
return return
if callbacks.addressed(irc.nick, msg): if callbacks.addressed(irc.nick, msg):
return return
channel = msg.args[0]
r = self.registryValue('nonSnarfingRegexp', channel)
#self.log.warning('Title: %r' % r)
if self.registryValue('titleSnarfer', channel): if self.registryValue('titleSnarfer', channel):
url = match.group(0) url = match.group(0)
r = self.registryValue('nonSnarfingRegexp', channel)
if r and r.search(url): if r and r.search(url):
self.log.debug('Not titleSnarfing %r.', url)
return return
try: try:
size = conf.supybot.protocols.http.peekSize() size = conf.supybot.protocols.http.peekSize()
@ -225,71 +200,24 @@ class URL(callbacks.PrivmsgCommandAndRegexp,
irc.reply(s, prefixName=False) irc.reply(s, prefixName=False)
titleSnarfer = privmsgs.urlSnarfer(titleSnarfer) titleSnarfer = privmsgs.urlSnarfer(titleSnarfer)
def _updateTinyDb(self, url, tinyurl, channel):
db = self.getDb(channel)
cursor = db.cursor()
cursor.execute("""INSERT INTO tinyurls
VALUES (NULL, 0, %s)""", tinyurl)
cursor.execute("""SELECT id FROM urls WHERE url=%s""", url)
id = cursor.fetchone()[0]
cursor.execute("""UPDATE tinyurls SET url_id=%s
WHERE tinyurl=%s""", id, tinyurl)
db.commit()
_tinyRe = re.compile(r'<blockquote><b>(http://tinyurl\.com/\w+)</b>') _tinyRe = re.compile(r'<blockquote><b>(http://tinyurl\.com/\w+)</b>')
def _getTinyUrl(self, url, channel, cmd=False): def _getTinyUrl(self, url, channel, cmd=False):
db = self.getDb(channel)
cursor = db.cursor()
try: try:
cursor.execute("""SELECT tinyurls.tinyurl FROM urls, tinyurls fd = urllib2.urlopen('http://tinyurl.com/create.php?url=%s' %
WHERE urls.url=%s AND url)
tinyurls.url_id=urls.id""", url) s = fd.read()
except sqlite.OperationalError: fd.close()
raise m = self._tinyRe.search(s)
if cursor.rowcount == 0: if m is None:
updateDb = True tinyurl = None
try: else:
fd = urllib2.urlopen('http://tinyurl.com/create.php?url=%s' % tinyurl = m.group(1)
url) return tinyurl
s = fd.read() except urllib2.HTTPError, e:
fd.close() if cmd:
m = self._tinyRe.search(s) raise callbacks.Error, e.msg()
if m is None: else:
tinyurl = None self.log.warning(str(e))
else:
tinyurl = m.group(1)
except urllib2.HTTPError, e:
if cmd:
raise callbacks.Error, e.msg()
else:
self.log.warning(str(e))
else:
updateDb = False
tinyurl = cursor.fetchone()[0]
return (tinyurl, updateDb)
def _formatUrl(self, url, added, addedBy):
when = time.strftime(conf.supybot.humanTimestampFormat(),
time.localtime(int(added)))
return '<%s> (added by %s at %s)' % (url, addedBy, when)
def random(self, irc, msg, args):
"""[<channel>]
Returns a random URL from the URL database. <channel> is only required
if the message isn't sent in the channel itself.
"""
channel = privmsgs.getChannel(msg, args)
db = self.getDb(channel)
cursor = db.cursor()
cursor.execute("""SELECT url, added, added_by
FROM urls
ORDER BY random()
LIMIT 1""")
if cursor.rowcount == 0:
irc.reply('I have no URLs in my database for %s' % channel)
else:
irc.reply(self._formatUrl(*cursor.fetchone()))
def tiny(self, irc, msg, args): def tiny(self, irc, msg, args):
"""<url> """<url>
@ -305,15 +233,10 @@ class URL(callbacks.PrivmsgCommandAndRegexp,
minlen = self.registryValue('tinyurlSnarfer.minimumLength', channel) minlen = self.registryValue('tinyurlSnarfer.minimumLength', channel)
r = self.registryValue('nonSnarfingRegexp', channel) r = self.registryValue('nonSnarfingRegexp', channel)
if snarf and len(url) >= minlen and not r.search(url): if snarf and len(url) >= minlen and not r.search(url):
self.log.debug('Not applying tiny command, snarfer is active.')
return return
try: tinyurl = self._getTinyUrl(url, channel, cmd=True)
(tinyurl, updateDb) = self._getTinyUrl(url, channel, cmd=True)
except sqlite.OperationalError:
irc.error('The database just decided to crap itself.')
return
if tinyurl is not None: if tinyurl is not None:
if updateDb:
self._updateTinyDb(url, tinyurl, channel)
irc.reply(tinyurl) irc.reply(tinyurl)
else: else:
s = 'Could not parse the TinyURL.com results page.' s = 'Could not parse the TinyURL.com results page.'
@ -328,85 +251,54 @@ class URL(callbacks.PrivmsgCommandAndRegexp,
""" """
channel = privmsgs.getChannel(msg, args) channel = privmsgs.getChannel(msg, args)
db = self.getDb(channel) db = self.getDb(channel)
cursor = db.cursor() count = db.numUrls()
cursor.execute("""SELECT COUNT(*) FROM urls""") irc.reply('I have %s in my database.' % utils.nItems('URL', count))
(count,) = cursor.fetchone()
count = int(count)
irc.reply('I have %s %s in my database.' %
(count, count == 1 and 'URL' or 'URLs'))
def last(self, irc, msg, args): def last(self, irc, msg, args):
"""[<channel>] [--{from,with,at,proto,near}=<value>] --{nolimit,fancy} """[<channel>] [--{from,with,proto}=<value>] --{nolimit}
Gives the last URL matching the given criteria. --from is from whom Gives the last URL matching the given criteria. --from is from whom
the URL came; --at is the site of the URL; --proto is the protocol the the URL came; --proto is the protocol the URL used; --with is something
URL used; --with is something inside the URL; --near is a string in the inside the URL; If --nolimit is given, returns all the URLs that are
messages before and after the link. If --nolimit is given, returns found. to just the URL. <channel> is only necessary if the message
all the URLs that are found. --fancy returns information in addition isn't sent in the channel itself.
to just the URL. <channel> is only necessary if the message isn't sent
in the channel itself.
""" """
channel = privmsgs.getChannel(msg, args) channel = privmsgs.getChannel(msg, args)
(optlist, rest) = getopt.getopt(args, '', ['from=', 'with=', 'at=', (optlist, rest) = getopt.getopt(args, '', ['from=', 'with=',
'proto=', 'near=', 'proto=', 'nolimit',])
'nolimit', 'fancy']) predicates = []
criteria = ['1=1']
formats = []
simple = True
nolimit = False nolimit = False
for (option, argument) in optlist: for (option, arg) in optlist:
option = option.lstrip('-') # Strip off the --. if option == '--nolimit':
if option == 'nolimit':
nolimit = True nolimit = True
if option == 'fancy': elif option == '--from':
simple = False def from_(url, nick, arg=arg):
elif option == 'from': return nick.lower() == arg.lower()
criteria.append('added_by LIKE %s') predicates.append(from_)
formats.append(argument) elif option == '--with':
elif option == 'with': def with(url, nick, arg=arg):
if '%' not in argument and '_' not in argument: return arg in url
argument = '%%%s%%' % argument predicates.append(with)
criteria.append('url LIKE %s') elif option == '--proto':
formats.append(argument) def proto(url, nick, arg=arg):
elif option == 'at': return url.startswith(arg)
if '%' not in argument and '_' not in argument: predicates.append(proto)
argument = '%' + argument
criteria.append('site LIKE %s')
formats.append(argument)
elif option == 'proto':
criteria.append('protocol=%s')
formats.append(argument)
elif option == 'near':
criteria.append("""(previous_msg LIKE %s OR
next_msg LIKE %s OR
current_msg LIKE %s)""")
if '%' not in argument:
argument = '%%%s%%' % argument
formats.append(argument)
formats.append(argument)
formats.append(argument)
db = self.getDb(channel) db = self.getDb(channel)
cursor = db.cursor() def predicate(url, nick):
criterion = ' AND '.join(criteria) for predicate in predicates:
sql = """SELECT id, url, added, added_by if not predicate(url, nick):
FROM urls return False
WHERE %s ORDER BY id DESC return True
LIMIT 100""" % criterion urls = db.getUrls(predicate)
cursor.execute(sql, *formats) if not urls:
if cursor.rowcount == 0:
irc.reply('No URLs matched that criteria.') irc.reply('No URLs matched that criteria.')
else: else:
if nolimit: if nolimit:
urls = ['<%s>' % t[1] for t in cursor.fetchall()] urls = ['<%s>' % url for url in urls]
s = ', '.join(urls) s = ', '.join(urls)
elif simple:
s = cursor.fetchone()[1]
else: else:
(id, url, added, added_by) = cursor.fetchone() # We should optimize this with another URLDB method eventually.
timestamp = time.strftime('%I:%M %p, %B %d, %Y', s = urls[0]
time.localtime(int(added)))
s = '#%s: <%s>, added by %s at %s.' % \
(id, url, added_by, timestamp)
irc.reply(s) irc.reply(s)

View File

@ -66,111 +66,106 @@ http://gameknot.com/tsignup.pl
http://lambda.weblogs.com/xml/rss.xml http://lambda.weblogs.com/xml/rss.xml
""".strip().splitlines() """.strip().splitlines()
try: class URLTestCase(ChannelPluginTestCase, PluginDocumentation):
import sqlite plugins = ('URL',)
except ImportError: def setUp(self):
sqlite = None ChannelPluginTestCase.setUp(self)
conf.supybot.plugins.URL.tinyurlSnarfer.setValue(False)
if sqlite is not None: def test(self):
class URLTestCase(ChannelPluginTestCase, PluginDocumentation): counter = 0
plugins = ('URL',) #self.assertNotError('url random')
def setUp(self): for url in urls:
ChannelPluginTestCase.setUp(self)
conf.supybot.plugins.URL.tinyurlSnarfer.setValue(False)
def test(self):
counter = 0
self.assertNotError('url random')
for url in urls:
self.assertRegexp('url stats', str(counter))
self.feedMsg(url)
counter += 1
self.assertRegexp('url stats', str(counter)) self.assertRegexp('url stats', str(counter))
self.assertRegexp('url last', re.escape(urls[-1])) self.feedMsg(url)
self.assertRegexp('url last --proto https', re.escape(urls[-3])) counter += 1
self.assertRegexp('url last --at gameknot.com',re.escape(urls[-2])) self.assertRegexp('url stats', str(counter))
self.assertRegexp('url last --with dhcp', re.escape(urls[-4])) self.assertRegexp('url last', re.escape(urls[-1]))
self.assertRegexp('url last --from alsdkjf', '^No') self.assertRegexp('url last --proto https', re.escape(urls[-3]))
self.assertNotError('url random') self.assertRegexp('url last --with gameknot.com',
re.escape(urls[-2]))
self.assertRegexp('url last --with dhcp', re.escape(urls[-4]))
self.assertRegexp('url last --from alsdkjf', '^No')
self.assertNotError('url random')
def testDefaultNotFancy(self): def testDefaultNotFancy(self):
self.feedMsg(urls[0]) self.feedMsg(urls[0])
self.assertResponse('url last', urls[0]) self.assertResponse('url last', urls[0])
def testAction(self): def testAction(self):
self.irc.feedMsg(ircmsgs.action(self.channel, urls[1])) self.irc.feedMsg(ircmsgs.action(self.channel, urls[1]))
self.assertNotRegexp('url last', '\\x01') self.assertNotRegexp('url last', '\\x01')
def testNonSnarfingRegexpConfigurable(self): def testNonSnarfingRegexpConfigurable(self):
self.assertNoResponse('http://foo.bar.baz/', 2) self.assertNoResponse('http://foo.bar.baz/', 2)
self.assertResponse('url last', 'http://foo.bar.baz/')
try:
conf.supybot.plugins.URL.nonSnarfingRegexp.set('m/biff/i')
self.assertNoResponse('http://biff.bar.baz/', 2)
self.assertResponse('url last', 'http://foo.bar.baz/') self.assertResponse('url last', 'http://foo.bar.baz/')
finally:
conf.supybot.plugins.URL.nonSnarfingRegexp.set('')
if network:
def testTinyurl(self):
try: try:
conf.supybot.plugins.URL.nonSnarfingRegexp.set('m/biff/i') conf.supybot.plugins.URL.tinyurlSnarfer.setValue(False)
self.assertNoResponse('http://biff.bar.baz/', 2) self.assertRegexp(
self.assertResponse('url last', 'http://foo.bar.baz/') 'url tiny http://sourceforge.net/tracker/?'
'func=add&group_id=58965&atid=489447',
r'http://tinyurl.com/rqac')
conf.supybot.plugins.URL.tinyurlSnarfer.setValue(True)
self.assertRegexp(
'url tiny http://sourceforge.net/tracker/?'
'func=add&group_id=58965&atid=489447',
r'http://tinyurl.com/rqac')
finally: finally:
conf.supybot.plugins.URL.nonSnarfingRegexp.set('') conf.supybot.plugins.URL.tinyurlSnarfer.setValue(False)
if network: def testTinysnarf(self):
def testTinyurl(self): try:
try: conf.supybot.plugins.URL.tinyurlSnarfer.setValue(True)
conf.supybot.plugins.URL.tinyurlSnarfer.setValue(False) self.assertRegexp('http://sourceforge.net/tracker/?'
self.assertRegexp( 'func=add&group_id=58965&atid=489447',
'url tiny http://sourceforge.net/tracker/?' r'http://tinyurl.com/rqac.* \(at')
'func=add&group_id=58965&atid=489447', self.assertRegexp(
r'http://tinyurl.com/rqac') 'http://www.urbandictionary.com/define.php?'
conf.supybot.plugins.URL.tinyurlSnarfer.setValue(True) 'term=all+your+base+are+belong+to+us',
self.assertRegexp( r'http://tinyurl.com/u479.* \(at')
'url tiny http://sourceforge.net/tracker/?' finally:
'func=add&group_id=58965&atid=489447', conf.supybot.plugins.URL.tinyurlSnarfer.setValue(False)
r'http://tinyurl.com/rqac')
finally:
conf.supybot.plugins.URL.tinyurlSnarfer.setValue(False)
def testTinysnarf(self): def testTitleSnarfer(self):
try:
conf.supybot.plugins.URL.titleSnarfer.setValue(True)
self.assertResponse('http://microsoft.com/',
'Title: Microsoft Corporation'
' (at microsoft.com)')
finally:
conf.supybot.plugins.URL.titleSnarfer.setValue(False)
def testNonSnarfing(self):
tiny = conf.supybot.plugins.URL.tinyurlSnarfer()
snarf = conf.supybot.plugins.URL.nonSnarfingRegexp()
title = conf.supybot.plugins.URL.titleSnarfer()
try:
conf.supybot.plugins.URL.nonSnarfingRegexp.set('m/sf/')
try: try:
conf.supybot.plugins.URL.tinyurlSnarfer.setValue(True) conf.supybot.plugins.URL.tinyurlSnarfer.setValue(True)
self.assertRegexp('http://sourceforge.net/tracker/?' self.assertNoResponse('http://sf.net/', 2)
'func=add&group_id=58965&atid=489447', self.assertResponse('http://www.sourceforge.net/',
r'http://tinyurl.com/rqac.* \(at') 'http://tinyurl.com/2cnkf')
self.assertRegexp(
'http://www.urbandictionary.com/define.php?'
'term=all+your+base+are+belong+to+us',
r'http://tinyurl.com/u479.* \(at')
finally: finally:
conf.supybot.plugins.URL.tinyurlSnarfer.setValue(False) conf.supybot.plugins.URL.tinyurlSnarfer.setValue(tiny)
def testTitleSnarfer(self):
try: try:
conf.supybot.plugins.URL.titleSnarfer.setValue(True) conf.supybot.plugins.URL.titleSnarfer.setValue(True)
self.assertResponse('http://microsoft.com/', self.assertNoResponse('http://sf.net/', 2)
'Title: Microsoft Corporation' self.assertRegexp('http://www.sourceforge.net/',
' (at microsoft.com)') r'Sourceforge\.net')
finally: finally:
conf.supybot.plugins.URL.titleSnarfer.setValue(False) conf.supybot.plugins.URL.titleSnarfer.setValue(title)
finally:
def testNonSnarfing(self): conf.supybot.plugins.URL.nonSnarfingRegexp.setValue(snarf)
tiny = conf.supybot.plugins.URL.tinyurlSnarfer()
snarf = conf.supybot.plugins.URL.nonSnarfingRegexp()
title = conf.supybot.plugins.URL.titleSnarfer()
try:
conf.supybot.plugins.URL.nonSnarfingRegexp.set('m/sf/')
try:
conf.supybot.plugins.URL.tinyurlSnarfer.setValue(True)
self.assertNoResponse('http://sf.net/', 2)
self.assertResponse('http://www.sourceforge.net/',
'http://tinyurl.com/2cnkf')
finally:
conf.supybot.plugins.URL.tinyurlSnarfer.setValue(tiny)
try:
conf.supybot.plugins.URL.titleSnarfer.setValue(True)
self.assertNoResponse('http://sf.net/', 2)
self.assertRegexp('http://www.sourceforge.net/',
r'Sourceforge\.net')
finally:
conf.supybot.plugins.URL.titleSnarfer.setValue(title)
finally:
conf.supybot.plugins.URL.nonSnarfingRegexp.setValue(snarf)