[Checkins] SVN: Zope/branches/2.12/ Fixed the usage of pstats.Stats() output stream. The

Ross Patterson me at rpatterson.net
Thu Nov 18 17:03:11 EST 2010


Log message for revision 118468:
  Fixed the usage of pstats.Stats() output stream.  The
  Control_Panel/DebugInfo/manage_profile ZMI view has been broken since
  Python 2.5.  This breaks Python 2.4 compatibility when the
  publisher-profile-file configuration option is set.  This also removes
  some ugly sys.stdout hackery.
  

Changed:
  U   Zope/branches/2.12/doc/CHANGES.rst
  U   Zope/branches/2.12/src/App/ApplicationManager.py
  U   Zope/branches/2.12/src/ZPublisher/Publish.py

-=-
Modified: Zope/branches/2.12/doc/CHANGES.rst
===================================================================
--- Zope/branches/2.12/doc/CHANGES.rst	2010-11-18 13:37:13 UTC (rev 118467)
+++ Zope/branches/2.12/doc/CHANGES.rst	2010-11-18 22:03:10 UTC (rev 118468)
@@ -11,6 +11,10 @@
 Bugs Fixed
 ++++++++++
 
+- Fixed the usage of pstats.Stats() output stream.  The
+  Control_Panel/DebugInfo/manage_profile ZMI view has been broken
+  since Python 2.5.  This breaks Python 2.4 compatibility when the
+  publisher-profile-file configuration option is set.
 
 
 2.12.13 (2010-11-06)

Modified: Zope/branches/2.12/src/App/ApplicationManager.py
===================================================================
--- Zope/branches/2.12/src/App/ApplicationManager.py	2010-11-18 13:37:13 UTC (rev 118467)
+++ Zope/branches/2.12/src/App/ApplicationManager.py	2010-11-18 22:03:10 UTC (rev 118468)
@@ -15,7 +15,6 @@
 __version__='$Revision: 1.94 $'[11:-2]
 
 from cgi import escape
-from cStringIO import StringIO
 from logging import getLogger
 import os
 import sys
@@ -232,17 +231,12 @@
         stats=getattr(sys, '_ps_', None)
         if stats is None:
             return None
-        output=StringIO()
-        stdout=sys.stdout
         if stripDirs:
             from copy import copy; stats= copy(stats)
             stats.strip_dirs()
         stats.sort_stats(sort)
-        sys.stdout=output
         getattr(stats,'print_%s' % mode)(limit)
-        sys.stdout.flush()
-        sys.stdout=stdout
-        return output.getvalue()
+        return stats.stream.getvalue()
 
     def manage_getSysPath(self):
         return list(sys.path)

Modified: Zope/branches/2.12/src/ZPublisher/Publish.py
===================================================================
--- Zope/branches/2.12/src/ZPublisher/Publish.py	2010-11-18 13:37:13 UTC (rev 118467)
+++ Zope/branches/2.12/src/ZPublisher/Publish.py	2010-11-18 22:03:10 UTC (rev 118468)
@@ -403,7 +403,9 @@
         result=sys._pr_
         pobj.create_stats()
         if _pstat is None:
-            _pstat=sys._ps_=pstats.Stats(pobj)
+            from cStringIO import StringIO
+            stream = StringIO()
+            _pstat = sys._ps_ = pstats.Stats(pobj, stream=stream)
         else: _pstat.add(pobj)
     finally:
         _plock.release()



More information about the checkins mailing list