From 8d08214a5f926a99946b89563b650dbb7f3f95d5 2008-08-11 18:41:53 From: gvaroquaux Date: 2008-08-11 18:41:53 Subject: [PATCH] More docstring work. --- diff --git a/IPython/kernel/core/fd_redirector.py b/IPython/kernel/core/fd_redirector.py index 0941fac..510a439 100644 --- a/IPython/kernel/core/fd_redirector.py +++ b/IPython/kernel/core/fd_redirector.py @@ -2,6 +2,8 @@ """ Stdout/stderr redirector, at the OS level, using file descriptors. + +This also works under windows. """ __docformat__ = "restructuredtext en" @@ -31,8 +33,12 @@ class FDRedirector(object): """ 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() @@ -42,12 +48,17 @@ class FDRedirector(object): 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) @@ -62,6 +73,9 @@ class FDRedirector(object): 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 diff --git a/IPython/kernel/core/file_like.py b/IPython/kernel/core/file_like.py index a09f47a..f984451 100644 --- a/IPython/kernel/core/file_like.py +++ b/IPython/kernel/core/file_like.py @@ -25,25 +25,42 @@ class FileLike(object): self.write = write_callback def flush(self): + """ This method is there for compatibility with other file-like + objects. + """ pass def close(self): + """ This method is there for compatibility with other file-like + objects. + """ pass def writelines(self, lines): - for line in lines: - self.write(line) + map(self.write, lines) def isatty(self): + """ This method is there for compatibility with other file-like + objects. + """ return False def getvalue(self): + """ This method is there for compatibility with other file-like + objects. + """ return '' def reset(self): + """ This method is there for compatibility with other file-like + objects. + """ pass def truncate(self): + """ This method is there for compatibility with other file-like + objects. + """ pass diff --git a/IPython/kernel/core/redirector_output_trap.py b/IPython/kernel/core/redirector_output_trap.py index fb396ce..fcc3f71 100644 --- a/IPython/kernel/core/redirector_output_trap.py +++ b/IPython/kernel/core/redirector_output_trap.py @@ -31,6 +31,10 @@ class RedirectorOutputTrap(OutputTrap): # OutputTrap interface. #------------------------------------------------------------------------ def __init__(self, out_callback, err_callback): + """ + out_callback : callable called when there is output in the stdout + err_callback : callable called when there is output in the stderr + """ # Callback invoked on write to stdout and stderr self.out_callback = out_callback self.err_callback = err_callback diff --git a/IPython/kernel/core/sync_traceback_trap.py b/IPython/kernel/core/sync_traceback_trap.py index df9b0e5..cf9e1bf 100644 --- a/IPython/kernel/core/sync_traceback_trap.py +++ b/IPython/kernel/core/sync_traceback_trap.py @@ -21,9 +21,17 @@ from traceback_trap import TracebackTrap from IPython.ultraTB import ColorTB class SyncTracebackTrap(TracebackTrap): + """ TracebackTrap that displays immediatly the traceback in addition + to capturing it. Useful in frontends, as without this traceback trap, + some tracebacks never get displayed. + """ def __init__(self, sync_formatter=None, formatters=None, raiseException=True): + """ + sync_formatter: Callable to display the traceback. + formatters: A list of formatters to apply. + """ TracebackTrap.__init__(self, formatters=formatters) if sync_formatter is None: sync_formatter = ColorTB(color_scheme='LightBG')