mirror of
https://github.com/Mikaela/Limnoria.git
synced 2025-01-25 19:44:13 +01:00
plugins/RSS: Stop using attributes for feeds.
This commit is contained in:
parent
4baff174a5
commit
7fdb72ab4f
@ -27,6 +27,7 @@
|
|||||||
# POSSIBILITY OF SUCH DAMAGE.
|
# POSSIBILITY OF SUCH DAMAGE.
|
||||||
###
|
###
|
||||||
|
|
||||||
|
import new
|
||||||
import time
|
import time
|
||||||
import socket
|
import socket
|
||||||
import sgmllib
|
import sgmllib
|
||||||
@ -58,7 +59,8 @@ class RSS(callbacks.Plugin):
|
|||||||
def __init__(self, irc):
|
def __init__(self, irc):
|
||||||
self.__parent = super(RSS, self)
|
self.__parent = super(RSS, self)
|
||||||
self.__parent.__init__(irc)
|
self.__parent.__init__(irc)
|
||||||
self.feedNames = callbacks.CanonicalNameSet()
|
# Schema is feed : [url, command]
|
||||||
|
self.feedNames = callbacks.CanonicalNameDict()
|
||||||
self.locks = {}
|
self.locks = {}
|
||||||
self.lastRequest = {}
|
self.lastRequest = {}
|
||||||
self.cachedFeeds = {}
|
self.cachedFeeds = {}
|
||||||
@ -73,6 +75,27 @@ class RSS(callbacks.Plugin):
|
|||||||
self.makeFeedCommand(name, url)
|
self.makeFeedCommand(name, url)
|
||||||
self.getFeed(url) # So announced feeds don't announce on startup.
|
self.getFeed(url) # So announced feeds don't announce on startup.
|
||||||
|
|
||||||
|
def isCommandMethod(self, name):
|
||||||
|
if not self.__parent.isCommandMethod(name):
|
||||||
|
if name in self.feedNames:
|
||||||
|
return True
|
||||||
|
else:
|
||||||
|
return False
|
||||||
|
else:
|
||||||
|
return True
|
||||||
|
|
||||||
|
def listCommands(self):
|
||||||
|
commands = self.__parent.listCommands()
|
||||||
|
commands.extend(self.feedNames.keys())
|
||||||
|
commands.sort()
|
||||||
|
return commands
|
||||||
|
|
||||||
|
def getCommandMethod(self, command):
|
||||||
|
try:
|
||||||
|
return self.__parent.getCommandMethod(command)
|
||||||
|
except AttributeError:
|
||||||
|
return self.feedNames[command[0]][1]
|
||||||
|
|
||||||
def _registerFeed(self, name, url=''):
|
def _registerFeed(self, name, url=''):
|
||||||
self.registryValue('feeds').add(name)
|
self.registryValue('feeds').add(name)
|
||||||
group = self.registryValue('feeds', value=False)
|
group = self.registryValue('feeds', value=False)
|
||||||
@ -87,8 +110,7 @@ class RSS(callbacks.Plugin):
|
|||||||
for name in feeds:
|
for name in feeds:
|
||||||
commandName = callbacks.canonicalName(name)
|
commandName = callbacks.canonicalName(name)
|
||||||
if self.isCommandMethod(commandName):
|
if self.isCommandMethod(commandName):
|
||||||
name = commandName
|
url = self.feedNames[commandName][0]
|
||||||
url = getattr(self, name).url
|
|
||||||
else:
|
else:
|
||||||
url = name
|
url = name
|
||||||
if self.willGetNewFeed(url):
|
if self.willGetNewFeed(url):
|
||||||
@ -255,17 +277,15 @@ class RSS(callbacks.Plugin):
|
|||||||
""", name, url)
|
""", name, url)
|
||||||
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.__class__, name) and \
|
if self.isCommandMethod(name):
|
||||||
not hasattr(getattr(self, name), 'url'):
|
|
||||||
s = format('I already have a command in this plugin named %s.',name)
|
s = format('I already have a command in this plugin named %s.',name)
|
||||||
raise callbacks.Error, s
|
raise callbacks.Error, s
|
||||||
def f(self, irc, msg, args):
|
def f(self, irc, msg, args):
|
||||||
args.insert(0, url)
|
args.insert(0, url)
|
||||||
self.rss(irc, msg, args)
|
self.rss(irc, msg, args)
|
||||||
f = utils.python.changeFunctionName(f, name, docstring)
|
f = utils.python.changeFunctionName(f, name, docstring)
|
||||||
f.url = url # Used by __call__.
|
f = new.instancemethod(f, self, RSS)
|
||||||
self.feedNames.add(name)
|
self.feedNames[name] = (url, f)
|
||||||
setattr(self.__class__, name, f)
|
|
||||||
self._registerFeed(name, url)
|
self._registerFeed(name, url)
|
||||||
|
|
||||||
def add(self, irc, msg, args, name, url):
|
def add(self, irc, msg, args, name, url):
|
||||||
@ -287,8 +307,7 @@ class RSS(callbacks.Plugin):
|
|||||||
if name not in self.feedNames:
|
if name not in self.feedNames:
|
||||||
irc.error('That\'s not a valid RSS feed command name.')
|
irc.error('That\'s not a valid RSS feed command name.')
|
||||||
return
|
return
|
||||||
self.feedNames.remove(name)
|
self.feedNames.pop(name)
|
||||||
delattr(self.__class__, name)
|
|
||||||
conf.supybot.plugins.RSS.feeds().remove(name)
|
conf.supybot.plugins.RSS.feeds().remove(name)
|
||||||
conf.supybot.plugins.RSS.feeds.unregister(name)
|
conf.supybot.plugins.RSS.feeds.unregister(name)
|
||||||
irc.replySuccess()
|
irc.replySuccess()
|
||||||
|
@ -60,6 +60,7 @@ class RSSTestCase(ChannelPluginTestCase):
|
|||||||
self.assertNotError('rss add advogato %s' % url)
|
self.assertNotError('rss add advogato %s' % url)
|
||||||
self.assertNotError('rss announce advogato')
|
self.assertNotError('rss announce advogato')
|
||||||
self.assertNotRegexp('rss announce', r'ValueError')
|
self.assertNotRegexp('rss announce', r'ValueError')
|
||||||
|
self.assertNotError('rss remove advogato')
|
||||||
|
|
||||||
def testRss(self):
|
def testRss(self):
|
||||||
self.assertNotError('rss %s' % url)
|
self.assertNotError('rss %s' % url)
|
||||||
|
Loading…
Reference in New Issue
Block a user