Mercurial > hg-stable
diff mercurial/encoding.py @ 31456:067add650129
encoding: factor out unicode variants of from/tolocal()
Unfortunately, these functions will be commonly used on Python 3.
author | Yuya Nishihara <yuya@tcha.org> |
---|---|
date | Mon, 13 Mar 2017 09:11:08 -0700 |
parents | ce36fa9b140c |
children | 6419cd243017 |
line wrap: on
line diff
--- a/mercurial/encoding.py Mon Mar 13 08:53:31 2017 -0700 +++ b/mercurial/encoding.py Mon Mar 13 09:11:08 2017 -0700 @@ -196,6 +196,14 @@ except LookupError as k: raise error.Abort(k, hint="please check your locale settings") +def unitolocal(u): + """Convert a unicode string to a byte string of local encoding""" + return tolocal(u.encode('utf-8')) + +def unifromlocal(s): + """Convert a byte string of local encoding to a unicode string""" + return fromlocal(s).decode('utf-8') + if not _nativeenviron: # now encoding and helper functions are available, recreate the environ # dict to be exported to other modules