Factoids: Fix compatibility of web server with Python 3. Closes GH-784.

This commit is contained in:
Valentin Lorentz 2014-08-04 13:21:27 +00:00
parent f39e6363ed
commit d431c2992b
3 changed files with 16 additions and 5 deletions

View File

@ -124,14 +124,14 @@ class FactoidsCallback(httpserver.SupyHTTPServerCallback):
self.send_response(200)
self.send_header('Content-type', 'text/html; charset=utf-8')
self.end_headers()
self.wfile.write(httpserver.get_template('factoids/index.html'))
self.write(httpserver.get_template('factoids/index.html'))
elif len(parts) == 2:
channel = urllib.unquote(parts[0])
if not ircutils.isChannel(channel):
self.send_response(404)
self.send_header('Content-type', 'text/html; charset=utf-8')
self.end_headers()
self.wfile.write(httpserver.get_template('generic/error.html')%
self.write(httpserver.get_template('generic/error.html')%
{'title': 'Factoids - not a channel',
'error': 'This is not a channel'})
return
@ -139,7 +139,7 @@ class FactoidsCallback(httpserver.SupyHTTPServerCallback):
self.send_response(403)
self.send_header('Content-type', 'text/html; charset=utf-8')
self.end_headers()
self.wfile.write(httpserver.get_template('generic/error.html')%
self.write(httpserver.get_template('generic/error.html')%
{'title': 'Factoids - unavailable',
'error': 'This channel does not exist or its factoids '
'are not available here.'})
@ -172,7 +172,7 @@ class FactoidsCallback(httpserver.SupyHTTPServerCallback):
self.send_response(200)
self.send_header('Content-type', 'text/html; charset=utf-8')
self.end_headers()
self.wfile.write(httpserver.get_template('factoids/channel.html')%
self.write(httpserver.get_template('factoids/channel.html')%
{'channel': channel, 'rows': content})
def doPost(self, handler, path, form):
if 'chan' in form:
@ -184,7 +184,7 @@ class FactoidsCallback(httpserver.SupyHTTPServerCallback):
self.send_response(400)
self.send_header('Content-type', 'text/plain; charset=utf-8')
self.end_headers()
self.wfile.write('Missing field \'chan\'.')
self.write('Missing field \'chan\'.')
class Factoids(callbacks.Plugin, plugins.ChannelDBHandler):
def __init__(self, irc):

View File

@ -282,6 +282,8 @@ class RSS(callbacks.Plugin):
if entry.id not in feed.announced_entries]
if not new_entries:
return []
print(repr(feed.announced_entries))
print(repr(new_entries))
feed.announced_entries |= set(entry.id for entry in new_entries)
# We keep a little more because we don't want to re-announce
# oldest entries if one of the newest gets removed.

View File

@ -277,6 +277,15 @@ class SupyHTTPServerCallback(object):
message, it probably means you are developing a plugin, and you have
neither overriden this message or defined an handler for this query.""")
if sys.version_info[0] >= 3:
def write(self, b):
if isinstance(b, str):
b = b.encode()
self.wfile.write(b)
else:
def write(self, s):
self.wfile.write(s)
def doGet(self, handler, path, *args, **kwargs):
handler.send_response(400)
self.send_header('Content-Type', 'text/plain; charset=utf-8; charset=utf-8')