当前位置: 首页>>代码示例>>Python>>正文


Python StringIO.flush方法代码示例

本文整理汇总了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()
开发者ID:Yingmin-Li,项目名称:taurus,代码行数:9,代码来源:console.py

示例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
开发者ID:cloud-init,项目名称:cloud-init,代码行数:11,代码来源:helpers.py

示例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)
开发者ID:pombredanne,项目名称:phy,代码行数:16,代码来源:testing.py

示例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)
开发者ID:alset0326,项目名称:peda-arm,代码行数:52,代码来源:utils.py

示例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()
开发者ID:giltis,项目名称:dataportal,代码行数:17,代码来源:simple_broker.py

示例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()
开发者ID:Juanlu001,项目名称:pyomo,代码行数:39,代码来源:test_con.py


注:本文中的six.StringIO.flush方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。