示例#1
0
class Traverser:

  def __init__(self):
    self._script = Script('', 1, 0, 'example.py')
    self._module = self._script._get_module()

  def names_in_module(self, module_name):
    try:
      _import_module(module_name)
    except Exception as e:
      pp.pprint(e)
      return []

    imp = Importer(
        self._script._evaluator, [FakeName('.'.join(module_name))],
        self._module, 0)
    try:
      scope_set = imp.follow()
    except Exception as e:
      # print('Error "{}" in {}, ignoring...'.format(e, module_name))
      return []

    all_names = []
    for s in scope_set:
      names = []
      for names_dict in s.names_dicts(search_global=False):
        names += chain.from_iterable(names_dict.values())

      all_names += finder.filter_definition_names(names, self._module)
    return all_names
示例#2
0
 def paths(src):
     script = Script(src)
     expr_stmt = script._get_module_node().children[0].children[0]
     return set(
         sys_path._paths_from_assignment(script._get_module(), expr_stmt))
示例#3
0
 def paths(src):
     script = Script(src)
     expr_stmt = script._get_module_node().children[0].children[0]
     return set(sys_path._paths_from_assignment(script._get_module(), expr_stmt))
示例#4
0
 def paths(src):
     script = Script(src)
     stmt = script._get_module_node().statements[0]
     return set(sys_path._paths_from_assignment(script._get_module(), stmt))
示例#5
0
def test_equals(source):
    script = Script(source)
    node = script._get_module_node().children[0].children[0]
    first, = script._get_module().eval_node(node)
    assert isinstance(first, CompiledObject) and first.obj is True
示例#6
0
def test_equals(source):
    script = Script(source)
    node = script._get_module_node().children[0].children[0]
    first, = script._get_module().eval_node(node)
    assert isinstance(first, CompiledObject) and first.obj is True
示例#7
0
 def paths(src):
     script = Script(src, path='/foo/bar.py')
     expr_stmt = script._module_node.children[0]
     return set(
         sys_path._paths_from_assignment(script._get_module(), expr_stmt))