comparison configmix/compat.py @ 207:b3b5ed34d180

Handle most flake8 errors and warnings. NOTE: E265 "block comment should start with '# ' ist not yet handled. We would need to adjust our Python style.
author Franz Glasner <fzglas.hg@dom66.de>
date Sun, 05 May 2019 18:29:47 +0200
parents b5ce9a8461bf
children bbe8513ea649
comparison
equal deleted inserted replaced
206:5064e3a2e54a 207:b3b5ed34d180
7 7
8 """ 8 """
9 9
10 from __future__ import division, absolute_import, print_function 10 from __future__ import division, absolute_import, print_function
11 11
12 import sys
13 import os
14 import locale
15
16
17 __all__ = ["PY2", 12 __all__ = ["PY2",
18 "text_to_native_os_str", 13 "text_to_native_os_str",
19 "native_os_str_to_text", 14 "native_os_str_to_text",
20 "u", 15 "u",
21 "u2fs"] 16 "u2fs"]
17
18
19 import sys
20 import os
21 import locale
22 22
23 23
24 PY2 = sys.version_info[0] <= 2 24 PY2 = sys.version_info[0] <= 2
25 25
26 26
30 30
31 _FS_ENCODING = sys.getfilesystemencoding() or _OS_ENCODING 31 _FS_ENCODING = sys.getfilesystemencoding() or _OS_ENCODING
32 32
33 33
34 def text_to_native_os_str(s, encoding=None): 34 def text_to_native_os_str(s, encoding=None):
35 if isinstance(s, unicode): 35 if isinstance(s, unicode): # noqa: F821
36 return s.encode(encoding or _OS_ENCODING) 36 return s.encode(encoding or _OS_ENCODING)
37 else: 37 else:
38 return s 38 return s
39 39
40 40
41 def native_os_str_to_text(s, encoding=None): 41 def native_os_str_to_text(s, encoding=None):
42 return s.decode(encoding or _OS_ENCODING) 42 return s.decode(encoding or _OS_ENCODING)
43 43
44 44
45 def u(s, encoding="utf-8"): 45 def u(s, encoding="utf-8"):
46 if isinstance(s, unicode): 46 if isinstance(s, unicode): # noqa: F821
47 return s 47 return s
48 else: 48 else:
49 return s.decode(encoding) 49 return s.decode(encoding)
50 50
51 51