| Index: cherrypy/lib/profiler.py |
| =================================================================== |
| --- cherrypy/lib/profiler.py (Revision 1982) |
| +++ cherrypy/lib/profiler.py (Arbeitskopie) |
| @@ -87,15 +87,22 @@ |
| def stats(self, filename, sortby='cumulative'): |
| """stats(index) -> output of print_stats() for the given profile.""" |
| - s = pstats.Stats(os.path.join(self.path, filename)) |
| + sio = StringIO.StringIO() |
| + kwds = {} |
| + if sys.version_info >= (2, 5): |
| + kwds['stream'] = sio |
| + s = pstats.Stats(os.path.join(self.path, filename), **kwds) |
| s.strip_dirs() |
| s.sort_stats(sortby) |
| - oldout = sys.stdout |
| - try: |
| - sys.stdout = sio = StringIO.StringIO() |
| - s.print_stats() |
| - finally: |
| - sys.stdout = oldout |
| + if sys.version_info >= (2, 5): |
| + s.print_stats() |
| + else: |
| + oldout = sys.stdout |
| + try: |
| + sys.stdout = sio |
| + s.print_stats() |
| + finally: |
| + sys.stdout = oldout |
| response = sio.getvalue() |
| sio.close() |
| return response |