diff options
author | ianb <devnull@localhost> | 2008-07-31 18:46:38 +0000 |
---|---|---|
committer | ianb <devnull@localhost> | 2008-07-31 18:46:38 +0000 |
commit | 349beb2177f91b18faf53b71f2f0d33dd4725ec8 (patch) | |
tree | 2294a92ff675ef5d1396601ef4e14261417c62a4 /paste/debug/prints.py | |
parent | f1f5f30462c5d317d3dbd0b01e9f567964c4e986 (diff) | |
download | paste-349beb2177f91b18faf53b71f2f0d33dd4725ec8.tar.gz |
Make paste.debug.prints work with appengine, which replaces stdout on every request, so our patching isn't persistent
Diffstat (limited to 'paste/debug/prints.py')
-rw-r--r-- | paste/debug/prints.py | 14 |
1 files changed, 11 insertions, 3 deletions
diff --git a/paste/debug/prints.py b/paste/debug/prints.py index c971895..d30fc8f 100644 --- a/paste/debug/prints.py +++ b/paste/debug/prints.py @@ -23,6 +23,7 @@ import cgi from paste.util import threadedprint from paste import wsgilib from paste import response +import sys _threadedprint_installed = False @@ -53,6 +54,9 @@ class PrintDebugMiddleware(object): ``environ['paste.remove_printdebug']`` is a function that, if called, will disable printing of output for that request. + + If you have ``replace_stdout=True`` then stdout is replaced, not + captured. """ log_template = ( @@ -62,7 +66,7 @@ class PrintDebugMiddleware(object): '%s</pre>') def __init__(self, app, global_conf=None, force_content_type=False, - print_wsgi_errors=True): + print_wsgi_errors=True, replace_stdout=False): # @@: global_conf should be handled separately and only for # the entry point self.app = app @@ -71,6 +75,8 @@ class PrintDebugMiddleware(object): from paste.deploy.converters import asbool print_wsgi_errors = asbool(print_wsgi_errors) self.print_wsgi_errors = print_wsgi_errors + self.replace_stdout = replace_stdout + self._threaded_print_stdout = None def __call__(self, environ, start_response): global _threadedprint_installed @@ -78,10 +84,12 @@ class PrintDebugMiddleware(object): # In a testing environment this interception isn't # useful: return self.app(environ, start_response) - if not _threadedprint_installed: + if (not _threadedprint_installed + or self._threaded_print_stdout is not sys.stdout): # @@: Not strictly threadsafe _threadedprint_installed = True - threadedprint.install(leave_stdout=True) + threadedprint.install(leave_stdout=not self.replace_stdout) + self._threaded_print_stdout = sys.stdout removed = [] def remove_printdebug(): removed.append(None) |