11import ctypes , ctypes .util , operator , sys
22from . import model
33
4- if sys .version_info < (3 ,):
5- bytechr = chr
6- else :
7- unicode = str
8- long = int
9- xrange = range
10- bytechr = lambda num : bytes ([num ])
11-
124class CTypesType (type ):
135 pass
146
@@ -161,7 +153,7 @@ def _newp(cls, init):
161153 return cls (init )
162154
163155 def __iter__ (self ):
164- for i in xrange (len (self )):
156+ for i in range (len (self )):
165157 yield self [i ]
166158
167159 def _get_own_repr (self ):
@@ -183,7 +175,7 @@ def _cast_from(cls, source):
183175 address = 0
184176 elif isinstance (source , CTypesData ):
185177 address = source ._cast_to_integer ()
186- elif isinstance (source , ( int , long ) ):
178+ elif isinstance (source , int ):
187179 address = source
188180 else :
189181 raise TypeError ("bad type for cast to %r: %r" %
@@ -399,7 +391,7 @@ def __int__(self):
399391 if kind == 'bool' :
400392 @classmethod
401393 def _cast_from (cls , source ):
402- if not isinstance (source , (int , long , float )):
394+ if not isinstance (source , (int , float )):
403395 source = _cast_source_to_int (source )
404396 return cls (bool (source ))
405397 def __int__ (self ):
@@ -409,7 +401,7 @@ def __int__(self):
409401 @classmethod
410402 def _cast_from (cls , source ):
411403 source = _cast_source_to_int (source )
412- source = bytechr ( source & 0xFF )
404+ source = bytes ([ source & 0xFF ] )
413405 return cls (source )
414406 def __int__ (self ):
415407 return ord (self ._value )
@@ -438,7 +430,7 @@ def __float__(self):
438430 if kind == 'int' or kind == 'byte' or kind == 'bool' :
439431 @staticmethod
440432 def _to_ctypes (x ):
441- if not isinstance (x , ( int , long ) ):
433+ if not isinstance (x , int ):
442434 if isinstance (x , CTypesData ):
443435 x = int (x )
444436 else :
@@ -471,7 +463,7 @@ def __nonzero__(self):
471463 if kind == 'float' :
472464 @staticmethod
473465 def _to_ctypes (x ):
474- if not isinstance (x , (int , long , float , CTypesData )):
466+ if not isinstance (x , (int , float , CTypesData )):
475467 raise TypeError ("float expected, got %s" %
476468 type (x ).__name__ )
477469 return ctype (x ).value
@@ -535,14 +527,14 @@ def __init__(self, init):
535527 self ._own = True
536528
537529 def __add__ (self , other ):
538- if isinstance (other , ( int , long ) ):
530+ if isinstance (other , int ):
539531 return self ._new_pointer_at (self ._address +
540532 other * self ._bitem_size )
541533 else :
542534 return NotImplemented
543535
544536 def __sub__ (self , other ):
545- if isinstance (other , ( int , long ) ):
537+ if isinstance (other , int ):
546538 return self ._new_pointer_at (self ._address -
547539 other * self ._bitem_size )
548540 elif type (self ) is type (other ):
@@ -617,7 +609,7 @@ class CTypesArray(CTypesGenericArray):
617609
618610 def __init__ (self , init ):
619611 if length is None :
620- if isinstance (init , ( int , long ) ):
612+ if isinstance (init , int ):
621613 len1 = init
622614 init = None
623615 elif kind == 'char' and isinstance (init , bytes ):
@@ -696,7 +688,7 @@ def _arg_to_ctypes(value):
696688 return CTypesPtr ._arg_to_ctypes (value )
697689
698690 def __add__ (self , other ):
699- if isinstance (other , ( int , long ) ):
691+ if isinstance (other , long ):
700692 return CTypesPtr ._new_pointer_at (
701693 ctypes .addressof (self ._blob ) +
702694 other * ctypes .sizeof (BItem ._ctype ))
@@ -776,7 +768,7 @@ def initialize(blob, init):
776768 "only one supported (use a dict if needed)"
777769 % (len (init ),))
778770 if not isinstance (init , dict ):
779- if isinstance (init , (bytes , unicode )):
771+ if isinstance (init , (bytes , str )):
780772 raise TypeError ("union initializer: got a str" )
781773 init = tuple (init )
782774 if len (init ) > len (fnames ):
@@ -1061,7 +1053,7 @@ def typeoffsetof(self, BType, fieldname, num=0):
10611053 if BField is Ellipsis :
10621054 raise TypeError ("not supported for bitfields" )
10631055 return (BField , BType ._offsetof (fieldname ))
1064- elif isinstance (fieldname , ( int , long ) ):
1056+ elif isinstance (fieldname , int ):
10651057 if issubclass (BType , CTypesGenericArray ):
10661058 BType = BType ._CTPtr
10671059 if not issubclass (BType , CTypesGenericPtr ):
0 commit comments