mirror of
https://github.com/Mikaela/Limnoria.git
synced 2024-10-14 17:59:29 +02:00
Reduced functionality, but I doubt anyone will complain. Much cleaner and clearer now that we're using flat files.
This commit is contained in:
parent
46383f9fc7
commit
d594232c5c
@ -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
|
||||||
|
298
plugins/URL.py
298
plugins/URL.py
@ -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,29 +200,8 @@ 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:
|
|
||||||
cursor.execute("""SELECT tinyurls.tinyurl FROM urls, tinyurls
|
|
||||||
WHERE urls.url=%s AND
|
|
||||||
tinyurls.url_id=urls.id""", url)
|
|
||||||
except sqlite.OperationalError:
|
|
||||||
raise
|
|
||||||
if cursor.rowcount == 0:
|
|
||||||
updateDb = True
|
|
||||||
try:
|
try:
|
||||||
fd = urllib2.urlopen('http://tinyurl.com/create.php?url=%s' %
|
fd = urllib2.urlopen('http://tinyurl.com/create.php?url=%s' %
|
||||||
url)
|
url)
|
||||||
@ -258,38 +212,12 @@ class URL(callbacks.PrivmsgCommandAndRegexp,
|
|||||||
tinyurl = None
|
tinyurl = None
|
||||||
else:
|
else:
|
||||||
tinyurl = m.group(1)
|
tinyurl = m.group(1)
|
||||||
|
return tinyurl
|
||||||
except urllib2.HTTPError, e:
|
except urllib2.HTTPError, e:
|
||||||
if cmd:
|
if cmd:
|
||||||
raise callbacks.Error, e.msg()
|
raise callbacks.Error, e.msg()
|
||||||
else:
|
else:
|
||||||
self.log.warning(str(e))
|
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)
|
||||||
|
|
||||||
|
|
||||||
|
@ -66,12 +66,6 @@ http://gameknot.com/tsignup.pl
|
|||||||
http://lambda.weblogs.com/xml/rss.xml
|
http://lambda.weblogs.com/xml/rss.xml
|
||||||
""".strip().splitlines()
|
""".strip().splitlines()
|
||||||
|
|
||||||
try:
|
|
||||||
import sqlite
|
|
||||||
except ImportError:
|
|
||||||
sqlite = None
|
|
||||||
|
|
||||||
if sqlite is not None:
|
|
||||||
class URLTestCase(ChannelPluginTestCase, PluginDocumentation):
|
class URLTestCase(ChannelPluginTestCase, PluginDocumentation):
|
||||||
plugins = ('URL',)
|
plugins = ('URL',)
|
||||||
def setUp(self):
|
def setUp(self):
|
||||||
@ -80,7 +74,7 @@ if sqlite is not None:
|
|||||||
|
|
||||||
def test(self):
|
def test(self):
|
||||||
counter = 0
|
counter = 0
|
||||||
self.assertNotError('url random')
|
#self.assertNotError('url random')
|
||||||
for url in urls:
|
for url in urls:
|
||||||
self.assertRegexp('url stats', str(counter))
|
self.assertRegexp('url stats', str(counter))
|
||||||
self.feedMsg(url)
|
self.feedMsg(url)
|
||||||
@ -88,7 +82,8 @@ if sqlite is not None:
|
|||||||
self.assertRegexp('url stats', str(counter))
|
self.assertRegexp('url stats', str(counter))
|
||||||
self.assertRegexp('url last', re.escape(urls[-1]))
|
self.assertRegexp('url last', re.escape(urls[-1]))
|
||||||
self.assertRegexp('url last --proto https', re.escape(urls[-3]))
|
self.assertRegexp('url last --proto https', re.escape(urls[-3]))
|
||||||
self.assertRegexp('url last --at gameknot.com',re.escape(urls[-2]))
|
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 --with dhcp', re.escape(urls[-4]))
|
||||||
self.assertRegexp('url last --from alsdkjf', '^No')
|
self.assertRegexp('url last --from alsdkjf', '^No')
|
||||||
self.assertNotError('url random')
|
self.assertNotError('url random')
|
||||||
|
Loading…
Reference in New Issue
Block a user