本文整理汇总了Python中six.StringIO.flush方法的典型用法代码示例。如果您正苦于以下问题:Python StringIO.flush方法的具体用法?Python StringIO.flush怎么用?Python StringIO.flush使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类six.StringIO
的用法示例。
在下文中一共展示了StringIO.flush方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: flush
# 需要导入模块: from six import StringIO [as 别名]
# 或者: from six.StringIO import flush [as 别名]
def flush(self):
"""
:type self: StringIONotifying or StringIO
"""
StringIO.flush(self)
self.listener()
示例2: stringify
# 需要导入模块: from six import StringIO [as 别名]
# 或者: from six.StringIO import flush [as 别名]
def stringify(self, header=None):
contents = ''
outputstream = StringIO()
self.write(outputstream)
outputstream.flush()
contents = outputstream.getvalue()
if header:
contents = '\n'.join([header, contents, ''])
return contents
示例3: captured_logging
# 需要导入模块: from six import StringIO [as 别名]
# 或者: from six.StringIO import flush [as 别名]
def captured_logging(name=None):
buffer = StringIO()
logger = logging.getLogger(name)
handlers = logger.handlers
for handler in logger.handlers:
logger.removeHandler(handler)
handler = logging.StreamHandler(buffer)
handler.setLevel(logging.DEBUG)
logger.addHandler(handler)
yield buffer
buffer.flush()
logger.removeHandler(handler)
for handler in handlers:
logger.addHandler(handler)
示例4: message
# 需要导入模块: from six import StringIO [as 别名]
# 或者: from six.StringIO import flush [as 别名]
class message(object):
"""
Generic pretty printer with redirection.
It also suports buffering using bufferize() and flush().
"""
def __init__(self):
self.out = sys.stdout
self.buffering = 0
def bufferize(self, f=None):
"""Activate message's bufferization, can also be used as a decorater."""
if f is not None:
@functools.wraps(f)
def wrapper(*args, **kwargs):
self.bufferize()
f(*args, **kwargs)
self.flush()
return wrapper
# If we are still using stdio we need to change it.
if not self.buffering:
self.out = StringIO()
self.buffering += 1
def flush(self):
if not self.buffering:
raise ValueError("Tried to flush a message that is not bufferising.")
self.buffering -= 1
# We only need to flush if this is the lowest recursion level.
if not self.buffering:
self.out.flush()
sys.stdout.write(self.out.getvalue())
self.out = sys.stdout
def __call__(self, text, color=None, attrib=None, teefd=None):
if not teefd:
teefd = config.Option.get("_teefd")
if isinstance(text, six.string_types) and "\x00" not in text:
print(colorize(text, color, attrib), file=self.out)
if teefd:
print(colorize(text, color, attrib), file=teefd)
else:
pprint.pprint(text, self.out)
if teefd:
pprint.pprint(text, teefd)
示例5: Stream
# 需要导入模块: from six import StringIO [as 别名]
# 或者: from six.StringIO import flush [as 别名]
class Stream(object):
def __init__(self):
self._stringio = StringIO()
self._stringio.isatty = sys.stdout.isatty
def write(self, msg, color='default', newline=True):
if newline:
msg += '\n'
color_print(msg, color, file=self._stringio)
self._stringio.flush()
def readout(self):
self._stringio.seek(0)
return self._stringio.read()
示例6: LogBuffer
# 需要导入模块: from six import StringIO [as 别名]
# 或者: from six.StringIO import flush [as 别名]
class LogBuffer(object):
def __init__(self, logger, logLevel=None):
if isinstance(logger, logging.Logger):
self.logger = logger
else:
self.logger = logging.getLogger(logger)
self.buffer = StringIO()
if logLevel is None:
self.old_level = None
else:
self.old_level = self.logger.getEffectiveLevel()
self.logger.setLevel(logLevel)
self.logHandler = logging.StreamHandler(self.buffer)
self.logger.addHandler(self.logHandler)
def __del__(self):
self.close()
def close(self):
if self.logger is None:
return
if self.old_level is not None:
self.logger.setLevel(self.old_level)
self.logger.removeHandler(self.logHandler)
self.logHandler.flush()
self.buffer.flush()
self.logHandler = None
self.logger = None
def value(self):
if self.logHandler is not None:
self.logHandler.flush();
self.buffer.flush()
return self.buffer.getvalue()