diff options
author | Maximilian Hils <git@maximilianhils.com> | 2015-11-14 22:15:24 -0800 |
---|---|---|
committer | Maximilian Hils <git@maximilianhils.com> | 2015-11-14 22:15:24 -0800 |
commit | 0df7e27c3b43164dc41f5b37a6e425e8a719c6e9 (patch) | |
tree | 4d241c4532f751f6aa5f8a19c760a5ff8f3db0da /netlib | |
parent | 5916260849504ccf475f5a190bd7249c7709bad8 (diff) | |
parent | ce02874e2a7c5dacd12e58652e9665857bd46c62 (diff) | |
download | mitmproxy-0df7e27c3b43164dc41f5b37a6e425e8a719c6e9.tar.gz mitmproxy-0df7e27c3b43164dc41f5b37a6e425e8a719c6e9.tar.bz2 mitmproxy-0df7e27c3b43164dc41f5b37a6e425e8a719c6e9.zip |
Merge pull request #103 from scone/master
Utils port to 3.4 keeping py2 compatibility
Diffstat (limited to 'netlib')
-rw-r--r-- | netlib/utils.py | 4 | ||||
-rw-r--r-- | netlib/wsgi.py | 11 |
2 files changed, 8 insertions, 7 deletions
diff --git a/netlib/utils.py b/netlib/utils.py index acc7ccd4..66225897 100644 --- a/netlib/utils.py +++ b/netlib/utils.py @@ -85,9 +85,9 @@ def hexdump(s): A generator of (offset, hex, str) tuples """ for i in range(0, len(s), 16): - offset = b"%.10x" % i + offset = "{:0=10x}".format(i).encode() part = s[i:i + 16] - x = b" ".join(b"%.2x" % i for i in six.iterbytes(part)) + x = b" ".join("{:0=2x}".format(i).encode() for i in six.iterbytes(part)) x = x.ljust(47) # 16*2 + 15 yield (offset, x, clean_bin(part, False)) diff --git a/netlib/wsgi.py b/netlib/wsgi.py index df248a19..d6dfae5d 100644 --- a/netlib/wsgi.py +++ b/netlib/wsgi.py @@ -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 |