11# -*- coding: utf-8 -*-
22
33"""
4- This module provide Oython 2 / Python 3 compatability
4+ This module provide Python 2 / Python 3 compatability
55"""
66
7- from sys import version_info
7+ import sys
88
99try :
1010 from io import StringIO
1111except ImportError :
1212 from StringIO import StringIO
1313
14- from .exceptions import PythonCompatibilityError
15-
1614
1715# flags to indicate Python versions
18- PY2 = None
19- """
20- Flag to indication CPython 2 compatibility, set to True when running CPython 2
21- False otherwise
22- """
23-
24- PY3 = None
25- """
26- Flag to indication CPython 2 compatibility, set to True when running CPython 3
27- False otherwise
28- """
29-
30- # check major version if 2 then set PY2 to True
31- if version_info [0 ] == 2 : # pragma: no cover
32- PY2 = True
33- # check major version if 3 then set PY3 to True
34- elif version_info [0 ] == 3 : # pragma: no cover
35- PY3 = True
36- else : # pragma: no cover
37- PY2 = False
38- PY3 = False
16+ PY2 = sys .version_info [0 ] == 2
3917
4018
4119def u (text ): # pragma: no cover
@@ -45,17 +23,9 @@ def u(text): # pragma: no cover
4523
4624 :param text: text to encode
4725 :type text: str,unicode
48-
49- :raises PythonCompatibilityError:
50- if unicode support is not handled by interpreter/version
5126 """
5227 # look for unicode in the builtins which only exists in python 2
5328 if PY2 is True :
54- unicode_text = unicode (text , "utf-8" )
55- elif PY3 is True :
56- unicode_text = text
57- else :
58- msg = "unicode support unhandled for this Python interpreter/version"
59- raise PythonCompatibilityError (msg )
60-
61- return unicode_text
29+ return unicode (text , "utf-8" )
30+
31+ return text
0 commit comments