Mercurial > hgrepos > Python > libs > ConfigMix
view configmix/compat.py @ 100:e3289a56ba80
Enhance docu
| author | Franz Glasner <f.glasner@feldmann-mg.com> |
|---|---|
| date | Thu, 22 Mar 2018 16:22:22 +0100 |
| parents | 218807d7d883 |
| children | e2e8d21b4122 |
line wrap: on
line source
# -*- coding: utf-8 -*- #- # :Copyright: (c) 2015-2018, Franz Glasner. All rights reserved. # :License: 3-clause BSD. See LICENSE.txt for details. #- """Some minimal compatibility shim between Python2 and Python3 """ from __future__ import division, absolute_import, print_function import sys import locale __all__ = ["PY2", "text_to_native_os_str", "native_os_str_to_text", "u"] PY2 = sys.version_info[0] <= 2 if PY2: _OS_ENCODING = locale.getpreferredencoding() def text_to_native_os_str(s, encoding=None): if isinstance(s, unicode): return s.encode(encoding or _OS_ENCODING) else: return s def native_os_str_to_text(s, encoding=None): return s.decode(encoding or _OS_ENCODING) def u(s, encoding="utf-8"): if isinstance(s, unicode): return s else: return s.decode(encoding) else: def text_to_native_os_str(s, encoding=None): return s def native_os_str_to_text(s, encoding=None): return s def u(s, encoding="utf-8"): if isinstance(s, str): return s else: return s.decode(encoding)
