1
0
mirror of https://github.com/wting/autojump synced 2024-10-27 20:34:07 +00:00

add unicode helpers back

This commit is contained in:
William Ting 2013-12-16 15:39:49 -06:00
parent 7671fcbd06
commit 8cbd19cc79
2 changed files with 26 additions and 1 deletions

View File

@ -39,7 +39,7 @@ def load(config):
parse = lambda x: x.strip().split('\t') parse = lambda x: x.strip().split('\t')
# example: ['10.0', u'/home/user'] -> (u'/home/user', 10.0) # example: ['10.0', u'/home/user'] -> (u'/home/user', 10.0)
convert = lambda x: (x[1], float(x[0]) convert = lambda x: (x[1], float(x[0]))
return dict(imap(convert, imap(parse, lines))) return dict(imap(convert, imap(parse, lines)))
return {} return {}

View File

@ -17,6 +17,31 @@ def create_dir(path):
raise raise
def decode(string):
"""Converts byte string to Unicode string."""
if is_python2():
return string.decode('utf-8', errors='replace')
return string
def encode(string):
"""Converts Unicode string to byte string."""
if is_python2():
return string.encode('utf-8', errors='replace')
return string
def encode_local(string, encoding=None):
"""Converts string into local filesystem encoding."""
if is_python2():
return decode(string).encode(encoding or sys.getfilesystemencoding())
return string
def is_python2():
return sys.version_info[0] == 2
def is_linux(): def is_linux():
return platform.system() == 'Linux' return platform.system() == 'Linux'