Mercurial > public > mercurial-scm > hg-stable
diff 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 |
line wrap: on
line diff
--- a/mercurial/encoding.py Mon Mar 13 09:11:08 2017 -0700 +++ b/mercurial/encoding.py Mon Mar 13 09:12:56 2017 -0700 @@ -204,6 +204,16 @@ """Convert a byte string of local encoding to a unicode string""" return fromlocal(s).decode('utf-8') +# converter functions between native str and byte string. use these if the +# character encoding is not aware (e.g. exception message) or is known to +# be locale dependent (e.g. date formatting.) +if pycompat.ispy3: + strtolocal = unitolocal + strfromlocal = unifromlocal +else: + strtolocal = str + strfromlocal = str + if not _nativeenviron: # now encoding and helper functions are available, recreate the environ # dict to be exported to other modules