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


Python token.STRING属性代码示例

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


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

示例1: test

# 需要导入模块: from lib2to3.pgen2 import token [as 别名]
# 或者: from lib2to3.pgen2.token import STRING [as 别名]
def test(self):
        kids = [None,
                [Leaf(token.NUMBER, 1), Leaf(token.NUMBER, 2),
                 Leaf(token.NUMBER, 3)],
                [Leaf(token.NUMBER, 1), Leaf(token.NUMBER, 3),
                 Leaf(token.NUMBER, 2), Leaf(token.NUMBER, 4)],
                [Leaf(token.STRING, "b"), Leaf(token.STRING, "j", prefix=" ")]
                ]
        self.assertStr(self._Call("A"), "A()")
        self.assertStr(self._Call("b", kids[1]), "b(1,2,3)")
        self.assertStr(self._Call("a.b().c", kids[2]), "a.b().c(1,3,2,4)")
        self.assertStr(self._Call("d", kids[3], prefix=" "), " d(b, j)") 
开发者ID:remg427,项目名称:misp42splunk,代码行数:14,代码来源:test_util.py

示例2: transform

# 需要导入模块: from lib2to3.pgen2 import token [as 别名]
# 或者: from lib2to3.pgen2.token import STRING [as 别名]
def transform(self, node, results):
        if node.type == token.STRING:
            if _literal_re.match(node.value):
                new = node.clone()
                new.value = u'b' + new.value
                return new 
开发者ID:remg427,项目名称:misp42splunk,代码行数:8,代码来源:fix_bytes.py

示例3: transform

# 需要导入模块: from lib2to3.pgen2 import token [as 别名]
# 或者: from lib2to3.pgen2.token import STRING [as 别名]
def transform(self, node, results):
        if node.type == token.STRING:
            touch_import_top(u'past.types', u'oldstr', node)
            if _literal_re.match(node.value):
                new = node.clone()
                # Strip any leading space or comments:
                # TODO: check: do we really want to do this?
                new.prefix = u''
                new.value = u'b' + new.value
                wrapped = wrap_in_fn_call("oldstr", [new], prefix=node.prefix)
                return wrapped 
开发者ID:remg427,项目名称:misp42splunk,代码行数:13,代码来源:fix_oldstr_wrap.py

示例4: transform

# 需要导入模块: from lib2to3.pgen2 import token [as 别名]
# 或者: from lib2to3.pgen2.token import STRING [as 别名]
def transform(self, node, results):
        syms = self.syms

        exc = results["exc"].clone()
        if exc.type == token.STRING:
            msg = "Python 3 does not support string exceptions"
            self.cannot_convert(node, msg)
            return

        # Python 2 supports
        #  raise ((((E1, E2), E3), E4), E5), V
        # as a synonym for
        #  raise E1, V
        # Since Python 3 will not support this, we recurse down any tuple
        # literals, always taking the first element.
        if is_tuple(exc):
            while is_tuple(exc):
                # exc.children[1:-1] is the unparenthesized tuple
                # exc.children[1].children[0] is the first element of the tuple
                exc = exc.children[1].children[0].clone()
            exc.prefix = u" "

        if "val" not in results:
            # One-argument raise
            new = pytree.Node(syms.raise_stmt, [Name(u"raise"), exc])
            new.prefix = node.prefix
            return new

        val = results["val"].clone()
        if is_tuple(val):
            args = [c.clone() for c in val.children[1:-1]]
        else:
            val.prefix = u""
            args = [val]

        return pytree.Node(syms.raise_stmt,
                           [Name(u"raise"), Call(exc, args)],
                           prefix=node.prefix) 
开发者ID:remg427,项目名称:misp42splunk,代码行数:40,代码来源:fix_raise.py

示例5: transform

# 需要导入模块: from lib2to3.pgen2 import token [as 别名]
# 或者: from lib2to3.pgen2.token import STRING [as 别名]
def transform(self, node, results):
        if node.type == token.STRING and _literal_re.match(node.value):
            new = node.clone()
            new.value = new.value[1:]
            new.prefix = ''
            node.replace(Call(Name(u'u', prefix=node.prefix), [new])) 
