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


Python util.format_lines方法代码示例

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


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

示例1: update_consts

# 需要导入模块: from pygments import util [as 别名]
# 或者: from pygments.util import format_lines [as 别名]
def update_consts(filename, constname, content):
        with open(filename) as f:
            data = f.read()

        # Line to start/end inserting
        re_match = re.compile(r'^%s\s*=\s*\($.*?^\s*\)$' % constname, re.M | re.S)
        m = re_match.search(data)
        if not m:
            raise ValueError('Could not find existing definition for %s' %
                             (constname,))

        new_block = format_lines(constname, content)
        data = data[:m.start()] + new_block + data[m.end():]

        with open(filename, 'w') as f:
            f.write(data) 
开发者ID:joxeankoret,项目名称:pigaios,代码行数:18,代码来源:_postgres_builtins.py

示例2: regenerate

# 需要导入模块: from pygments import util [as 别名]
# 或者: from pygments.util import format_lines [as 别名]
def regenerate(filename, natives):
        with open(filename) as fp:
            content = fp.read()

        header = content[:content.find('FUNCTIONS = (')]
        footer = content[content.find("if __name__ == '__main__':")-1:]


        with open(filename, 'w') as fp:
            fp.write(header)
            fp.write(format_lines('FUNCTIONS', natives))
            fp.write(footer) 
开发者ID:joxeankoret,项目名称:pigaios,代码行数:14,代码来源:_sourcemod_builtins.py

示例3: test_format_lines

# 需要导入模块: from pygments import util [as 别名]
# 或者: from pygments.util import format_lines [as 别名]
def test_format_lines():
    lst = ['cat', 'dog']
    output = util.format_lines('var', lst)
    d = {}
    exec(output, d)
    assert isinstance(d['var'], tuple)
    assert ('cat', 'dog') == d['var'] 
开发者ID:pygments,项目名称:pygments,代码行数:9,代码来源:test_util.py

示例4: getkw

# 需要导入模块: from pygments import util [as 别名]
# 或者: from pygments.util import format_lines [as 别名]
def getkw(input, output):
    out = file(output, 'w')

    # Copy template from an existing file.
    print(HEADER, file=out)

    output_info = {'command': [], 'option': [], 'auto': []}
    for line in file(input):
        m = r_line.match(line)
        if m:
            # Decide which output gets mapped to d
            if 'vimCommand' in m.group(1):
                d = output_info['command']
            elif 'AutoEvent' in m.group(1):
                d = output_info['auto']
            else:
                d = output_info['option']

            # Extract all the shortened versions
            for i in r_item.finditer(m.group(2)):
                d.append('(%r,%r)' %
                         (i.group(1), "%s%s" % (i.group(1), i.group(2) or '')))

    output_info['option'].append("('nnoremap','nnoremap')")
    output_info['option'].append("('inoremap','inoremap')")
    output_info['option'].append("('vnoremap','vnoremap')")

    for key, keywordlist in output_info.items():
        keywordlist.sort()
        body = format_lines('var', keywordlist, raw=True, indent_level=1)
        print(METHOD % locals(), file=out) 
开发者ID:pygments,项目名称:pygments,代码行数:33,代码来源:get_vimkw.py


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