Author: fw Date: 2005-12-15 11:34:35 +0000 (Thu, 15 Dec 2005) New Revision: 3050 Modified: lib/python/web_support.py Log: lib/python/web_support.py (BinaryResult): New class. Modified: lib/python/web_support.py ==================================================================--- lib/python/web_support.py 2005-12-15 11:33:46 UTC (rev 3049) +++ lib/python/web_support.py 2005-12-15 11:34:35 UTC (rev 3050) @@ -571,6 +571,21 @@ write("Content-Type: text/html\n\n%s\n" % self.doctype) self.contents.flatten(write) +class BinaryResult(Result): + """An object of this class combines a status code with HTML contents.""" + def __init__(self, contents, status=200, + mimetype=''application/octet-stream''): + self.contents = contents + self.status = status + self.mimetype = mimetype + + def flatten(self, write): + """Invokes write for the response header and the binary data.""" + if self.status <> 200: + write("Status: %d\n" % self.status) + write("Content-Type: %s\n\n" % self.mimetype) + write(self.contents) + class WebService(Service): def __init__(self, socket_name): Service.__init__(self, socket_name)