file_like.py
49 lines
| 1.1 KiB
| text/x-python
|
PythonLexer
Gael Varoquaux
|
r1383 | # encoding: utf-8 | ||
Gael Varoquaux
|
r1407 | """ File like object that redirects its write calls to a given callback.""" | ||
Gael Varoquaux
|
r1383 | |||
__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 sys | ||||
class FileLike(object): | ||||
""" FileLike object that redirects all write to a callback. | ||||
Only the write-related methods are implemented, as well as those | ||||
required to read a StringIO. | ||||
""" | ||||
closed = False | ||||
Gael Varoquaux
|
r1407 | def __init__(self, write_callback): | ||
self.write = write_callback | ||||
Gael Varoquaux
|
r1383 | |||
def flush(self): | ||||
pass | ||||
def close(self): | ||||
pass | ||||
def writelines(self, lines): | ||||
for line in lines: | ||||
self.write(line) | ||||
def isatty(self): | ||||
return False | ||||
def getvalue(self): | ||||
return '' | ||||
Gael Varoquaux
|
r1407 | def reset(self): | ||
pass | ||||
Gael Varoquaux
|
r1383 | |||
Gael Varoquaux
|
r1407 | def truncate(self): | ||
Gael Varoquaux
|
r1383 | pass | ||
Gael Varoquaux
|
r1407 | |||