core: Various Python 3 compatibility fixes.

This commit is contained in:
Valentin Lorentz 2013-03-25 19:15:08 +01:00
parent 3137db859f
commit 916a85c965
4 changed files with 13 additions and 8 deletions

View File

@ -888,6 +888,7 @@ class first(context):
spec(irc, msg, args, state)
return
except Exception, e:
e2 = e # 'e' is local.
errored = state.errored
state.errored = False
continue
@ -895,7 +896,7 @@ class first(context):
state.args.append(self.default)
else:
state.errored = errored
raise e
raise e2
class reverse(context):
def __call__(self, irc, msg, args, state):

View File

@ -257,7 +257,7 @@ class SupyHTTPServerCallback:
self.send_header('Content_type', 'text/plain; charset=utf-8')
self.send_header('Content-Length', len(self.defaultResponse))
self.end_headers()
self.wfile.write(self.defaultResponse)
self.wfile.write(self.defaultResponse.encode())
doPost = doHead = doGet
@ -279,7 +279,7 @@ class Supy404(SupyHTTPServerCallback):
self.send_header('Content_type', 'text/plain; charset=utf-8')
self.send_header('Content-Length', len(self.response))
self.end_headers()
self.wfile.write(self.response)
self.wfile.write(self.response.encode())
doPost = doHead = doGet
@ -346,7 +346,7 @@ class Favicon(SupyHTTPServerCallback):
self.send_header('Content-type', 'text/plain')
self.send_header('Content-Length', len(response))
self.end_headers()
self.wfile.write(response)
self.wfile.write(response.encode())
http_servers = None

View File

@ -38,7 +38,6 @@ import urllib
import httplib
import unittest
import threading
import StringIO
import supybot.log as log
import supybot.i18n as i18n
@ -599,8 +598,12 @@ class HTTPPluginTestCase(PluginTestCase):
def request(self, url, method='GET', read=True, data={}):
assert url.startswith('/')
wfile = StringIO.StringIO()
rfile = StringIO.StringIO()
try:
from io import BytesIO as StringIO
except ImportError:
from StringIO import StringIO
wfile = StringIO()
rfile = StringIO()
connection = FakeHTTPConnection(wfile, rfile)
connection.putrequest(method, url)
connection.endheaders()

View File

@ -459,7 +459,8 @@ def format(s, *args, **kwargs):
return has(args.pop())
elif char == 'L':
t = args.pop()
if isinstance(t, list):
if isinstance(t, list) or (sys.version_info[0] >= 3 and
(isinstance(t, map) or isinstance(t, filter))):
return commaAndify(t)
elif isinstance(t, tuple) and len(t) == 2:
if not isinstance(t[0], list):