本文整理匯總了Python中ctypes._SimpleCData方法的典型用法代碼示例。如果您正苦於以下問題:Python ctypes._SimpleCData方法的具體用法?Python ctypes._SimpleCData怎麽用?Python ctypes._SimpleCData使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類ctypes
的用法示例。
在下文中一共展示了ctypes._SimpleCData方法的5個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。
示例1: synchronized
# 需要導入模塊: import ctypes [as 別名]
# 或者: from ctypes import _SimpleCData [as 別名]
def synchronized(obj, lock=None):
assert not isinstance(obj, SynchronizedBase), 'object already synchronized'
if isinstance(obj, ctypes._SimpleCData):
return Synchronized(obj, lock)
elif isinstance(obj, ctypes.Array):
if obj._type_ is ctypes.c_char:
return SynchronizedString(obj, lock)
return SynchronizedArray(obj, lock)
else:
cls = type(obj)
try:
scls = class_cache[cls]
except KeyError:
names = [field[0] for field in cls._fields_]
d = dict((name, make_property(name)) for name in names)
classname = 'Synchronized' + cls.__name__
scls = class_cache[cls] = type(classname, (SynchronizedBase,), d)
return scls(obj, lock)
#
# Functions for pickling/unpickling
#
示例2: synchronized
# 需要導入模塊: import ctypes [as 別名]
# 或者: from ctypes import _SimpleCData [as 別名]
def synchronized(obj, lock=None, ctx=None):
assert not isinstance(obj, SynchronizedBase), 'object already synchronized'
ctx = ctx or get_context()
if isinstance(obj, ctypes._SimpleCData):
return Synchronized(obj, lock, ctx)
elif isinstance(obj, ctypes.Array):
if obj._type_ is ctypes.c_char:
return SynchronizedString(obj, lock, ctx)
return SynchronizedArray(obj, lock, ctx)
else:
cls = type(obj)
try:
scls = class_cache[cls]
except KeyError:
names = [field[0] for field in cls._fields_]
d = dict((name, make_property(name)) for name in names)
classname = 'Synchronized' + cls.__name__
scls = class_cache[cls] = type(classname, (SynchronizedBase,), d)
return scls(obj, lock, ctx)
#
# Functions for pickling/unpickling
#
示例3: synchronized
# 需要導入模塊: import ctypes [as 別名]
# 或者: from ctypes import _SimpleCData [as 別名]
def synchronized(obj, lock=None, ctx=None):
assert not isinstance(obj, SynchronizedBase), 'object already synchronized'
ctx = ctx or get_context()
if isinstance(obj, ctypes._SimpleCData):
return Synchronized(obj, lock, ctx)
elif isinstance(obj, ctypes.Array):
if obj._type_ is ctypes.c_char:
return SynchronizedString(obj, lock, ctx)
return SynchronizedArray(obj, lock, ctx)
else:
cls = type(obj)
try:
scls = class_cache[cls]
except KeyError:
names = [field[0] for field in cls._fields_]
d = {name: make_property(name) for name in names}
classname = 'Synchronized' + cls.__name__
scls = class_cache[cls] = type(classname, (SynchronizedBase,), d)
return scls(obj, lock, ctx)
#
# Functions for pickling/unpickling
#
示例4: enumerate_winstructs
# 需要導入模塊: import ctypes [as 別名]
# 或者: from ctypes import _SimpleCData [as 別名]
def enumerate_winstructs(self):
for obj in vars(windows.generated_def.winstructs):
instance = eval("windows.generated_def.winstructs." + obj)
if hasattr(instance, '__bases__'):
if instance.__bases__[0] is Structure or instance.__bases__[0] is Union or hasattr(instance, '_fields_'):
self.structures[obj] = {}
self.structures[obj]['type'] = instance.__bases__[0].__name__
self.structures[obj]['fields'] = self.get_fields(instance)
elif instance.__bases__[0] is windows.generated_def.winstructs.EnumType:
self.enums[obj] = {}
enum_values = []
for value in instance.values:
enum_values.append({'name': value.name, 'real': value.real})
self.enums[obj]['values'] = enum_values
elif instance.__bases__[0] is _Pointer:
self.pointers[obj] = {}
self.pointers[obj]['type_name'] = instance._type_.__name__
elif instance.__bases__[0] is _SimpleCData:
continue
elif instance.__bases__[0] is CDLL:
continue
elif instance.__bases__[0] is object:
continue
elif instance.__bases__[0] is dict:
continue
elif instance.__bases__[0] is c_ulong:
continue
elif instance.__bases__[0] is Exception:
continue
else:
if self.debug_level > 0:
self.dump_object(obj, instance)
示例5: test_itemsize
# 需要導入模塊: import ctypes [as 別名]
# 或者: from ctypes import _SimpleCData [as 別名]
def test_itemsize(self):
for size in [1, 2, 4, 8]:
a = Array((1,), 'i', size)
ct = a._ctype
self.assertTrue(issubclass(ct, ctypes._SimpleCData))
self.assertEqual(sizeof(ct), size)