mirror of
https://github.com/Mikaela/Limnoria.git
synced 2025-01-22 18:14:41 +01:00
Factoids: Fix compatibility of web server with Python 3. Closes GH-784.
This commit is contained in:
parent
f39e6363ed
commit
d431c2992b
@ -124,14 +124,14 @@ class FactoidsCallback(httpserver.SupyHTTPServerCallback):
|
|||||||
self.send_response(200)
|
self.send_response(200)
|
||||||
self.send_header('Content-type', 'text/html; charset=utf-8')
|
self.send_header('Content-type', 'text/html; charset=utf-8')
|
||||||
self.end_headers()
|
self.end_headers()
|
||||||
self.wfile.write(httpserver.get_template('factoids/index.html'))
|
self.write(httpserver.get_template('factoids/index.html'))
|
||||||
elif len(parts) == 2:
|
elif len(parts) == 2:
|
||||||
channel = urllib.unquote(parts[0])
|
channel = urllib.unquote(parts[0])
|
||||||
if not ircutils.isChannel(channel):
|
if not ircutils.isChannel(channel):
|
||||||
self.send_response(404)
|
self.send_response(404)
|
||||||
self.send_header('Content-type', 'text/html; charset=utf-8')
|
self.send_header('Content-type', 'text/html; charset=utf-8')
|
||||||
self.end_headers()
|
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',
|
{'title': 'Factoids - not a channel',
|
||||||
'error': 'This is not a channel'})
|
'error': 'This is not a channel'})
|
||||||
return
|
return
|
||||||
@ -139,7 +139,7 @@ class FactoidsCallback(httpserver.SupyHTTPServerCallback):
|
|||||||
self.send_response(403)
|
self.send_response(403)
|
||||||
self.send_header('Content-type', 'text/html; charset=utf-8')
|
self.send_header('Content-type', 'text/html; charset=utf-8')
|
||||||
self.end_headers()
|
self.end_headers()
|
||||||
self.wfile.write(httpserver.get_template('generic/error.html')%
|
self.write(httpserver.get_template('generic/error.html')%
|
||||||
{'title': 'Factoids - unavailable',
|
{'title': 'Factoids - unavailable',
|
||||||
'error': 'This channel does not exist or its factoids '
|
'error': 'This channel does not exist or its factoids '
|
||||||
'are not available here.'})
|
'are not available here.'})
|
||||||
@ -172,7 +172,7 @@ class FactoidsCallback(httpserver.SupyHTTPServerCallback):
|
|||||||
self.send_response(200)
|
self.send_response(200)
|
||||||
self.send_header('Content-type', 'text/html; charset=utf-8')
|
self.send_header('Content-type', 'text/html; charset=utf-8')
|
||||||
self.end_headers()
|
self.end_headers()
|
||||||
self.wfile.write(httpserver.get_template('factoids/channel.html')%
|
self.write(httpserver.get_template('factoids/channel.html')%
|
||||||
{'channel': channel, 'rows': content})
|
{'channel': channel, 'rows': content})
|
||||||
def doPost(self, handler, path, form):
|
def doPost(self, handler, path, form):
|
||||||
if 'chan' in form:
|
if 'chan' in form:
|
||||||
@ -184,7 +184,7 @@ class FactoidsCallback(httpserver.SupyHTTPServerCallback):
|
|||||||
self.send_response(400)
|
self.send_response(400)
|
||||||
self.send_header('Content-type', 'text/plain; charset=utf-8')
|
self.send_header('Content-type', 'text/plain; charset=utf-8')
|
||||||
self.end_headers()
|
self.end_headers()
|
||||||
self.wfile.write('Missing field \'chan\'.')
|
self.write('Missing field \'chan\'.')
|
||||||
|
|
||||||
class Factoids(callbacks.Plugin, plugins.ChannelDBHandler):
|
class Factoids(callbacks.Plugin, plugins.ChannelDBHandler):
|
||||||
def __init__(self, irc):
|
def __init__(self, irc):
|
||||||
|
@ -282,6 +282,8 @@ class RSS(callbacks.Plugin):
|
|||||||
if entry.id not in feed.announced_entries]
|
if entry.id not in feed.announced_entries]
|
||||||
if not new_entries:
|
if not new_entries:
|
||||||
return []
|
return []
|
||||||
|
print(repr(feed.announced_entries))
|
||||||
|
print(repr(new_entries))
|
||||||
feed.announced_entries |= set(entry.id for entry in 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
|
# We keep a little more because we don't want to re-announce
|
||||||
# oldest entries if one of the newest gets removed.
|
# oldest entries if one of the newest gets removed.
|
||||||
|
@ -277,6 +277,15 @@ class SupyHTTPServerCallback(object):
|
|||||||
message, it probably means you are developing a plugin, and you have
|
message, it probably means you are developing a plugin, and you have
|
||||||
neither overriden this message or defined an handler for this query.""")
|
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):
|
def doGet(self, handler, path, *args, **kwargs):
|
||||||
handler.send_response(400)
|
handler.send_response(400)
|
||||||
self.send_header('Content-Type', 'text/plain; charset=utf-8; charset=utf-8')
|
self.send_header('Content-Type', 'text/plain; charset=utf-8; charset=utf-8')
|
||||||
|
Loading…
Reference in New Issue
Block a user