comparison configmix/compat.py @ 15:0b1292e920af

Variables: namespaces and filters
author Franz Glasner <f.glasner@feldmann-mg.com>
date Wed, 09 Mar 2016 15:35:46 +0100
parents dc058099a4cb
children f85dc4677c01
comparison
equal deleted inserted replaced
14:36fa039f7e11 15:0b1292e920af
1 # -*- coding: utf-8 -*- 1 # -*- coding: utf-8 -*-
2 r"""Some minimal compatibility between Python2 and Python3 2 r"""Some minimal compatibility between Python2 and Python3
3 3
4 """ 4 """
5 5
6 from __future__ import division, absolute_import, print_function
7
6 import sys 8 import sys
9 import locale
7 10
8 11
9 __all__ = [] 12 __all__ = ["PY2",
13 "text_to_native_os_str",
14 "native_os_str_to_text"]
10 15
11 16
12 PY2 = sys.version_info[0] <= 2 17 PY2 = sys.version_info[0] <= 2
18
19
20 if PY2:
21
22 _OS_ENCODING = locale.getpreferredencoding()
23
24 def text_to_native_os_str(s, encoding=None):
25 if isinstance(s, unicode):
26 return s.encode(encoding or _OS_ENCODING)
27 else:
28 return s
29
30
31 def native_os_str_to_text(s, encoding=None):
32 return s.decode(encoding or _OS_ENCODING)
33
34 else:
35
36 def text_to_native_os_str(s, encoding=None):
37 return s
38
39
40 def native_os_str_to_text(s, encoding=None):
41 return s