Skip to content

Commit 122b03c

Browse files
committed
Simplify compat module by always treating Python 3 as normal case
1 parent 69ad845 commit 122b03c

File tree

2 files changed

+6
-43
lines changed

2 files changed

+6
-43
lines changed

radish/compat.py

Lines changed: 6 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -1,41 +1,19 @@
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

99
try:
1010
from io import StringIO
1111
except 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

4119
def 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

radish/exceptions.py

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -13,13 +13,6 @@ class RadishError(Exception):
1313
pass
1414

1515

16-
class PythonCompatibilityError(RadishError):
17-
"""
18-
Raised if python compatibility is not possible
19-
"""
20-
pass
21-
22-
2316
class LanguageNotSupportedError(RadishError):
2417
"""
2518
Raised if the language could not be found.

0 commit comments

Comments
 (0)