Be more correct about encoding/decoding strings under py3. Patch by aeruder.
This commit is contained in:
commit
eff62c336a
@ -1384,6 +1384,7 @@ individuals have contributed to UltiSnips (in chronological order):
|
|||||||
Pedro Ferrari - petobens
|
Pedro Ferrari - petobens
|
||||||
Ches Martin - ches
|
Ches Martin - ches
|
||||||
Christian - Oberon00
|
Christian - Oberon00
|
||||||
|
Andrew Ruder - aeruder
|
||||||
|
|
||||||
Thank you for your support.
|
Thank you for your support.
|
||||||
|
|
||||||
|
@ -10,22 +10,21 @@ import sys
|
|||||||
|
|
||||||
import vim # pylint:disable=import-error
|
import vim # pylint:disable=import-error
|
||||||
|
|
||||||
def _vim_dec(string):
|
|
||||||
"""Decode 'string' using &encoding."""
|
|
||||||
try:
|
|
||||||
return string.decode(vim.eval("&encoding"))
|
|
||||||
except UnicodeDecodeError:
|
|
||||||
# At least we tried. There might be some problems down the road now
|
|
||||||
return string
|
|
||||||
|
|
||||||
def _vim_enc(string):
|
|
||||||
"""Encode 'string' using &encoding."""
|
|
||||||
try:
|
|
||||||
return string.encode(vim.eval("&encoding"))
|
|
||||||
except UnicodeEncodeError:
|
|
||||||
return string
|
|
||||||
|
|
||||||
if sys.version_info >= (3, 0):
|
if sys.version_info >= (3, 0):
|
||||||
|
def _vim_dec(string):
|
||||||
|
"""Decode 'string' using &encoding."""
|
||||||
|
# We don't have the luxury here of failing, everything
|
||||||
|
# falls apart if we don't return a bytearray from the
|
||||||
|
# passed in string
|
||||||
|
return string.decode(vim.eval("&encoding"), "replace")
|
||||||
|
|
||||||
|
def _vim_enc(bytearray):
|
||||||
|
"""Encode 'string' using &encoding."""
|
||||||
|
# We don't have the luxury here of failing, everything
|
||||||
|
# falls apart if we don't return a string from the passed
|
||||||
|
# in bytearray
|
||||||
|
return bytearray.encode(vim.eval("&encoding"), "replace")
|
||||||
|
|
||||||
def open_ascii_file(filename, mode):
|
def open_ascii_file(filename, mode):
|
||||||
"""Opens a file in "r" mode."""
|
"""Opens a file in "r" mode."""
|
||||||
return open(filename, mode, encoding="utf-8")
|
return open(filename, mode, encoding="utf-8")
|
||||||
@ -60,6 +59,22 @@ if sys.version_info >= (3, 0):
|
|||||||
else:
|
else:
|
||||||
import warnings
|
import warnings
|
||||||
warnings.filterwarnings("ignore", category=DeprecationWarning)
|
warnings.filterwarnings("ignore", category=DeprecationWarning)
|
||||||
|
|
||||||
|
def _vim_dec(string):
|
||||||
|
"""Decode 'string' using &encoding."""
|
||||||
|
try:
|
||||||
|
return string.decode(vim.eval("&encoding"))
|
||||||
|
except UnicodeDecodeError:
|
||||||
|
# At least we tried. There might be some problems down the road now
|
||||||
|
return string
|
||||||
|
|
||||||
|
def _vim_enc(string):
|
||||||
|
"""Encode 'string' using &encoding."""
|
||||||
|
try:
|
||||||
|
return string.encode(vim.eval("&encoding"))
|
||||||
|
except UnicodeEncodeError:
|
||||||
|
return string
|
||||||
|
|
||||||
def open_ascii_file(filename, mode):
|
def open_ascii_file(filename, mode):
|
||||||
"""Opens a file in "r" mode."""
|
"""Opens a file in "r" mode."""
|
||||||
return open(filename, mode)
|
return open(filename, mode)
|
||||||
|
Loading…
Reference in New Issue
Block a user