2828# ==============================================================================
2929# Data types
3030# ==============================================================================
31- if PY2 :
32- # Python 2
33- TEXT_TYPES = (str , unicode )
34- INT_TYPES = (int , long )
35- else :
31+ if True :
3632 # Python 3
3733 TEXT_TYPES = (str ,)
3834 INT_TYPES = (int ,)
4238# ==============================================================================
4339# Renamed/Reorganized modules
4440# ==============================================================================
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 :
6842 # Python 3
6943 import builtins
7044 import configparser
8559# ==============================================================================
8660# Strings
8761# ==============================================================================
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 :
9863 # Python 3
9964 def u (obj ):
10065 """Return string as it is"""
@@ -104,20 +69,14 @@ def u(obj):
10469def is_text_string (obj ):
10570 """Return True if `obj` is a text string, False if it is anything else,
10671 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 :
11173 # Python 3
11274 return isinstance (obj , str )
11375
11476
11577def is_binary_string (obj ):
11678 """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 :
12180 # Python 3
12281 return isinstance (obj , bytes )
12382
@@ -130,23 +89,14 @@ def is_string(obj):
13089
13190def is_unicode (obj ):
13291 """Return True if `obj` is unicode"""
133- if PY2 :
134- # Python 2
135- return isinstance (obj , unicode )
136- else :
92+ if True :
13793 # Python 3
13894 return isinstance (obj , str )
13995
14096
14197def to_text_string (obj , encoding = None ):
14298 """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 :
150100 # Python 3
151101 if encoding is None :
152102 return str (obj )
@@ -159,13 +109,7 @@ def to_text_string(obj, encoding=None):
159109
160110def to_binary_string (obj , encoding = None ):
161111 """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 :
169113 # Python 3
170114 return bytes (
171115 obj , 'utf-8' if encoding is None else encoding
@@ -177,30 +121,21 @@ def to_binary_string(obj, encoding=None):
177121# ==============================================================================
178122def get_func_code (func ):
179123 """Return function code object"""
180- if PY2 :
181- # Python 2
182- return func .func_code
183- else :
124+ if True :
184125 # Python 3
185126 return func .__code__
186127
187128
188129def get_func_name (func ):
189130 """Return function name"""
190- if PY2 :
191- # Python 2
192- return func .func_name
193- else :
131+ if True :
194132 # Python 3
195133 return func .__name__
196134
197135
198136def get_func_defaults (func ):
199137 """Return function default argument values"""
200- if PY2 :
201- # Python 2
202- return func .func_defaults
203- else :
138+ if True :
204139 # Python 3
205140 return func .__defaults__
206141
@@ -210,47 +145,29 @@ def get_func_defaults(func):
210145# ==============================================================================
211146def get_meth_func (obj ):
212147 """Return method function object"""
213- if PY2 :
214- # Python 2
215- return obj .im_func
216- else :
148+ if True :
217149 # Python 3
218150 return obj .__func__
219151
220152
221153def get_meth_class_inst (obj ):
222154 """Return method class instance"""
223- if PY2 :
224- # Python 2
225- return obj .im_self
226- else :
155+ if True :
227156 # Python 3
228157 return obj .__self__
229158
230159
231160def get_meth_class (obj ):
232161 """Return method class"""
233- if PY2 :
234- # Python 2
235- return obj .im_class
236- else :
162+ if True :
237163 # Python 3
238164 return obj .__self__ .__class__
239165
240166
241167# ==============================================================================
242168# Misc.
243169# ==============================================================================
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 :
254171 # Python 3
255172 input = input
256173 getcwd = os .getcwd
0 commit comments