diff --git a/plugins/RSS/plugin.py b/plugins/RSS/plugin.py index 6b9e579bc..98874916f 100644 --- a/plugins/RSS/plugin.py +++ b/plugins/RSS/plugin.py @@ -63,6 +63,18 @@ addConverter('feedName', get_feedName) announced_headlines_filename = \ conf.supybot.directories.data.dirize('RSS_announced.flat') +def only_one_at_once(f): + lock = [False] + def newf(*args, **kwargs): + if lock[0]: + return + lock[0] = True + try: + f(*args, **kwargs) + finally: + lock[0] = False + return newf + class Feed: __slots__ = ('url', 'name', 'data', 'last_update', 'entries', 'etag', 'modified', 'initial', @@ -129,7 +141,6 @@ def save_announces_db(db, fd): json.dump(dict((name, list(entries)) for (name, entries) in db), fd) - class RSS(callbacks.Plugin): """This plugin is useful both for announcing updates to RSS feeds in a channel, and for retrieving the headlines of RSS feeds via command. Use @@ -230,7 +241,7 @@ class RSS(callbacks.Plugin): def __call__(self, irc, msg): self.__parent.__call__(irc, msg) - self.update_feeds() + threading.Thread(target=self.update_feeds).start() ################## @@ -274,6 +285,7 @@ class RSS(callbacks.Plugin): if self.is_expired(feed): self.update_feed(feed) + @only_one_at_once def update_feeds(self): announced_feeds = set() for irc in world.ircs: diff --git a/src/httpserver.py b/src/httpserver.py index 242bf2d3b..315aeaa62 100644 --- a/src/httpserver.py +++ b/src/httpserver.py @@ -242,12 +242,15 @@ class SupyHTTPRequestHandler(BaseHTTPRequestHandler): def do_POST(self): if 'Content-Type' not in self.headers: self.headers['Content-Type'] = 'application/x-www-form-urlencoded' - form = cgi.FieldStorage( - fp=self.rfile, - headers=self.headers, - environ={'REQUEST_METHOD':'POST', - 'CONTENT_TYPE':self.headers['Content-Type'], - }) + if self.headers['Content-Type'] == 'application/x-www-form-urlencoded': + form = cgi.FieldStorage( + fp=self.rfile, + headers=self.headers, + environ={'REQUEST_METHOD':'POST', + 'CONTENT_TYPE':self.headers['Content-Type'], + }) + else: + form = self.rfile.read() self.do_X('doPost', form=form) def do_HEAD(self):