8484def namespace_handler (ns ):
8585 return ns
8686
87-
88- try :
89- unicode = unicode
90- except NameError :
91- # 'unicode' is undefined, must be Python 3
92- str = str
93- unicode = str
94- bytes = bytes
95- basestring = (str , bytes )
96- else :
97- # 'unicode' exists, must be Python 2
98- str = str
99- unicode = unicode
100- bytes = str
101- basestring = basestring
102-
103-
10487def augment_arg_names (method ):
10588 """replaces missing arg_names with "in_%d" % i, where i is the position
10689 number of the arg"""
@@ -1276,7 +1259,7 @@ def _create_wrapper_for_attribute(self, attribute):
12761259 )
12771260 indented = Code ()
12781261
1279- if isinstance (cleanup , basestring ):
1262+ if isinstance (cleanup , ( str , bytes ) ):
12801263 cleanup = " %s" % cleanup
12811264
12821265 indented .add (cleanup )
@@ -1288,10 +1271,10 @@ def _create_wrapper_for_attribute(self, attribute):
12881271
12891272 cy_type = self .cr .cython_type (t )
12901273
1291- if isinstance (to_py_code , basestring ):
1274+ if isinstance (to_py_code , ( str , bytes ) ):
12921275 to_py_code = " %s" % to_py_code
12931276
1294- if isinstance (access_stmt , basestring ):
1277+ if isinstance (access_stmt , ( str , bytes ) ):
12951278 access_stmt = " %s" % access_stmt
12961279
12971280 if t .is_ptr :
@@ -1360,7 +1343,7 @@ def create_wrapper_for_nonoverloaded_method(self, cdcl, py_name, method):
13601343 else :
13611344 indented = meth_code
13621345
1363- if isinstance (full_call_stmt , basestring ):
1346+ if isinstance (full_call_stmt , ( str , bytes ) ):
13641347 indented .add (
13651348 """
13661349 | $full_call_stmt
@@ -1373,14 +1356,14 @@ def create_wrapper_for_nonoverloaded_method(self, cdcl, py_name, method):
13731356 for cleanup in reversed (cleanups ):
13741357 if not cleanup :
13751358 continue
1376- if isinstance (cleanup , basestring ):
1359+ if isinstance (cleanup , ( str , bytes ) ):
13771360 cleanup = " %s" % cleanup
13781361 indented .add (cleanup )
13791362
13801363 to_py_code = out_converter .output_conversion (res_t , "_r" , "py_result" )
13811364
13821365 if to_py_code is not None : # for non void return value
1383- if isinstance (to_py_code , basestring ):
1366+ if isinstance (to_py_code , ( str , bytes ) ):
13841367 to_py_code = " %s" % to_py_code
13851368 indented .add (to_py_code )
13861369 indented .add (" return py_result" )
@@ -1455,7 +1438,7 @@ def _create_wrapper_for_free_function(
14551438 out_converter = self .cr .get (res_t )
14561439 full_call_stmt = out_converter .call_method (res_t , cy_call_str )
14571440
1458- if isinstance (full_call_stmt , basestring ):
1441+ if isinstance (full_call_stmt , ( str , bytes ) ):
14591442 fun_code .add (
14601443 """
14611444 | $full_call_stmt
@@ -1468,15 +1451,15 @@ def _create_wrapper_for_free_function(
14681451 for cleanup in reversed (cleanups ):
14691452 if not cleanup :
14701453 continue
1471- if isinstance (cleanup , basestring ):
1454+ if isinstance (cleanup , ( str , bytes ) ):
14721455 cleanup = " %s" % cleanup
14731456 fun_code .add (cleanup )
14741457
14751458 to_py_code = out_converter .output_conversion (res_t , "_r" , "py_result" )
14761459
14771460 out_vars = ["py_result" ]
14781461 if to_py_code is not None : # for non void return value
1479- if isinstance (to_py_code , basestring ):
1462+ if isinstance (to_py_code , ( str , bytes ) ):
14801463 to_py_code = " %s" % to_py_code
14811464 fun_code .add (to_py_code )
14821465 fun_code .add (" return %s" % (", " .join (out_vars )))
@@ -1573,7 +1556,7 @@ def create_wrapper_for_nonoverloaded_constructor(self, class_decl, py_name, cons
15731556 for cleanup in reversed (cleanups ):
15741557 if not cleanup :
15751558 continue
1576- if isinstance (cleanup , basestring ):
1559+ if isinstance (cleanup , ( str , bytes ) ):
15771560 cleanup = " %s" % cleanup
15781561 cons_code .add (cleanup )
15791562
@@ -1699,7 +1682,7 @@ def create_special_getitem_method(self, mdcl):
16991682 out_converter = self .cr .get (res_t )
17001683 full_call_stmt = out_converter .call_method (res_t , cy_call_str )
17011684
1702- if isinstance (full_call_stmt , basestring ):
1685+ if isinstance (full_call_stmt , ( str , bytes ) ):
17031686 meth_code .add (
17041687 """
17051688 | $full_call_stmt
@@ -1712,14 +1695,14 @@ def create_special_getitem_method(self, mdcl):
17121695 for cleanup in reversed (cleanups ):
17131696 if not cleanup :
17141697 continue
1715- if isinstance (cleanup , basestring ):
1698+ if isinstance (cleanup , ( str , bytes ) ):
17161699 cleanup = Code ().add (cleanup )
17171700 meth_code .add (cleanup )
17181701
17191702 out_var = "py_result"
17201703 to_py_code = out_converter .output_conversion (res_t , "_r" , out_var )
17211704 if to_py_code is not None : # for non void return value
1722- if isinstance (to_py_code , basestring ):
1705+ if isinstance (to_py_code , ( str , bytes ) ):
17231706 to_py_code = " %s" % to_py_code
17241707 meth_code .add (to_py_code )
17251708 meth_code .add (" return $out_var" , locals ())
@@ -1827,7 +1810,7 @@ def create_cast_methods(self, mdecls):
18271810 call_stmt = "<%s>(deref(self.inst.get()))" % cy_t
18281811 full_call_stmt = out_converter .call_method (res_t , call_stmt )
18291812
1830- if isinstance (full_call_stmt , basestring ):
1813+ if isinstance (full_call_stmt , ( str , bytes ) ):
18311814 code .add (
18321815 """
18331816 | $full_call_stmt
@@ -1838,7 +1821,7 @@ def create_cast_methods(self, mdecls):
18381821 code .add (full_call_stmt )
18391822
18401823 to_py_code = out_converter .output_conversion (res_t , "_r" , "py_res" )
1841- if isinstance (to_py_code , basestring ):
1824+ if isinstance (to_py_code , ( str , bytes ) ):
18421825 to_py_code = " %s" % to_py_code
18431826 code .add (to_py_code )
18441827 code .add (""" return py_res""" )
0 commit comments