[Moin-devel] Fix(?) for httpdmain.py to work

Joo-won Jung sanori at sanori.net
Tue Sep 17 06:45:04 EDT 2002


Hello,

The attached patch is the simple fix that httpdmain.py of current CVS
gives pages to browser. This patch may help the MoinMoin working on
mod_python with CGI mode and PyApache.

(In fact, some more fixes are needed for MoinMoin to work on mod_python.
 It is explained on http://www.sanori.net/wiki/moin.py/MoinMoinOnModPython
 though it has some old information.)

The reason that httpdmain.py gives pages to (real) stdout, not to
browser, is that webapi.(cgiMoin.)http_headers() enforces sys.stdout
to be sys.__stdout__. It does not matter when the MoinMoin runs
as real CGI. But it does matter when MoinMoin run with httpdmain.py,
on mod_python and on PyApache since they redirect sys.stdout to socket
stream by 'sys.stdout = self.wfile'.

I don't know why the author, Ju"gen Hermann, added StdoutGuard and I
have no confidence that my patch reflect the author's idea. But it
works correctly as far as I tested.

I tested httpdmain.py on Windows XP and tested it on mod_python CGI mode
on Linux. I did not tested it on PyApache.

Hope this helps,

-Sanori


-------------- next part --------------
? httpd.patch
Index: cgimain.py
===================================================================
RCS file: /cvsroot/moin/MoinMoin/cgimain.py,v
retrieving revision 1.60
diff -c -r1.60 cgimain.py
*** cgimain.py	2 Aug 2002 16:45:49 -0000	1.60
--- cgimain.py	17 Sep 2002 12:26:21 -0000
***************
*** 67,73 ****
  
      # install stdout guard if available
      if hasattr(webapi, 'StdoutGuard'):
!         sys.stdout = webapi.StdoutGuard(request)
  
      # sys.stderr.write("----\n")
      # for key in os.environ.keys():    
--- 67,73 ----
  
      # install stdout guard if available
      if hasattr(webapi, 'StdoutGuard'):
!         sys.stdout = webapi.StdoutGuard(request, sys.stdout)
  
      # sys.stderr.write("----\n")
      # for key in os.environ.keys():    
Index: webapi/cgiMoin.py
===================================================================
RCS file: /cvsroot/moin/MoinMoin/webapi/cgiMoin.py,v
retrieving revision 1.17
diff -c -r1.17 cgiMoin.py
*** webapi/cgiMoin.py	4 Sep 2002 18:33:56 -0000	1.17
--- webapi/cgiMoin.py	17 Sep 2002 12:26:22 -0000
***************
*** 87,101 ****
          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)
--- 87,102 ----
          sys.stdout.
      """
  
!     def __init__(self, request, stdout):
          self.request = request
+         self.saved_stdout = stdout
  
      def __getattr__(self, attr):
          # send headers, then raise an exception to create a stack trace
!         if attr != 'saved_stdout':
!             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)
***************
*** 111,117 ****
      have_ct = 0
  
      # deactivate guard
!     sys.stdout = sys.__stdout__
  
      # send http headers
      for header in more_headers:
--- 112,119 ----
      have_ct = 0
  
      # deactivate guard
!     if hasattr(sys.stdout, 'saved_stdout'):
!         sys.stdout = sys.stdout.saved_stdout
  
      # send http headers
      for header in more_headers:


More information about the Moin-devel mailing list