This commit is contained in:
Jeremy Fincher 2004-04-29 11:49:24 +00:00
parent 8274d5dfb9
commit 2c2e21e765
3 changed files with 26 additions and 2 deletions

View File

@ -231,6 +231,11 @@ class RSS(callbacks.Privmsg):
def getHeadlines(self, feed): def getHeadlines(self, feed):
return [utils.htmlToText(d['title'].strip()) for d in feed['items']] return [utils.htmlToText(d['title'].strip()) for d in feed['items']]
def _validFeedName(self, name):
if not registry.isValidRegistryName(name):
raise ValueError, name
return callbacks.canonicalName(name)
def makeFeedCommand(self, name, url): def makeFeedCommand(self, name, url):
docstring = """<number of headlines> docstring = """<number of headlines>
@ -240,7 +245,7 @@ class RSS(callbacks.Privmsg):
seconds, which defaults to 1800 (30 minutes) since that's what most seconds, which defaults to 1800 (30 minutes) since that's what most
websites prefer. websites prefer.
""" % (name, url) """ % (name, url)
name = callbacks.canonicalName(name) assert name == self._validFeedName(name)
if url not in self.locks: if url not in self.locks:
self.locks[url] = threading.RLock() self.locks[url] = threading.RLock()
if hasattr(self, name): if hasattr(self, name):
@ -262,6 +267,12 @@ class RSS(callbacks.Privmsg):
given URL. given URL.
""" """
(name, url) = privmsgs.getArgs(args, required=2) (name, url) = privmsgs.getArgs(args, required=2)
try:
name = self._validFeedName(name)
except ValueError:
irc.error('%r is not a valid feed name. Feed names must not '
'include dots, colons, or spaces.' % name)
return
self.makeFeedCommand(name, url) self.makeFeedCommand(name, url)
irc.replySuccess() irc.replySuccess()
@ -317,7 +328,7 @@ class RSS(callbacks.Privmsg):
try: try:
n = int(n) n = int(n)
except ValueError: except ValueError:
raise callbacks.Error raise callbacks.ArgumentError
headlines = headlines[:n] headlines = headlines[:n]
headlines = imap(utils.htmlToText, headlines) headlines = imap(utils.htmlToText, headlines)
sep = self.registryValue('headlineSeparator', channel) sep = self.registryValue('headlineSeparator', channel)

View File

@ -47,6 +47,9 @@ class RegistryException(Exception):
class InvalidRegistryFile(RegistryException): class InvalidRegistryFile(RegistryException):
pass pass
class InvalidRegistryName(RegistryException):
pass
class InvalidRegistryValue(RegistryException): class InvalidRegistryValue(RegistryException):
pass pass
@ -100,6 +103,9 @@ def close(registry, filename, annotated=True, helpOnceOnly=False):
fd.write('%s: %s\n' % (name, value)) fd.write('%s: %s\n' % (name, value))
fd.close() fd.close()
def isValidRegistryName(name):
return '.' not in name and ':' not in name and len(name.split()) == 1
class Group(object): class Group(object):
def __init__(self, supplyDefault=False): def __init__(self, supplyDefault=False):
@ -161,6 +167,8 @@ class Group(object):
pass pass
def register(self, name, node=None): def register(self, name, node=None):
if not isValidRegistryName(name):
raise InvalidRegistryName, name
if node is None: if node is None:
node = Group() node = Group()
if name not in self.children: # XXX Is this right? if name not in self.children: # XXX Is this right?

View File

@ -63,6 +63,11 @@ if network:
finally: finally:
conf.supybot.reply.whenNotCommand.setValue(orig) conf.supybot.reply.whenNotCommand.setValue(orig)
def testRssAddBadName(self):
self.assertError('rss add . %s' % url)
self.assertError('rss add : %s' % url)
self.assertError('rss add "foo bar" %s' % url)
def testCantAddFeedNamedRss(self): def testCantAddFeedNamedRss(self):
self.assertError('rss add rss %s' % url) self.assertError('rss add rss %s' % url)