28
28
# ==============================================================================
29
29
# Data types
30
30
# ==============================================================================
31
- if PY2 :
32
- # Python 2
33
- TEXT_TYPES = (str , unicode )
34
- INT_TYPES = (int , long )
35
- else :
31
+ if True :
36
32
# Python 3
37
33
TEXT_TYPES = (str ,)
38
34
INT_TYPES = (int ,)
42
38
# ==============================================================================
43
39
# Renamed/Reorganized modules
44
40
# ==============================================================================
45
- if PY2 :
46
- # Python 2
47
- import __builtin__ as builtins
48
- import ConfigParser as configparser
49
-
50
- try :
51
- import _winreg as winreg
52
- except ImportError :
53
- pass
54
- from sys import maxint as maxsize
55
-
56
- try :
57
- import CStringIO as io
58
- except ImportError :
59
- import StringIO as io
60
- try :
61
- import cPickle as pickle
62
- except ImportError :
63
- import pickle
64
- from UserDict import DictMixin as MutableMapping
65
- import thread as _thread
66
- import repr as reprlib
67
- else :
41
+ if True :
68
42
# Python 3
69
43
import builtins
70
44
import configparser
85
59
# ==============================================================================
86
60
# Strings
87
61
# ==============================================================================
88
- if PY2 :
89
- # Python 2
90
- import codecs
91
-
92
- def u (obj ):
93
- """Make unicode object"""
94
- return codecs .unicode_escape_decode (obj )[0 ]
95
-
96
-
97
- else :
62
+ if True :
98
63
# Python 3
99
64
def u (obj ):
100
65
"""Return string as it is"""
@@ -104,20 +69,14 @@ def u(obj):
104
69
def is_text_string (obj ):
105
70
"""Return True if `obj` is a text string, False if it is anything else,
106
71
like binary data (Python 3) or QString (Python 2, PyQt API #1)"""
107
- if PY2 :
108
- # Python 2
109
- return isinstance (obj , basestring )
110
- else :
72
+ if True :
111
73
# Python 3
112
74
return isinstance (obj , str )
113
75
114
76
115
77
def is_binary_string (obj ):
116
78
"""Return True if `obj` is a binary string, False if it is anything else"""
117
- if PY2 :
118
- # Python 2
119
- return isinstance (obj , str )
120
- else :
79
+ if True :
121
80
# Python 3
122
81
return isinstance (obj , bytes )
123
82
@@ -130,23 +89,14 @@ def is_string(obj):
130
89
131
90
def is_unicode (obj ):
132
91
"""Return True if `obj` is unicode"""
133
- if PY2 :
134
- # Python 2
135
- return isinstance (obj , unicode )
136
- else :
92
+ if True :
137
93
# Python 3
138
94
return isinstance (obj , str )
139
95
140
96
141
97
def to_text_string (obj , encoding = None ):
142
98
"""Convert `obj` to (unicode) text string"""
143
- if PY2 :
144
- # Python 2
145
- if encoding is None :
146
- return unicode (obj )
147
- else :
148
- return unicode (obj , encoding )
149
- else :
99
+ if True :
150
100
# Python 3
151
101
if encoding is None :
152
102
return str (obj )
@@ -159,13 +109,7 @@ def to_text_string(obj, encoding=None):
159
109
160
110
def to_binary_string (obj , encoding = None ):
161
111
"""Convert `obj` to binary string (bytes in Python 3, str in Python 2)"""
162
- if PY2 :
163
- # Python 2
164
- if encoding is None :
165
- return str (obj )
166
- else :
167
- return obj .encode (encoding )
168
- else :
112
+ if True :
169
113
# Python 3
170
114
return bytes (
171
115
obj , 'utf-8' if encoding is None else encoding
@@ -177,30 +121,21 @@ def to_binary_string(obj, encoding=None):
177
121
# ==============================================================================
178
122
def get_func_code (func ):
179
123
"""Return function code object"""
180
- if PY2 :
181
- # Python 2
182
- return func .func_code
183
- else :
124
+ if True :
184
125
# Python 3
185
126
return func .__code__
186
127
187
128
188
129
def get_func_name (func ):
189
130
"""Return function name"""
190
- if PY2 :
191
- # Python 2
192
- return func .func_name
193
- else :
131
+ if True :
194
132
# Python 3
195
133
return func .__name__
196
134
197
135
198
136
def get_func_defaults (func ):
199
137
"""Return function default argument values"""
200
- if PY2 :
201
- # Python 2
202
- return func .func_defaults
203
- else :
138
+ if True :
204
139
# Python 3
205
140
return func .__defaults__
206
141
@@ -210,47 +145,29 @@ def get_func_defaults(func):
210
145
# ==============================================================================
211
146
def get_meth_func (obj ):
212
147
"""Return method function object"""
213
- if PY2 :
214
- # Python 2
215
- return obj .im_func
216
- else :
148
+ if True :
217
149
# Python 3
218
150
return obj .__func__
219
151
220
152
221
153
def get_meth_class_inst (obj ):
222
154
"""Return method class instance"""
223
- if PY2 :
224
- # Python 2
225
- return obj .im_self
226
- else :
155
+ if True :
227
156
# Python 3
228
157
return obj .__self__
229
158
230
159
231
160
def get_meth_class (obj ):
232
161
"""Return method class"""
233
- if PY2 :
234
- # Python 2
235
- return obj .im_class
236
- else :
162
+ if True :
237
163
# Python 3
238
164
return obj .__self__ .__class__
239
165
240
166
241
167
# ==============================================================================
242
168
# Misc.
243
169
# ==============================================================================
244
- if PY2 :
245
- # Python 2
246
- input = raw_input
247
- getcwd = os .getcwdu
248
- cmp = cmp
249
- import string
250
-
251
- str_lower = string .lower
252
- from itertools import izip_longest as zip_longest
253
- else :
170
+ if True :
254
171
# Python 3
255
172
input = input
256
173
getcwd = os .getcwd
0 commit comments