Author: Amaury Forgeot d'Arc <[email protected]>
Branch: py3k
Changeset: r58757:48df97e8ce7a
Date: 2012-10-28 19:44 +0100
http://bitbucket.org/pypy/pypy/changeset/48df97e8ce7a/
Log: py3k-ify the _ctypes module
diff --git a/lib_pypy/_ctypes/array.py b/lib_pypy/_ctypes/array.py
--- a/lib_pypy/_ctypes/array.py
+++ b/lib_pypy/_ctypes/array.py
@@ -143,13 +143,12 @@
l = [self[i] for i in range(start, stop, step)]
letter = getattr(self._type_, '_type_', None)
if letter == 'c':
+ return b"".join(l)
+ if letter == 'u':
return "".join(l)
- if letter == 'u':
- return u"".join(l)
return l
-class Array(_CData):
- __metaclass__ = ArrayMeta
+class Array(_CData, metaclass=ArrayMeta):
_ffiargshape = 'P'
def __init__(self, *args):
diff --git a/lib_pypy/_ctypes/basics.py b/lib_pypy/_ctypes/basics.py
--- a/lib_pypy/_ctypes/basics.py
+++ b/lib_pypy/_ctypes/basics.py
@@ -105,10 +105,9 @@
def __ne__(self, other):
return self._obj != other
-class _CData(object):
+class _CData(object, metaclass=_CDataMeta):
""" The most basic object for all ctypes types
"""
- __metaclass__ = _CDataMeta
_objects = None
_ffiargtype = None
diff --git a/lib_pypy/_ctypes/function.py b/lib_pypy/_ctypes/function.py
--- a/lib_pypy/_ctypes/function.py
+++ b/lib_pypy/_ctypes/function.py
@@ -59,8 +59,7 @@
from_address = cdata_from_address
-class CFuncPtr(_CData):
- __metaclass__ = CFuncPtrType
+class CFuncPtr(_CData, metaclass=CFuncPtrType):
_argtypes_ = None
_restype_ = None
@@ -214,7 +213,7 @@
argument = argsl.pop(0)
# Direct construction from raw address
- if isinstance(argument, (int, long)) and not argsl:
+ if isinstance(argument, int) and not argsl:
self._set_address(argument)
restype = self._restype_
if restype is None:
@@ -255,7 +254,7 @@
return
# A COM function call, by index
- if (sys.platform == 'win32' and isinstance(argument, (int, long))
+ if (sys.platform == 'win32' and isinstance(argument, int)
and argsl):
ffiargs, ffires = self._ffishapes(self._argtypes_, self._restype_)
self._com_index = argument + 0x1000
@@ -301,7 +300,7 @@
try:
newargs = self._convert_args_for_callback(argtypes, args)
- except (UnicodeError, TypeError, ValueError), e:
+ except (UnicodeError, TypeError, ValueError) as e:
raise ArgumentError(str(e))
try:
res = self.callable(*newargs)
@@ -468,7 +467,7 @@
cobj = c_wchar_p(arg)
elif arg is None:
cobj = c_void_p()
- elif isinstance(arg, (int, long)):
+ elif isinstance(arg, long):
cobj = c_int(arg)
else:
raise TypeError("Don't know how to handle %s" % (arg,))
@@ -559,7 +558,7 @@
else:
try:
keepalive, newarg, newargtype = self._conv_param(argtype,
args[i])
- except (UnicodeError, TypeError, ValueError), e:
+ except (UnicodeError, TypeError, ValueError) as e:
raise ArgumentError(str(e))
keepalives.append(keepalive)
newargs.append(newarg)
@@ -571,7 +570,7 @@
for i, arg in enumerate(extra):
try:
keepalive, newarg, newargtype = self._conv_param(None, arg)
- except (UnicodeError, TypeError, ValueError), e:
+ except (UnicodeError, TypeError, ValueError) as e:
raise ArgumentError(str(e))
keepalives.append(keepalive)
newargs.append(newarg)
diff --git a/lib_pypy/_ctypes/pointer.py b/lib_pypy/_ctypes/pointer.py
--- a/lib_pypy/_ctypes/pointer.py
+++ b/lib_pypy/_ctypes/pointer.py
@@ -74,8 +74,7 @@
from_address = cdata_from_address
-class _Pointer(_CData):
- __metaclass__ = PointerType
+class _Pointer(_CData, metaclass=PointerType):
def getcontents(self):
addr = self._buffer[0]
diff --git a/lib_pypy/_ctypes/primitive.py b/lib_pypy/_ctypes/primitive.py
--- a/lib_pypy/_ctypes/primitive.py
+++ b/lib_pypy/_ctypes/primitive.py
@@ -308,8 +308,7 @@
def _is_pointer_like(self):
return self._type_ in "sPzUZXO"
-class _SimpleCData(_CData):
- __metaclass__ = SimpleType
+class _SimpleCData(_CData, metaclass=SimpleType):
_type_ = 'i'
def __init__(self, value=DEFAULT_VALUE):
diff --git a/lib_pypy/_ctypes/structure.py b/lib_pypy/_ctypes/structure.py
--- a/lib_pypy/_ctypes/structure.py
+++ b/lib_pypy/_ctypes/structure.py
@@ -191,7 +191,7 @@
if isinstance(value, tuple):
try:
value = self(*value)
- except Exception, e:
+ except Exception as e:
# XXX CPython does not even respect the exception type
raise RuntimeError("(%s) %s: %s" % (self.__name__, type(e), e))
return _CDataMeta.from_param(self, value)
@@ -211,8 +211,7 @@
res.__dict__['_index'] = -1
return res
-class StructOrUnion(_CData):
- __metaclass__ = StructOrUnionMeta
+class StructOrUnion(_CData, metaclass=StructOrUnionMeta):
def __new__(cls, *args, **kwds):
self = super(_CData, cls).__new__(cls, *args, **kwds)
@@ -254,5 +253,5 @@
class StructureMeta(StructOrUnionMeta):
_is_union = False
-class Structure(StructOrUnion):
- __metaclass__ = StructureMeta
+class Structure(StructOrUnion, metaclass=StructureMeta):
+ pass
diff --git a/lib_pypy/_ctypes/union.py b/lib_pypy/_ctypes/union.py
--- a/lib_pypy/_ctypes/union.py
+++ b/lib_pypy/_ctypes/union.py
@@ -3,5 +3,5 @@
class UnionMeta(structure.StructOrUnionMeta):
_is_union = True
-class Union(structure.StructOrUnion):
- __metaclass__ = UnionMeta
+class Union(structure.StructOrUnion, metaclass=UnionMeta):
+ pass
_______________________________________________
pypy-commit mailing list
[email protected]
http://mail.python.org/mailman/listinfo/pypy-commit