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


Python util.StringIO方法代码示例

本文整理汇总了Python中pygments.util.StringIO方法的典型用法代码示例。如果您正苦于以下问题:Python util.StringIO方法的具体用法?Python util.StringIO怎么用?Python util.StringIO使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在pygments.util的用法示例。


在下文中一共展示了util.StringIO方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: format

# 需要导入模块: from pygments import util [as 别名]
# 或者: from pygments.util import StringIO [as 别名]
def format(tokens, formatter, outfile=None):
    """
    Format a tokenlist ``tokens`` with the formatter ``formatter``.

    If ``outfile`` is given and a valid file object (an object
    with a ``write`` method), the result will be written to it, otherwise
    it is returned as a string.
    """
    try:
        if not outfile:
            realoutfile = getattr(formatter, 'encoding', None) and BytesIO() or StringIO()
            formatter.format(tokens, realoutfile)
            return realoutfile.getvalue()
        else:
            formatter.format(tokens, outfile)
    except TypeError as err:
        if isinstance(err.args[0], str) and \
           ('unbound method format' in err.args[0] or
                'missing 1 required positional argument' in err.args[0]):
            raise TypeError('format() argument must be a formatter instance, '
                            'not a class')
        raise 
开发者ID:joxeankoret,项目名称:pigaios,代码行数:24,代码来源:__init__.py

示例2: format

# 需要导入模块: from pygments import util [as 别名]
# 或者: from pygments.util import StringIO [as 别名]
def format(tokens, formatter, outfile=None):  # pylint: disable=redefined-builtin
    """
    Format a tokenlist ``tokens`` with the formatter ``formatter``.

    If ``outfile`` is given and a valid file object (an object
    with a ``write`` method), the result will be written to it, otherwise
    it is returned as a string.
    """
    try:
        if not outfile:
            realoutfile = getattr(formatter, 'encoding', None) and BytesIO() or StringIO()
            formatter.format(tokens, realoutfile)
            return realoutfile.getvalue()
        else:
            formatter.format(tokens, outfile)
    except TypeError as err:
        if (isinstance(err.args[0], str) and
            ('unbound method format' in err.args[0] or
             'missing 1 required positional argument' in err.args[0])):
            raise TypeError('format() argument must be a formatter instance, '
                            'not a class')
        raise 
开发者ID:luckystarufo,项目名称:pySINDy,代码行数:24,代码来源:__init__.py


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