def app(environ, start_response): cl = environ.get('CONTENT_LENGTH', None) if cl is not None: cl = int(cl) body = environ['wsgi.input'].read(cl) cl = str(len(body)) if environ['PATH_INFO'] == '/before_start_response': raise ValueError('wrong') write = start_response( '200 OK', [('Content-Length', cl), ('Content-Type', 'text/plain')] ) if environ['PATH_INFO'] == '/after_write_cb': write('abc') if environ['PATH_INFO'] == '/in_generator': def foo(): yield 'abc' raise ValueError return foo() raise ValueError('wrong') if __name__ == '__main__': from waitress.tests.support import start_server start_server(app, expose_tracebacks=True)
def chunks(l, n): """ Yield successive n-sized chunks from l. """ for i in range(0, len(l), n): yield l[i:i + n] def gen(body): for chunk in chunks(body, 10): yield chunk def app(environ, start_response): cl = environ.get('CONTENT_LENGTH', None) if cl is not None: cl = int(cl) body = environ['wsgi.input'].read(cl) start_response('200 OK', [('Content-Type', 'text/plain')]) if environ['PATH_INFO'] == '/list': return [body] if environ['PATH_INFO'] == '/list_lentwo': return [body[0:1], body[1:]] return gen(body) if __name__ == '__main__': from waitress.tests.support import start_server start_server(app, expose_tracebacks=True)
import time def app(environ, start_response): if environ['PATH_INFO'] == '/sleepy': time.sleep(2) body = b'sleepy returned' else: body = b'notsleepy returned' cl = str(len(body)) start_response('200 OK', [('Content-Length', cl), ('Content-Type', 'text/plain')]) return [body] if __name__ == '__main__': from waitress.tests.support import start_server start_server(app)
else: data = open(fn, 'rb').read() cl = len(data) f = KindaFilelike(data) if path_info == '/notfilelike': headers = [('Content-Length', str(len(data))), ('Content-Type', 'image/jpeg')] elif path_info == '/notfilelike_nocl': headers = [('Content-Type', 'image/jpeg')] elif path_info == '/notfilelike_shortcl': # short content length headers = [ ('Content-Length', '1'), ('Content-Type', 'image/jpeg') ] else: # long content length (/notfilelike_longcl) headers = [ ('Content-Length', str(cl+10)), ('Content-Type', 'image/jpeg') ] start_response( '200 OK', headers ) return environ['wsgi.file_wrapper'](f, 8192) if __name__ == '__main__': from waitress.tests.support import start_server start_server(app)
def app(environ, start_response): body = b'abcdef' cl = len(body) start_response('200 OK', [('Content-Length', str(cl)), ('Content-Type', 'text/plain')]) return [body] if __name__ == '__main__': from waitress.tests.support import start_server start_server(app, max_request_header_size=1000, max_request_body_size=1000)
def app(environ, start_response): body = b'abcdef' cl = len(body) start_response( '200 OK', [('Content-Length', str(cl)), ('Content-Type', 'text/plain')] ) return [body] if __name__ == '__main__': from waitress.tests.support import start_server start_server(app, max_request_header_size=1000, max_request_body_size=1000)