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