6098:a1d10c6ce103 | 6099:a7fecbc392d7 |
---|---|
1 """EditorConfig Python2/Python3 compatibility utilities""" | |
2 import sys | |
3 | |
4 __all__ = ['force_unicode', 'u'] | |
5 | |
6 | |
7 if sys.version_info[0] == 2: | |
8 text_type = unicode | |
9 else: | |
10 text_type = str | |
11 | |
12 | |
13 def force_unicode(string): | |
14 if not isinstance(string, text_type): | |
15 string = text_type(string, encoding='utf-8') | |
16 return string | |
17 | |
18 | |
19 if sys.version_info[0] == 2: | |
20 import codecs | |
21 u = lambda s: codecs.unicode_escape_decode(s)[0] | |
22 else: | |
23 u = lambda s: s |