Commit 5f72af23 authored by Ross Patterson's avatar Ross Patterson

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.
parent e4816be9
...@@ -11,6 +11,10 @@ http://docs.zope.org/zope2/releases/. ...@@ -11,6 +11,10 @@ http://docs.zope.org/zope2/releases/.
Bugs Fixed 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) 2.12.13 (2010-11-06)
......
...@@ -15,7 +15,6 @@ __doc__="""System management components""" ...@@ -15,7 +15,6 @@ __doc__="""System management components"""
__version__='$Revision: 1.94 $'[11:-2] __version__='$Revision: 1.94 $'[11:-2]
from cgi import escape from cgi import escape
from cStringIO import StringIO
from logging import getLogger from logging import getLogger
import os import os
import sys import sys
...@@ -232,17 +231,12 @@ class DebugManager(Item, Implicit): ...@@ -232,17 +231,12 @@ class DebugManager(Item, Implicit):
stats=getattr(sys, '_ps_', None) stats=getattr(sys, '_ps_', None)
if stats is None: if stats is None:
return None return None
output=StringIO()
stdout=sys.stdout
if stripDirs: if stripDirs:
from copy import copy; stats= copy(stats) from copy import copy; stats= copy(stats)
stats.strip_dirs() stats.strip_dirs()
stats.sort_stats(sort) stats.sort_stats(sort)
sys.stdout=output
getattr(stats,'print_%s' % mode)(limit) getattr(stats,'print_%s' % mode)(limit)
sys.stdout.flush() return stats.stream.getvalue()
sys.stdout=stdout
return output.getvalue()
def manage_getSysPath(self): def manage_getSysPath(self):
return list(sys.path) return list(sys.path)
......
...@@ -403,7 +403,9 @@ def publish_module_profiled(module_name, stdin=sys.stdin, stdout=sys.stdout, ...@@ -403,7 +403,9 @@ def publish_module_profiled(module_name, stdin=sys.stdin, stdout=sys.stdout,
result=sys._pr_ result=sys._pr_
pobj.create_stats() pobj.create_stats()
if _pstat is None: 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) else: _pstat.add(pobj)
finally: finally:
_plock.release() _plock.release()
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment