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


Python token.INDENT属性代码示例

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


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

示例1: indentation

# 需要导入模块: from lib2to3.pygram import token [as 别名]
# 或者: from lib2to3.pygram.token import INDENT [as 别名]
def indentation(node):
    """
    Returns the indentation for this node
    Iff a node is in a suite, then it has indentation.
    """
    while node.parent is not None and node.parent.type != syms.suite:
        node = node.parent
    if node.parent is None:
        return u""
    # The first three children of a suite are NEWLINE, INDENT, (some other node)
    # INDENT.value contains the indentation for this suite
    # anything after (some other node) has the indentation as its prefix.
    if node.type == token.INDENT:
        return node.value
    elif node.prev_sibling is not None and node.prev_sibling.type == token.INDENT:
        return node.prev_sibling.value
    elif node.prev_sibling is None:
        return u""
    else:
        return node.prefix 
开发者ID:remg427,项目名称:misp42splunk,代码行数:22,代码来源:fixer_util.py

示例2: suitify

# 需要导入模块: from lib2to3.pygram import token [as 别名]
# 或者: from lib2to3.pygram.token import INDENT [as 别名]
def suitify(parent):
    """
    Turn the stuff after the first colon in parent's children
    into a suite, if it wasn't already
    """
    for node in parent.children:
        if node.type == syms.suite:
            # already in the prefered format, do nothing
            return

    # One-liners have no suite node, we have to fake one up
    for i, node in enumerate(parent.children):
        if node.type == token.COLON:
            break
    else:
        raise ValueError(u"No class suite and no ':'!")
    # Move everything into a suite node
    suite = Node(syms.suite, [Newline(), Leaf(token.INDENT, indentation(node) + indentation_step(node))])
    one_node = parent.children[i+1]
    one_node.remove()
    one_node.prefix = u''
    suite.append_child(one_node)
    parent.append_child(suite) 
开发者ID:remg427,项目名称:misp42splunk,代码行数:25,代码来源:fixer_util.py

示例3: fixup_indent

# 需要导入模块: from lib2to3.pygram import token [as 别名]
# 或者: from lib2to3.pygram.token import INDENT [as 别名]
def fixup_indent(suite):
    """ If an INDENT is followed by a thing with a prefix then nuke the prefix
        Otherwise we get in trouble when removing __metaclass__ at suite start
    """
    kids = suite.children[::-1]
    # find the first indent
    while kids:
        node = kids.pop()
        if node.type == token.INDENT:
            break

    # find the first Leaf
    while kids:
        node = kids.pop()
        if isinstance(node, Leaf) and node.type != token.DEDENT:
            if node.prefix:
                node.prefix = u''
            return
        else:
            kids.extend(node.children[::-1]) 
开发者ID:remg427,项目名称:misp42splunk,代码行数:22,代码来源:fix_metaclass.py

示例4: indentation

# 需要导入模块: from lib2to3.pygram import token [as 别名]
# 或者: from lib2to3.pygram.token import INDENT [as 别名]
def indentation(node):
    u"""
    Returns the indentation for this node
    Iff a node is in a suite, then it has indentation.
    """
    while node.parent is not None and node.parent.type != syms.suite:
        node = node.parent
    if node.parent is None:
        return u""
    # The first three children of a suite are NEWLINE, INDENT, (some other node)
    # INDENT.value contains the indentation for this suite
    # anything after (some other node) has the indentation as its prefix.
    if node.type == token.INDENT:
        return node.value
    elif node.prev_sibling is not None and node.prev_sibling.type == token.INDENT:
        return node.prev_sibling.value
    elif node.prev_sibling is None:
        return u""
    else:
        return node.prefix 
开发者ID:hughperkins,项目名称:kgsgo-dataset-preprocessor,代码行数:22,代码来源:fixer_util.py

示例5: suitify

# 需要导入模块: from lib2to3.pygram import token [as 别名]
# 或者: from lib2to3.pygram.token import INDENT [as 别名]
def suitify(parent):
    u"""
    Turn the stuff after the first colon in parent's children
    into a suite, if it wasn't already
    """
    for node in parent.children:
        if node.type == syms.suite:
            # already in the prefered format, do nothing
            return

    # One-liners have no suite node, we have to fake one up
    for i, node in enumerate(parent.children):
        if node.type == token.COLON:
            break
    else:
        raise ValueError(u"No class suite and no ':'!")
    # Move everything into a suite node
    suite = Node(syms.suite, [Newline(), Leaf(token.INDENT, indentation(node) + indentation_step(node))])
    one_node = parent.children[i+1]
    one_node.remove()
    one_node.prefix = u''
    suite.append_child(one_node)
    parent.append_child(suite) 
开发者ID:hughperkins,项目名称:kgsgo-dataset-preprocessor,代码行数:25,代码来源:fixer_util.py


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