示例#1
0
    def fp(src):
        p = FastParser(u(src))
        cache.save_parser(None, None, p, pickling=False)

        # TODO Don't change get_code, the whole thing should be the same.
        # -> Need to refactor the parser first, though.
        assert src == p.module.get_code()[:-1]
示例#2
0
文件: __init__.py 项目: beyang/jedi
def precache_parser(*files):
    for f in files:
        f = os.path.abspath(f)
        with open(f) as f_:
            source = f_.read()
            source = common.source_to_unicode(source, 'utf-8')
            parser = FastParser(source, f)
            cache.save_parser(f, None, parser, pickling=False)
示例#3
0
 def _parser(self):
     cache.invalidate_star_import_cache(self._path)
     if self._use_fast_parser:
         parser = FastParser(self._grammar, self._source, self._path)
         # Don't pickle that module, because the main module is changing quickly
         cache.save_parser(self._path, None, parser, pickling=False)
     else:
         parser = Parser(self._grammar, self._source, self._path)
     return parser
示例#4
0
文件: sys_path.py 项目: Axure/jedi
    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 = Parser(evaluator.grammar, source, buildout_script)
        cache.save_parser(buildout_script, None, p)
        return p.module
示例#5
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 = Parser(evaluator.grammar, source, buildout_script)
        cache.save_parser(buildout_script, p)
        return p.module
示例#6
0
文件: imports.py 项目: ldong/dotfiles
 def load(source):
     if path is not None and path.endswith('.py'):
         if source is None:
             with open(path) as f:
                 source = f.read()
     else:
         return compiled.load_module(path, name)
     p = path or name
     p = fast.FastParser(common.source_to_unicode(source), p)
     cache.save_parser(path, name, p)
     return p.module
示例#7
0
 def load(source):
     if path is not None and path.endswith('.py'):
         if source is None:
             with open(path) as f:
                 source = f.read()
     else:
         return compiled.load_module(path, name)
     p = path or name
     p = fast.FastParser(common.source_to_unicode(source), p)
     cache.save_parser(path, name, p)
     return p.module
示例#8
0
def test_open_parentheses():
    func = 'def func():\n a'
    p = FastParser(load_grammar(), u('isinstance(\n\n' + func))
    # As you can see, the isinstance call cannot be seen anymore after
    # get_code, because it isn't valid code.
    assert p.module.get_code() == '\n\n' + func
    assert p.number_of_splits == 2
    assert p.number_parsers_used == 2
    cache.save_parser(None, p, pickling=False)

    # Now with a correct parser it should work perfectly well.
    check_fp('isinstance()\n' + func, 1, 2)
示例#9
0
def test_open_parentheses():
    func = 'def func():\n a'
    p = FastParser(load_grammar(), 'isinstance(\n\n' + func)
    # As you can see, the isinstance call cannot be seen anymore after
    # get_code, because it isn't valid code.
    assert p.module.get_code() == '\n\n' + func
    assert p.number_of_splits == 2
    assert p.number_parsers_used == 2
    cache.save_parser(None, None, p, pickling=False)

    # Now with a correct parser it should work perfectly well.
    check_fp('isinstance()\n' + func, 1, 2)
示例#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") and not dotted_path in settings.auto_import_modules:
         if source is None:
             with open(path, "rb") as f:
                 source = f.read()
     else:
         return compiled.load_module(path)
     p = path
     p = fast.FastParser(evaluator.grammar, common.source_to_unicode(source), p)
     cache.save_parser(path, p)
     return p.module
示例#11
0
文件: imports.py 项目: awalex/awemacs
 def load(source):
     dotted_path = path and compiled.dotted_from_fs_path(path, sys_path)
     if path is not None and path.endswith('.py') \
             and not dotted_path in settings.auto_import_modules:
         if source is None:
             with open(path, 'rb') as f:
                 source = f.read()
     else:
         return compiled.load_module(path, name)
     p = path or name
     p = fast.FastParser(common.source_to_unicode(source), p)
     cache.save_parser(path, name, p)
     return p.module
示例#12
0
def check_fp(src, number_parsers_used, number_of_splits=None):
    if number_of_splits is None:
        number_of_splits = number_parsers_used

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

    # TODO Don't change get_code, the whole thing should be the same.
    # -> Need to refactor the parser first, though.
    assert src == p.module.get_code()
    assert p.number_of_splits == number_of_splits
    assert p.number_parsers_used == number_parsers_used
    return p.module
示例#13
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') \
             and not dotted_path in settings.auto_import_modules:
         if source is None:
             with open(path, 'rb') as f:
                 source = f.read()
     else:
         return compiled.load_module(path, name)
     p = path or name
     p = fast.FastParser(evaluator.grammar, common.source_to_unicode(source), p)
     cache.save_parser(path, name, p)
     return p.module
示例#14
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))
    cache.save_parser(None, None, p, pickling=False)

    # TODO Don't change get_code, the whole thing should be the same.
    # -> Need to refactor the parser first, though.
    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