Esempio n. 1
0
    def _get_module(self):
        cache.invalidate_star_import_cache(self._path)
        parser = FastParser(self._grammar, self._source, self.path)
        save_parser(self.path, parser, pickling=False)

        module = self._evaluator.wrap(parser.module)
        imports.add_module(self._evaluator, unicode(module.name), module)
        return parser.module
Esempio n. 2
0
    def load(buildout_script):
        try:
            with open(buildout_script, 'rb') as f:
                source = common.source_to_unicode(f.read())
        except IOError:
            debug.dbg('Error trying to read buildout_script: %s', buildout_script)
            return

        p = ParserWithRecovery(evaluator.grammar, source, buildout_script)
        save_parser(buildout_script, p)
        return p.module
Esempio n. 3
0
    def load(buildout_script):
        try:
            with open(buildout_script, 'rb') as f:
                source = common.source_to_unicode(f.read())
        except IOError:
            debug.dbg('Error trying to read buildout_script: %s', buildout_script)
            return

        p = ParserWithRecovery(evaluator.grammar, source, buildout_script)
        save_parser(buildout_script, p)
        return p.module
Esempio n. 4
0
def check_fp(src, number_parsers_used, number_of_splits=None, number_of_misses=0):
    if number_of_splits is None:
        number_of_splits = number_parsers_used

    p = FastParser(load_grammar(), u(src))
    save_parser(None, p, pickling=False)

    assert src == p.module.get_code()
    assert p.number_of_splits == number_of_splits
    assert p.number_parsers_used == number_parsers_used
    assert p.number_of_misses == number_of_misses
    return p.module
Esempio n. 5
0
def check_p(src,
            number_parsers_used,
            number_of_splits=None,
            number_of_misses=0):
    if number_of_splits is None:
        number_of_splits = number_parsers_used

    p = FastParser(load_grammar(), u(src))
    save_parser(None, p, pickling=False)

    assert src == p.module.get_code()
    return p.module
Esempio n. 6
0
 def load(source):
     dotted_path = path and compiled.dotted_from_fs_path(path, sys_path)
     if path is not None and path.endswith(('.py', '.zip', '.egg')) \
             and dotted_path not in settings.auto_import_modules:
         if source is None:
             with open(path, 'rb') as f:
                 source = f.read()
     else:
         return compiled.load_module(evaluator, path)
     p = path
     p = FastParser(evaluator.grammar, source_to_unicode(source), p)
     save_parser(path, p)
     return p.module
Esempio n. 7
0
def test_open_parentheses():
    func = 'def func():\n a'
    code = u('isinstance(\n\n' + func)
    p = FastParser(load_grammar(), code)
    # As you can see, the part that was failing is still there in the get_code
    # call. It is not relevant for evaluation, but still available as an
    # ErrorNode.
    assert p.module.get_code() == code
    assert p.number_of_splits == 2
    assert p.number_parsers_used == 2
    save_parser(None, p, pickling=False)

    # Now with a correct parser it should work perfectly well.
    check_fp('isinstance()\n' + func, 1, 2)
Esempio n. 8
0
def test_open_parentheses():
    func = 'def func():\n a'
    code = u('isinstance(\n\n' + func)
    p = FastParser(load_grammar(), code)
    # As you can see, the part that was failing is still there in the get_code
    # call. It is not relevant for evaluation, but still available as an
    # ErrorNode.
    assert p.module.get_code() == code
    assert p.number_of_splits == 2
    assert p.number_parsers_used == 2
    save_parser(None, p, pickling=False)

    # Now with a correct parser it should work perfectly well.
    check_fp('isinstance()\n' + func, 1, 2)
 def load(source):
     dotted_path = path and compiled.dotted_from_fs_path(path, sys_path)
     if path is not None and path.endswith(('.py', '.zip', '.egg')) \
             and dotted_path not in settings.auto_import_modules:
         if source is None:
             with open(path, 'rb') as f:
                 source = f.read()
     else:
         return compiled.load_module(evaluator, path)
     p = path
     p = fast.FastParser(evaluator.grammar, common.source_to_unicode(source), p)
     save_parser(path, p)
     from jedi.evaluate.representation import ModuleWrapper
     return ModuleWrapper(evaluator, p.module, parent_module)
Esempio n. 10
0
 def load(source):
     dotted_path = path and compiled.dotted_from_fs_path(path, sys_path)
     if path is not None and path.endswith(('.py', '.zip', '.egg')) \
             and dotted_path not in settings.auto_import_modules:
         if source is None:
             with open(path, 'rb') as f:
                 source = f.read()
     else:
         return compiled.load_module(evaluator, path)
     p = path
     p = fast.FastParser(evaluator.grammar,
                         common.source_to_unicode(source), p)
     save_parser(path, p)
     from jedi.evaluate.representation import ModuleWrapper
     return ModuleWrapper(evaluator, p.module, parent_module)
Esempio n. 11
0
    def _get_module_node(self):
        cache.invalidate_star_import_cache(self._path)
        parser = FastParser(self._grammar, self._source, self.path)
        save_parser(self.path, parser, pickling=False)

        return parser.module