[Moin-devel] CVS: MoinMoin/webapi cgiMoin.py,1.13,1.14
J?rgen Hermann
jhermann at users.sourceforge.net
Wed May 22 12:09:10 EDT 2002
Update of /cvsroot/moin/MoinMoin/webapi
In directory usw-pr-cvs1:/tmp/cvs-serv13134/MoinMoin/webapi
Modified Files:
cgiMoin.py
Log Message:
StdoutGuard to detect premature CGI output
Index: cgiMoin.py
===================================================================
RCS file: /cvsroot/moin/MoinMoin/webapi/cgiMoin.py,v
retrieving revision 1.13
retrieving revision 1.14
diff -C2 -r1.13 -r1.14
*** cgiMoin.py 17 Apr 2002 21:58:17 -0000 1.13
--- cgiMoin.py 22 May 2002 19:08:19 -0000 1.14
***************
*** 13,17 ****
# Imports
! import os, string
#############################################################################
--- 13,17 ----
# Imports
! import os, string, sys
#############################################################################
***************
*** 76,79 ****
--- 76,94 ----
#############################################################################
+ class StdoutGuard:
+ """ Throw an exception when someone tries to write prematurely to
+ sys.stdout.
+ """
+
+ def __init__(self, request):
+ self.request = request
+
+ def __getattr__(self, attr):
+ # send headers, then raise an exception to create a stack trace
+ sys.stdout = sys.__stdout__
+ http_headers(self.request)
+ raise RuntimeError("Premature access to sys.stdout.%s" % attr)
+
+
def setHttpHeader(request, header):
request.user_headers.append(header)
***************
*** 88,91 ****
--- 103,109 ----
request.sent_headers = 1
have_ct = 0
+
+ # deactivate guard
+ sys.stdout = sys.__stdout__
# send http headers
More information about the Moin-devel
mailing list