From 80f7bce68f7db63967c101f1442dabedcbef3005 Mon Sep 17 00:00:00 2001 From: "W. Trevor King" Date: Sun, 8 Dec 2013 21:27:29 -0800 Subject: [PATCH] gallery: Use byte-compatible sys.stdout for CGI output We're going to be writing bytes. In Python 2 they should go to sys.stdout, but in Python 3 they should go to sys.stdout.buffer. --- posts/gallery/gallery.py | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/posts/gallery/gallery.py b/posts/gallery/gallery.py index 110f383..40e09e1 100755 --- a/posts/gallery/gallery.py +++ b/posts/gallery/gallery.py @@ -752,7 +752,10 @@ def serve_cgi(server): if isinstance(p, list): p = p[0] url = p.value - server.serve(url=url, page=page, stream=sys.stdout) + stream = sys.stdout # Python 2 + if hasattr(stream, 'buffer'): # Python 3 + stream = sys.stdout.buffer + server.serve(url=url, page=page, stream=stream) def serve_scgi(server, host='localhost', port=4000): import scgi -- 2.26.2