开发者ID:tao12345666333,项目名称:tornado-zh,代码行数:8,代码来源:fix_unicode_literal.py

示例6: transform

# 需要导入模块: from lib2to3.pgen2 import token [as 别名]
# 或者: from lib2to3.pgen2.token import STRING [as 别名]
def transform(self, node, results):
        import pdb
        pdb.set_trace()
        if node.type == token.STRING:
            touch_import_top(u'past.types', u'oldstr', node)
            if _literal_re.match(node.value):
                new = node.clone()
                # Strip any leading space or comments:
                # TODO: check: do we really want to do this?
                new.prefix = u''
                new.value = u'b' + new.value
                wrapped = wrap_in_fn_call("oldstr", [new], prefix=node.prefix)
                return wrapped 
开发者ID:hughperkins,项目名称:kgsgo-dataset-preprocessor,代码行数:15,代码来源:fix_oldstr_wrap.py

示例7: testSimple

# 需要导入模块: from lib2to3.pgen2 import token [as 别名]
# 或者: from lib2to3.pgen2.token import STRING [as 别名]
def testSimple(self):
    tok = format_token.FormatToken(pytree.Leaf(token.STRING, "'hello world'"))
    self.assertEqual("FormatToken(name=STRING, value='hello world', lineno=0)",
                     str(tok))
    self.assertTrue(tok.is_string)

    tok = format_token.FormatToken(pytree.Leaf(token.COMMENT, '# A comment'))
    self.assertEqual('FormatToken(name=COMMENT, value=# A comment, lineno=0)',
                     str(tok))
    self.assertTrue(tok.is_comment) 
开发者ID:google,项目名称:yapf,代码行数:12,代码来源:format_token_test.py

示例8: testIsMultilineString

# 需要导入模块: from lib2to3.pgen2 import token [as 别名]
# 或者: from lib2to3.pgen2.token import STRING [as 别名]
def testIsMultilineString(self):
    tok = format_token.FormatToken(pytree.Leaf(token.STRING, '"""hello"""'))
    self.assertTrue(tok.is_multiline_string)

    tok = format_token.FormatToken(pytree.Leaf(token.STRING, 'r"""hello"""'))
    self.assertTrue(tok.is_multiline_string) 
开发者ID:google,项目名称:yapf,代码行数:8,代码来源:format_token_test.py

示例9: _c_str

# 需要导入模块: from lib2to3.pgen2 import token [as 别名]
# 或者: from lib2to3.pgen2.token import STRING [as 别名]
def _c_str(s):
    return Leaf(token.STRING, repr(s.s)) 
开发者ID:ambv,项目名称:retype,代码行数:4,代码来源:__init__.py

示例10: get_offset_and_prefix

# 需要导入模块: from lib2to3.pgen2 import token [as 别名]
# 或者: from lib2to3.pgen2.token import STRING [as 别名]
def get_offset_and_prefix(body, skip_assignments=False):
    """Returns the offset after which a statement can be inserted to the `body`.

    This offset is calculated to come after all imports, and maybe existing
    (possibly annotated) assignments if `skip_assignments` is True.

    Also returns the indentation prefix that should be applied to the inserted
    node.
    """
    assert body.type in (syms.file_input, syms.suite)

    _offset = 0
    prefix = ""
    for _offset, child in enumerate(body.children):
        if child.type == syms.simple_stmt:
            stmt = child.children[0]
            if stmt.type == syms.expr_stmt:
                expr = stmt.children
                if not skip_assignments:
                    break

                if (
                    len(expr) != 2
                    or expr[0].type != token.NAME
                    or expr[1].type != syms.annassign
                    or _eq in expr[1].children
                ):
                    break

            elif stmt.type not in (syms.import_name, syms.import_from, token.STRING):
                break

        elif child.type == token.INDENT:
            assert isinstance(child, Leaf)
            prefix = child.value
        elif child.type != token.NEWLINE:
            break

    prefix, child.prefix = child.prefix, prefix
    return _offset, prefix 
开发者ID:ambv,项目名称:retype,代码行数:42,代码来源:__init__.py


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