mirror of
https://github.com/zhigang1992/mitmproxy.git
synced 2026-04-28 20:24:59 +08:00
Porting to Python 3.4
Updated wsgi to support Python 3.4 byte strings. Updated test_wsgi to remove py.test warning for TestApp having an __init__ constructor. samc$ sudo py.test netlib/test/test_wsgi.py -r w = test session starts = platform darwin -- Python 3.4.1, pytest-2.8.2, py-1.4.30, pluggy-0.3.1 rootdir: /Users/samc/src/python/netlib, inifile: collected 6 items netlib/test/test_wsgi.py ...... = 6 passed in 0.20 seconds =
This commit is contained in:
@@ -96,16 +96,17 @@ class WSGIAdaptor(object):
|
||||
Make a best-effort attempt to write an error page. If headers are
|
||||
already sent, we just bung the error into the page.
|
||||
"""
|
||||
c = b"""
|
||||
c = """
|
||||
<html>
|
||||
<h1>Internal Server Error</h1>
|
||||
<pre>%s"</pre>
|
||||
<pre>{err}"</pre>
|
||||
</html>
|
||||
""".strip() % s.encode()
|
||||
""".format(err=s).strip().encode()
|
||||
|
||||
if not headers_sent:
|
||||
soc.write(b"HTTP/1.1 500 Internal Server Error\r\n")
|
||||
soc.write(b"Content-Type: text/html\r\n")
|
||||
soc.write(b"Content-Length: %s\r\n" % len(c))
|
||||
soc.write("Content-Length: {length}\r\n".format(length=len(c)).encode())
|
||||
soc.write(b"\r\n")
|
||||
soc.write(c)
|
||||
|
||||
@@ -119,7 +120,7 @@ class WSGIAdaptor(object):
|
||||
|
||||
def write(data):
|
||||
if not state["headers_sent"]:
|
||||
soc.write(b"HTTP/1.1 %s\r\n" % state["status"].encode())
|
||||
soc.write("HTTP/1.1 {status}\r\n".format(status=state["status"]).encode())
|
||||
headers = state["headers"]
|
||||
if 'server' not in headers:
|
||||
headers["Server"] = self.sversion
|
||||
|
||||
@@ -12,8 +12,6 @@ def tflow():
|
||||
|
||||
class TestApp:
|
||||
|
||||
def __init__(self):
|
||||
self.called = False
|
||||
|
||||
def __call__(self, environ, start_response):
|
||||
self.called = True
|
||||
|
||||
Reference in New Issue
Block a user