Fixes for Python 3

This commit is contained in:
Holger Rapp 2012-01-28 14:03:08 +01:00
parent e69838c4bf
commit 5ebad7351c
6 changed files with 11 additions and 5 deletions

View File

@ -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))

View File

@ -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, ()) ]

View File

@ -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 ]

View File

@ -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:

View File

@ -1,7 +1,7 @@
#!/usr/bin/env python
# encoding: utf-8
from _snippet_instance import SnippetInstance
from ._snippet_instance import SnippetInstance
__all__ = [ "SnippetInstance" ]

View File

@ -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]