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


Python token.RBRACE屬性代碼示例

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


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

示例1: transform

# 需要導入模塊: from lib2to3.fixer_util import token [as 別名]
# 或者: from lib2to3.fixer_util.token import RBRACE [as 別名]
def transform(self, node, results):
        single = results.get("single")
        if single:
            # Make a fake listmaker
            fake = pytree.Node(syms.listmaker, [single.clone()])
            single.replace(fake)
            items = fake
        else:
            items = results["items"]

        # Build the contents of the literal
        literal = [pytree.Leaf(token.LBRACE, "{")]
        literal.extend(n.clone() for n in items.children)
        literal.append(pytree.Leaf(token.RBRACE, "}"))
        # Set the prefix of the right brace to that of the ')' or ']'
        literal[-1].prefix = items.next_sibling.prefix
        maker = pytree.Node(syms.dictsetmaker, literal)
        maker.prefix = node.prefix

        # If the original was a one tuple, we need to remove the extra comma.
        if len(maker.children) == 4:
            n = maker.children[2]
            n.remove()
            maker.children[-1].prefix = n.prefix

        # Finally, replace the set call with our shiny new literal.
        return maker 
開發者ID:remg427,項目名稱:misp42splunk,代碼行數:29,代碼來源:fix_set_literal.py

示例2: transform

# 需要導入模塊: from lib2to3.fixer_util import token [as 別名]
# 或者: from lib2to3.fixer_util.token import RBRACE [as 別名]
def transform(self, node, results):
        single = results.get("single")
        if single:
            # Make a fake listmaker
            fake = pytree.Node(syms.listmaker, [single.clone()])
            single.replace(fake)
            items = fake
        else:
            items = results["items"]

        # Build the contents of the literal
        literal = [pytree.Leaf(token.LBRACE, u"{")]
        literal.extend(n.clone() for n in items.children)
        literal.append(pytree.Leaf(token.RBRACE, u"}"))
        # Set the prefix of the right brace to that of the ')' or ']'
        literal[-1].prefix = items.next_sibling.prefix
        maker = pytree.Node(syms.dictsetmaker, literal)
        maker.prefix = node.prefix

        # If the original was a one tuple, we need to remove the extra comma.
        if len(maker.children) == 4:
            n = maker.children[2]
            n.remove()
            maker.children[-1].prefix = n.prefix

        # Finally, replace the set call with our shiny new literal.
        return maker 
開發者ID:remg427,項目名稱:misp42splunk,代碼行數:29,代碼來源:fix_set_literal.py


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