From: W. Trevor King Date: Mon, 9 Dec 2013 05:27:29 +0000 (-0800) Subject: gallery: Use byte-compatible sys.stdout for CGI output X-Git-Url: http://git.tremily.us/?a=commitdiff_plain;h=80f7bce68f7db63967c101f1442dabedcbef3005;p=blog.git 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. --- 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