diff options
| author | Thiago de Arruda <tpadilha84@gmail.com> | 2015-04-23 08:27:17 -0300 | 
|---|---|---|
| committer | Thiago de Arruda <tpadilha84@gmail.com> | 2015-04-23 08:27:17 -0300 | 
| commit | 04e098fc3c485eaa6d323e9121e9c81215d94a87 (patch) | |
| tree | 6baa4183e8a40f6687a8825f4dde662ae650075c /runtime/autoload/provider/script_host.py | |
| parent | 0bd72fcae1071d1a5583af31f29e2223925044bc (diff) | |
| parent | 577d9f3f7e41cd2ac4813a35832bb2550c31a481 (diff) | |
| download | rneovim-04e098fc3c485eaa6d323e9121e9c81215d94a87.tar.gz rneovim-04e098fc3c485eaa6d323e9121e9c81215d94a87.tar.bz2 rneovim-04e098fc3c485eaa6d323e9121e9c81215d94a87.zip  | |
Merge PR #2208 'if_python3 support'
Diffstat (limited to 'runtime/autoload/provider/script_host.py')
| -rw-r--r-- | runtime/autoload/provider/script_host.py | 23 | 
1 files changed, 15 insertions, 8 deletions
diff --git a/runtime/autoload/provider/script_host.py b/runtime/autoload/provider/script_host.py index 14208310aa..e0b9ee6012 100644 --- a/runtime/autoload/provider/script_host.py +++ b/runtime/autoload/provider/script_host.py @@ -1,4 +1,4 @@ -"""Legacy python-vim emulation.""" +"""Legacy python/python3-vim emulation."""  import imp  import logging  import os @@ -35,7 +35,7 @@ class ScriptHost(object):          if IS_PYTHON3:              self.legacy_vim = self.legacy_vim.with_hook(                  neovim.DecodeHook( -                    encoding=nvim.options['encoding'].decode('ascii'))) +                    encoding=nvim.options['encoding']))          sys.modules['vim'] = self.legacy_vim      def setup(self, nvim): @@ -96,7 +96,7 @@ class ScriptHost(object):          # Python3 code (exec) must be a string, mixing bytes with          # function_def would use bytes.__repr__ instead          if isinstance and isinstance(code, bytes): -            code = code.decode(nvim.options['encoding'].decode('ascii')) +            code = code.decode(nvim.options['encoding'])          # define the function          function_def = 'def %s(line, linenr):\n %s' % (fname, code,)          exec(function_def, self.module.__dict__) @@ -166,6 +166,9 @@ class RedirectStream(object):      def writelines(self, seq):          self.redirect_handler('\n'.join(seq)) +    def flush(self): +        pass +  class LegacyEvalHook(neovim.SessionHook): @@ -175,8 +178,12 @@ class LegacyEvalHook(neovim.SessionHook):          super(LegacyEvalHook, self).__init__(from_nvim=self._string_eval)      def _string_eval(self, obj, session, method, kind): -        if method == 'vim_eval' and isinstance(obj, (int, long, float)): -            return str(obj) +        if method == 'vim_eval': +            if IS_PYTHON3: +                if isinstance(obj, (int, float)): +                    return str(obj) +            elif isinstance(obj, (int, long, float)): +                return str(obj)          return obj @@ -231,11 +238,11 @@ def discover_runtime_directories(nvim):      for path in nvim.list_runtime_paths():          if not os.path.exists(path):              continue -        path1 = os.path.join(path, b'pythonx') +        path1 = os.path.join(path, 'pythonx')          if IS_PYTHON3: -            path2 = os.path.join(path, b'python3') +            path2 = os.path.join(path, 'python3')          else: -            path2 = os.path.join(path, b'python2') +            path2 = os.path.join(path, 'python2')          if os.path.exists(path1):              rv.append(path1)          if os.path.exists(path2):  | 
