##// END OF EJS Templates
Add missing man pages contributed by Debian's Stephan Peijnik....
Add missing man pages contributed by Debian's Stephan Peijnik. This is an initial import of missing man pages taken verbatim from: http://svn.debian.org/viewsvn/python-modules/packages/ipython/trunk/debian/ This starts to close this bug: https://bugs.launchpad.net/ipython/+bug/291143 I wanted this commit to be purely an import of Stephan's documentation unmodified. I've made some edits to the man pages to update them for 0.10, that will go in the next commit.

File last commit:

r1459:8d08214a
r2098:5d6f848d
Show More
fd_redirector.py
81 lines | 2.1 KiB | text/x-python | PythonLexer
# encoding: utf-8
"""
Stdout/stderr redirector, at the OS level, using file descriptors.
This also works under windows.
"""
__docformat__ = "restructuredtext en"
#-------------------------------------------------------------------------------
# Copyright (C) 2008 The IPython Development Team
#
# Distributed under the terms of the BSD License. The full license is in
# the file COPYING, distributed as part of this software.
#-------------------------------------------------------------------------------
import os
import sys
STDOUT = 1
STDERR = 2
class FDRedirector(object):
""" Class to redirect output (stdout or stderr) at the OS level using
file descriptors.
"""
def __init__(self, fd=STDOUT):
""" fd is the file descriptor of the outpout you want to capture.
It can be STDOUT or STERR.
"""
self.fd = fd
self.started = False
self.piper = None
self.pipew = None
def start(self):
""" Setup the redirection.
"""
if not self.started:
self.oldhandle = os.dup(self.fd)
self.piper, self.pipew = os.pipe()
os.dup2(self.pipew, self.fd)
os.close(self.pipew)
self.started = True
def flush(self):
""" Flush the captured output, similar to the flush method of any
stream.
"""
if self.fd == STDOUT:
sys.stdout.flush()
elif self.fd == STDERR:
sys.stderr.flush()
def stop(self):
""" Unset the redirection and return the captured output.
"""
if self.started:
self.flush()
os.dup2(self.oldhandle, self.fd)
os.close(self.oldhandle)
f = os.fdopen(self.piper, 'r')
output = f.read()
f.close()
self.started = False
return output
else:
return ''
def getvalue(self):
""" Return the output captured since the last getvalue, or the
start of the redirection.
"""
output = self.stop()
self.start()
return output