當前位置: 首頁>>代碼示例>>Python>>正文


Python token.NEWLINE屬性代碼示例

本文整理匯總了Python中lib2to3.pygram.token.NEWLINE屬性的典型用法代碼示例。如果您正苦於以下問題:Python token.NEWLINE屬性的具體用法?Python token.NEWLINE怎麽用?Python token.NEWLINE使用的例子?那麽, 這裏精選的屬性代碼示例或許可以為您提供幫助。您也可以進一步了解該屬性所在lib2to3.pygram.token的用法示例。


在下文中一共展示了token.NEWLINE屬性的5個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。

示例1: indentation

# 需要導入模塊: from lib2to3.pygram import token [as 別名]
# 或者: from lib2to3.pygram.token import NEWLINE [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: indentation

# 需要導入模塊: from lib2to3.pygram import token [as 別名]
# 或者: from lib2to3.pygram.token import NEWLINE [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

示例3: future_import2

# 需要導入模塊: from lib2to3.pygram import token [as 別名]
# 或者: from lib2to3.pygram.token import NEWLINE [as 別名]
def future_import2(feature, node):
    """
    An alternative to future_import() which might not work ...
    """
    root = find_root(node)

    if does_tree_import(u"__future__", feature, node):
        return

    insert_pos = 0
    for idx, node in enumerate(root.children):
        if node.type == syms.simple_stmt and node.children and \
           node.children[0].type == token.STRING:
            insert_pos = idx + 1
            break

    for thing_after in root.children[insert_pos:]:
        if thing_after.type == token.NEWLINE:
            insert_pos += 1
            continue

        prefix = thing_after.prefix
        thing_after.prefix = u""
        break
    else:
        prefix = u""

    import_ = FromImport(u"__future__", [Leaf(token.NAME, feature, prefix=u" ")])

    children = [import_, Newline()]
    root.insert_child(insert_pos, Node(syms.simple_stmt, children, prefix=prefix)) 
開發者ID:remg427,項目名稱:misp42splunk,代碼行數:33,代碼來源:fixer_util.py

示例4: remove_trailing_newline

# 需要導入模塊: from lib2to3.pygram import token [as 別名]
# 或者: from lib2to3.pygram.token import NEWLINE [as 別名]
def remove_trailing_newline(node):
    if node.children and node.children[-1].type == token.NEWLINE:
        node.children[-1].remove() 
開發者ID:remg427,項目名稱:misp42splunk,代碼行數:5,代碼來源:fix_metaclass.py

示例5: future_import2

# 需要導入模塊: from lib2to3.pygram import token [as 別名]
# 或者: from lib2to3.pygram.token import NEWLINE [as 別名]
def future_import2(feature, node):
    """
    An alternative to future_import() which might not work ...
    """
    root = find_root(node)
    
    if does_tree_import(u"__future__", feature, node):
        return

    insert_pos = 0
    for idx, node in enumerate(root.children):
        if node.type == syms.simple_stmt and node.children and \
           node.children[0].type == token.STRING:
            insert_pos = idx + 1
            break

    for thing_after in root.children[insert_pos:]:
        if thing_after.type == token.NEWLINE:
            insert_pos += 1
            continue

        prefix = thing_after.prefix
        thing_after.prefix = u""
        break
    else:
        prefix = u""

    import_ = FromImport(u"__future__", [Leaf(token.NAME, feature, prefix=u" ")])

    children = [import_, Newline()]
    root.insert_child(insert_pos, Node(syms.simple_stmt, children, prefix=prefix)) 
開發者ID:QData,項目名稱:deepWordBug,代碼行數:33,代碼來源:fixer_util.py


注:本文中的lib2to3.pygram.token.NEWLINE屬性示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。