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


Python _ast.Str方法代码示例

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


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

示例1: make_const

# 需要导入模块: import _ast [as 别名]
# 或者: from _ast import Str [as 别名]
def make_const(i, bytecode):
    arg = bytecode[i][3]
    if isinstance(arg, basestring):
      return i, _ast.Str(arg)
    elif isinstance(arg, int) or isinstance(arg, float) or isinstance(arg, long):
      return i, _ast.Num(arg)
    elif isinstance(arg, dict):
      return i, _ast.Dict(arg.keys(), arg.values())
    elif isinstance(arg, set):
      return i, _ast.Dict(arg)
    elif isinstance(arg, tuple):
      return i, _ast.Tuple(arg, _ast.Load())
    elif isinstance(arg, list):
      return i, _ast.List(arg, _ast.Load())
    elif isinstance(arg, bytes):
      return i, _ast.Bytes(arg)
    return i, None 
开发者ID:neuroo,项目名称:equip,代码行数:19,代码来源:stmt.py

示例2: convert_to_value

# 需要导入模块: import _ast [as 别名]
# 或者: from _ast import Str [as 别名]
def convert_to_value(item):
    if isinstance(item, ast.Str):
        return item.s
    elif hasattr(ast, 'Bytes') and isinstance(item, ast.Bytes):
        return item.s
    elif isinstance(item, ast.Tuple):
        return tuple(convert_to_value(i) for i in item.elts)
    elif isinstance(item, ast.Num):
        return item.n
    elif isinstance(item, ast.Name):
        result = VariableKey(item=item)
        constants_lookup = {
            'True': True,
            'False': False,
            'None': None,
        }
        return constants_lookup.get(
            result.name,
            result,
        )
    elif (not PY33) and isinstance(item, ast.NameConstant):
        # None, True, False are nameconstants in python3, but names in 2
        return item.value
    else:
        return UnhandledKeyType() 
开发者ID:zrzka,项目名称:blackmamba,代码行数:27,代码来源:checker.py

示例3: _get_doc

# 需要导入模块: import _ast [as 别名]
# 或者: from _ast import Str [as 别名]
def _get_doc(node):
    try:
        if isinstance(node.body[0], _ast.Expr) and isinstance(node.body[0].value, _ast.Str):
            doc = node.body[0].value.s
            node.body = node.body[1:]
            return node, doc
    except IndexError:
        pass # ast built from scratch
    return node, None 
开发者ID:AtomLinter,项目名称:linter-pylama,代码行数:11,代码来源:rebuilder.py

示例4: sequence_typeof

# 需要导入模块: import _ast [as 别名]
# 或者: from _ast import Str [as 别名]
def sequence_typeof(ast_node):
  if isinstance(ast_node, _ast.Str):
    return StringType()
  elif isinstance(ast_node, _ast.Tuple):
    return TupleType()
  elif isinstance(ast_node, _ast.List):
    return ListType()

  return SequenceType() 
开发者ID:neuroo,项目名称:equip,代码行数:11,代码来源:types.py

示例5: is_sequence

# 需要导入模块: import _ast [as 别名]
# 或者: from _ast import Str [as 别名]
def is_sequence(ast_node):
  return isinstance(ast_node, _ast.Str)   \
      or isinstance(ast_node, _ast.Tuple) \
      or isinstance(ast_node, _ast.List) 
开发者ID:neuroo,项目名称:equip,代码行数:6,代码来源:types.py

示例6: __init__

# 需要导入模块: import _ast [as 别名]
# 或者: from _ast import Str [as 别名]
def __init__(self, name, source, scope):
        if '__all__' in scope and isinstance(source, ast.AugAssign):
            self.names = list(scope['__all__'].names)
        else:
            self.names = []
        if isinstance(source.value, (ast.List, ast.Tuple)):
            for node in source.value.elts:
                if isinstance(node, ast.Str):
                    self.names.append(node.s)
        super(ExportBinding, self).__init__(name, source) 
开发者ID:zrzka,项目名称:blackmamba,代码行数:12,代码来源:checker.py

示例7: isDocstring

# 需要导入模块: import _ast [as 别名]
# 或者: from _ast import Str [as 别名]
def isDocstring(self, node):
        """
        Determine if the given node is a docstring, as long as it is at the
        correct place in the node tree.
        """
        return isinstance(node, ast.Str) or (isinstance(node, ast.Expr) and
                                             isinstance(node.value, ast.Str)) 
开发者ID:zrzka,项目名称:blackmamba,代码行数:9,代码来源:checker.py

示例8: getDocstring

# 需要导入模块: import _ast [as 别名]
# 或者: from _ast import Str [as 别名]
def getDocstring(self, node):
        if isinstance(node, ast.Expr):
            node = node.value
        if not isinstance(node, ast.Str):
            return (None, None)

        if PYPY:
            doctest_lineno = node.lineno - 1
        else:
            # Computed incorrectly if the docstring has backslash
            doctest_lineno = node.lineno - node.s.count('\n') - 1

        return (node.s, doctest_lineno) 
开发者ID:zrzka,项目名称:blackmamba,代码行数:15,代码来源:checker.py

示例9: parse_function

# 需要导入模块: import _ast [as 别名]
# 或者: from _ast import Str [as 别名]
def parse_function(node):
    old_style = None
    new_style = None
    output = None
    setup = []
    setup_done = False
    title, details = parse_docstring(ast.get_docstring(node, clean=True))
    name = node.name[5:] if node.name.startswith('test_') else node.name

    for n in node.body:
        # Ignore the docstring
        if isinstance(n, _ast.Expr) and isinstance(n.value, _ast.Str):
            continue
        if isinstance(n, _ast.Assign) and n.targets[0].id == 'old_result':
            setup_done = True
            old_style = unparse(n.value, strip=True)
        if isinstance(n, _ast.Assign) and n.targets[0].id == 'new_result':
            setup_done = True
            new_style = unparse(n.value, strip=True)
        if isinstance(n, _ast.Assert) and isinstance(
                n.test.comparators[0], _ast.Str):
            setup_done = True
            output = n.test.comparators[0].s
        if not setup_done:
            setup.append(n)

    if setup:
        setup = unparse(setup, strip=True)

    return Example(
        name,
        title,
        details,
        setup or "",
        old_style or "",
        new_style or "",
        output or ""
    ) 
开发者ID:ulope,项目名称:pyformat.info,代码行数:40,代码来源:main.py

示例10: getDocstring

# 需要导入模块: import _ast [as 别名]
# 或者: from _ast import Str [as 别名]
def getDocstring(self, node):
        if isinstance(node, ast.Expr):
            node = node.value
        if not isinstance(node, ast.Str):
            return (None, None)
        # Computed incorrectly if the docstring has backslash
        doctest_lineno = node.lineno - node.s.count('\n') - 1
        return (node.s, doctest_lineno) 
开发者ID:QQuick,项目名称:Transcrypt,代码行数:10,代码来源:checker.py


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