Exemplo n.º 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
Exemplo n.º 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))
Exemplo n.º 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))
Exemplo n.º 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))
Exemplo n.º 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
Exemplo n.º 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
Exemplo n.º 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))