import time from PDFWriter import PDFWriter import netius.servers def get_pdf(): pw = PDFWriter('hello-from-netius.pdf') pw.setFont('Courier', 10) pw.setHeader('PDF generated by xtopdf, a PDF library for Python') pw.setFooter('Using netius Python network library, at {}'.format(time.ctime())) pw.writeLine('Hello world! This is a test PDF served by Netius, ') pw.writeLine('a Python networking library; PDF created with the help ') pw.writeLine('of xtopdf, a Python library for PDF creation.') pw.close() pdf_fil = open('hello-from-netius.pdf', 'rb') pdf_str = pdf_fil.read() pdf_len = len(pdf_str) pdf_fil.close() return pdf_len, pdf_str def app(environ, start_response): status = "200 OK" content_len, contents = get_pdf() headers = ( ("Content-Length", content_len), ("Content-type", "application/pdf"), ("Connection", "keep-alive") ) start_response(status, headers) yield contents server = netius.servers.WSGIServer(app = app) server.serve(port = 8080)