comparison mercurial/encoding.py @ 31457:6419cd243017

encoding: add converter between native str and byte string This kind of encoding conversion is unavoidable on Python 3.
author Yuya Nishihara <yuya@tcha.org>
date Mon, 13 Mar 2017 09:12:56 -0700
parents 067add650129
children 7d2cbe11ae48
comparison
equal deleted inserted replaced
31456:067add650129 31457:6419cd243017
201 return tolocal(u.encode('utf-8')) 201 return tolocal(u.encode('utf-8'))
202 202
203 def unifromlocal(s): 203 def unifromlocal(s):
204 """Convert a byte string of local encoding to a unicode string""" 204 """Convert a byte string of local encoding to a unicode string"""
205 return fromlocal(s).decode('utf-8') 205 return fromlocal(s).decode('utf-8')
206
207 # converter functions between native str and byte string. use these if the
208 # character encoding is not aware (e.g. exception message) or is known to
209 # be locale dependent (e.g. date formatting.)
210 if pycompat.ispy3:
211 strtolocal = unitolocal
212 strfromlocal = unifromlocal
213 else:
214 strtolocal = str
215 strfromlocal = str
206 216
207 if not _nativeenviron: 217 if not _nativeenviron:
208 # now encoding and helper functions are available, recreate the environ 218 # now encoding and helper functions are available, recreate the environ
209 # dict to be exported to other modules 219 # dict to be exported to other modules
210 environ = dict((tolocal(k.encode(u'utf-8')), tolocal(v.encode(u'utf-8'))) 220 environ = dict((tolocal(k.encode(u'utf-8')), tolocal(v.encode(u'utf-8')))