From 5ebad7351c4e8ffce643a0582ede2510076c5592 Mon Sep 17 00:00:00 2001 From: Holger Rapp Date: Sat, 28 Jan 2012 14:03:08 +0100 Subject: [PATCH] Fixes for Python 3 --- plugin/UltiSnips/__init__.py | 3 ++- plugin/UltiSnips/_diff.py | 2 +- plugin/UltiSnips/_vim.py | 4 ++++ plugin/UltiSnips/debug.py | 2 +- plugin/UltiSnips/text_objects/__init__.py | 2 +- plugin/UltiSnips/text_objects/_shell_code.py | 3 ++- 6 files changed, 11 insertions(+), 5 deletions(-) diff --git a/plugin/UltiSnips/__init__.py b/plugin/UltiSnips/__init__.py index 7e32ba5..99fe36c 100644 --- a/plugin/UltiSnips/__init__.py +++ b/plugin/UltiSnips/__init__.py @@ -8,7 +8,7 @@ import os import re import traceback -from debug import echo_to_hierarchy, debug +from UltiSnips.debug import echo_to_hierarchy, debug from UltiSnips.compatibility import as_unicode from UltiSnips._diff import diff, guess_edit @@ -597,6 +597,7 @@ class SnippetManager(object): ct_span = [0, len(ct)] initial_line = cstart + debug("type(lt): %r, type(ct): %r" % (type(lt), type(ct))) debug("lt: %r" % (lt)) debug("ct: %r" % (ct)) debug("self._lpos: %r, pos: %r" % (self._lpos, pos)) diff --git a/plugin/UltiSnips/_diff.py b/plugin/UltiSnips/_diff.py index 1a1410d..2357ef9 100644 --- a/plugin/UltiSnips/_diff.py +++ b/plugin/UltiSnips/_diff.py @@ -77,7 +77,7 @@ def diff(a, b, sline = 0): and not after \n """ d = defaultdict(list) - seen = defaultdict(lambda: sys.maxint) + seen = defaultdict(lambda: sys.maxsize) d[0] = [ (0,0,sline, 0, ()) ] diff --git a/plugin/UltiSnips/_vim.py b/plugin/UltiSnips/_vim.py index 3ec94a6..40487d7 100755 --- a/plugin/UltiSnips/_vim.py +++ b/plugin/UltiSnips/_vim.py @@ -14,6 +14,8 @@ from UltiSnips.compatibility import vim_cursor, set_vim_cursor, \ class VimBuffer(object): def __getitem__(self, idx): + if isinstance(idx, slice): # Py3 + return self.__getslice__(idx.start, idx.stop) rv = vim.current.buffer[idx] return as_unicode(rv) def __getslice__(self, i, j): @@ -21,6 +23,8 @@ class VimBuffer(object): return [ as_unicode(l) for l in rv ] def __setitem__(self, idx, text): + if isinstance(idx, slice): # Py3 + return self.__setslice__(idx.start, idx.stop, text) vim.current.buffer[idx] = as_vimencoding(text) def __setslice__(self, i, j, text): vim.current.buffer[i:j] = [ as_vimencoding(l) for l in text ] diff --git a/plugin/UltiSnips/debug.py b/plugin/UltiSnips/debug.py index 86e1f1e..6951083 100644 --- a/plugin/UltiSnips/debug.py +++ b/plugin/UltiSnips/debug.py @@ -12,7 +12,7 @@ def echo_to_hierarchy(to): while par._parent: par = par._parent def _do_print(to, indent=""): - debug(indent + unicode(to)) + debug(indent + as_unicode(to)) try: for c in to._childs: diff --git a/plugin/UltiSnips/text_objects/__init__.py b/plugin/UltiSnips/text_objects/__init__.py index 3df0757..27e87f9 100644 --- a/plugin/UltiSnips/text_objects/__init__.py +++ b/plugin/UltiSnips/text_objects/__init__.py @@ -1,7 +1,7 @@ #!/usr/bin/env python # encoding: utf-8 -from _snippet_instance import SnippetInstance +from ._snippet_instance import SnippetInstance __all__ = [ "SnippetInstance" ] diff --git a/plugin/UltiSnips/text_objects/_shell_code.py b/plugin/UltiSnips/text_objects/_shell_code.py index 04c89df..22d57bc 100755 --- a/plugin/UltiSnips/text_objects/_shell_code.py +++ b/plugin/UltiSnips/text_objects/_shell_code.py @@ -6,6 +6,7 @@ import subprocess import stat import tempfile +from UltiSnips.compatibility import as_unicode from UltiSnips.text_objects._base import NoneditableTextObject class ShellCode(NoneditableTextObject): @@ -24,7 +25,7 @@ class ShellCode(NoneditableTextObject): # Execute the file and read stdout proc = subprocess.Popen(path, shell=True, stdout=subprocess.PIPE) proc.wait() - output = proc.stdout.read() + output = as_unicode(proc.stdout.read()) if len(output) and output[-1] == '\n': output = output[:-1]