summaryrefslogtreecommitdiff
path: root/paste/debug/debugapp.py
diff options
context:
space:
mode:
authorcce <devnull@localhost>2006-01-11 15:34:25 +0000
committercce <devnull@localhost>2006-01-11 15:34:25 +0000
commitdd6c180701bb867bb768e770387a39cd9f117705 (patch)
treedb48f6782c73b0d59dd67242d29be5647adeb31d /paste/debug/debugapp.py
parent88839390a6e317da438ca5f8dc03a827aa62ea1f (diff)
downloadpaste-dd6c180701bb867bb768e770387a39cd9f117705.tar.gz
- 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)
Diffstat (limited to 'paste/debug/debugapp.py')
-rwxr-xr-xpaste/debug/debugapp.py63
1 files changed, 63 insertions, 0 deletions
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 = "<html><body>simple</body></html>"
+ 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 = "<html><body>%d bytes</body></html>" % size
+ else:
+ body = ('<html><body>\n'
+ '<form method="post" enctype="multipart/form-data">\n'
+ '<input type="file" name="file">\n'
+ '<input type="submit" >\n'
+ '</form></body></html>\n')
+ print "bingles"
+ start_response("200 OK",[('Content-Type', 'text/html'),
+ ('Content-Length', len(body))])
+ return [body]