소스 검색

add unicode helpers back

pull/241/head
William Ting 10 년 전
부모
커밋
8cbd19cc79
2개의 변경된 파일26개의 추가작업 그리고 1개의 파일을 삭제
  1. +1
    -1
      bin/data.py
  2. +25
    -0
      bin/utils.py

+ 1
- 1
bin/data.py 파일 보기

@ -39,7 +39,7 @@ def load(config):
parse = lambda x: x.strip().split('\t')
# 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 {}

+ 25
- 0
bin/utils.py 파일 보기

@ -17,6 +17,31 @@ def create_dir(path):
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():
return platform.system() == 'Linux'

불러오는 중...
취소
저장