[Zope-Checkins] SVN: Zope/trunk/ Merge Control_Panel/DebugInfo/manage_profile ZMI view fixes from

Ross Patterson me at rpatterson.net
Thu Nov 18 20:05:56 EST 2010


Log message for revision 118472:
  Merge Control_Panel/DebugInfo/manage_profile ZMI view fixes from
  svn+ssh://svn.zope.org/repos/main/Zope/branches/2.12 r118262:118470
  

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

-=-
Modified: Zope/trunk/doc/CHANGES.rst
===================================================================
--- Zope/trunk/doc/CHANGES.rst	2010-11-19 01:00:39 UTC (rev 118471)
+++ Zope/trunk/doc/CHANGES.rst	2010-11-19 01:05:56 UTC (rev 118472)
@@ -11,7 +11,14 @@
 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.
 
+- Use cProfile where possible for the
+  Control_Panel/DebugInfo/manage_profile ZMI view.
+
 Features Added
 ++++++++++++++
 

Modified: Zope/trunk/src/App/ApplicationManager.py
===================================================================
--- Zope/trunk/src/App/ApplicationManager.py	2010-11-19 01:00:39 UTC (rev 118471)
+++ Zope/trunk/src/App/ApplicationManager.py	2010-11-19 01:05:56 UTC (rev 118472)
@@ -232,17 +232,13 @@
         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
+        stats.stream = output = StringIO()
+        getattr(stats, 'print_%s' % mode)(limit)
         return output.getvalue()
 
     def manage_profile_reset(self):

Modified: Zope/trunk/src/ZPublisher/Publish.py
===================================================================
--- Zope/trunk/src/ZPublisher/Publish.py	2010-11-19 01:00:39 UTC (rev 118471)
+++ Zope/trunk/src/ZPublisher/Publish.py	2010-11-19 01:05:56 UTC (rev 118472)
@@ -386,7 +386,12 @@
 def publish_module_profiled(module_name, stdin=sys.stdin, stdout=sys.stdout,
                             stderr=sys.stderr, environ=os.environ, debug=0,
                             request=None, response=None):
-    import profile, pstats
+    try:
+        import cProfile as profile
+        profile  # pyflakes
+    except ImportError:
+        import profile
+    import pstats
     global _pstat
     _plock.acquire()
     try:
@@ -403,7 +408,7 @@
         result=sys._pr_
         pobj.create_stats()
         if _pstat is None:
-            _pstat=sys._ps_=pstats.Stats(pobj)
+            _pstat = sys._ps_ = pstats.Stats(pobj)
         else: _pstat.add(pobj)
     finally:
         _plock.release()



More information about the Zope-Checkins mailing list