From 10916f55cd49bc22c13bbc277ccc095e676a430d Mon Sep 17 00:00:00 2001 From: cce Date: Wed, 11 Jan 2006 15:34:25 +0000 Subject: - added paste.progress : a request upload progress monitor, partially complete (needs more testing, and a way to expire old uploaded requests) - added paste.debug.debugapp which bootstraps with a simple HTML applicatoin, and a slow consumer (paste.wsgilib.dumpenviron needs to move there) --- paste/debug/debugapp.py | 63 +++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 63 insertions(+) create mode 100755 paste/debug/debugapp.py (limited to 'paste/debug/debugapp.py') diff --git a/paste/debug/debugapp.py b/paste/debug/debugapp.py new file mode 100755 index 0000000..c33e1f4 --- /dev/null +++ b/paste/debug/debugapp.py @@ -0,0 +1,63 @@ +# (c) 2005 Clark C. Evans +# This module is part of the Python Paste Project and is released under +# the MIT License: http://www.opensource.org/licenses/mit-license.php +# This code was written with funding by http://prometheusresearch.com +""" +Various Applications for Debugging/Testing Purposes +""" + +import time +__all__ = ['SimpleApplication', 'SlowConsumer'] + + +class SimpleApplication: + """ + Produces a simple web page + """ + def __call__(self, environ, start_response): + body = "simple" + start_response("200 OK",[('Content-Type','text/html'), + ('Content-Length',len(body))]) + return [body] + +class SlowConsumer: + """ + Consumes an upload slowly... + + NOTE: This should use the iterator form of ``wsgi.input``, + but it isn't implemented in paste.httpserver. + """ + def __init__(self, chunk_size = 4096, delay = 1, progress = True): + self.chunk_size = chunk_size + self.delay = delay + self.progress = True + + def __call__(self, environ, start_response): + size = 0 + total = environ.get('CONTENT_LENGTH') + if total: + remaining = int(total) + while remaining > 0: + if self.progress: + print "%s of %s remaining" % (remaining, total) + if remaining > 4096: + chunk = environ['wsgi.input'].read(4096) + else: + chunk = environ['wsgi.input'].read(remaining) + if not chunk: + break + size += len(chunk) + remaining -= len(chunk) + if self.delay: + time.sleep(self.delay) + body = "%d bytes" % size + else: + body = ('\n' + '
\n' + '\n' + '\n' + '
\n') + print "bingles" + start_response("200 OK",[('Content-Type', 'text/html'), + ('Content-Length', len(body))]) + return [body] -- cgit v1.2.1