本文整理汇总了Python中ctypes.string_at方法的典型用法代码示例。如果您正苦于以下问题:Python ctypes.string_at方法的具体用法?Python ctypes.string_at怎么用?Python ctypes.string_at使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类ctypes
的用法示例。
在下文中一共展示了ctypes.string_at方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: get
# 需要导入模块: import ctypes [as 别名]
# 或者: from ctypes import string_at [as 别名]
def get(self, key, verify_checksums=False, fill_cache=True):
error = ctypes.POINTER(ctypes.c_char)()
options = _ldb.leveldb_readoptions_create()
_ldb.leveldb_readoptions_set_verify_checksums(options,
verify_checksums)
_ldb.leveldb_readoptions_set_fill_cache(options, fill_cache)
if self._snapshot is not None:
_ldb.leveldb_readoptions_set_snapshot(options, self._snapshot.ref)
size = ctypes.c_size_t(0)
val_p = _ldb.leveldb_get(self._db.ref, options, key, len(key),
ctypes.byref(size), ctypes.byref(error))
if bool(val_p):
val = ctypes.string_at(val_p, size.value)
_ldb.leveldb_free(ctypes.cast(val_p, ctypes.c_void_p))
else:
val = None
_ldb.leveldb_readoptions_destroy(options)
_checkError(error)
return val
# pylint: disable=W0212
示例2: decode
# 需要导入模块: import ctypes [as 别名]
# 或者: from ctypes import string_at [as 别名]
def decode(self, data64):
data = b64decode(data64)
inp = self.SECItem(0, data, len(data))
out = self.SECItem(0, None, 0)
e = self._PK11SDR_Decrypt(inp, out, None)
LOG.debug("Decryption of data returned %s", e)
try:
if e == -1:
LOG.error("Password decryption failed. Passwords protected by a Master Password!")
self.handle_error()
raise Exit(Exit.NEED_MASTER_PASSWORD)
res = ct.string_at(out.data, out.len).decode(LIB_ENCODING)
finally:
# Avoid leaking SECItem
self._SECITEM_ZfreeItem(out, 0)
return res
示例3: readbytes
# 需要导入模块: import ctypes [as 别名]
# 或者: from ctypes import string_at [as 别名]
def readbytes(self, length, max_speed_hz=0, bits_per_word=0, delay=0):
"""Perform half-duplex SPI read as a binary string
"""
receive_buffer = create_string_buffer(length)
spi_ioc_transfer = struct.pack(
SPI._IOC_TRANSFER_FORMAT,
0,
addressof(receive_buffer),
length,
max_speed_hz,
delay,
bits_per_word,
0,
0,
0,
0,
)
ioctl(self.handle, SPI._IOC_MESSAGE, spi_ioc_transfer)
return string_at(receive_buffer, length)
示例4: main
# 需要导入模块: import ctypes [as 别名]
# 或者: from ctypes import string_at [as 别名]
def main():
print("Preloading cache directories")
# print("Testing reload")
# server.tree.tree.reloadTree()
# print("Starting RPC server")
try:
run()
except:
# abort /hard/ if we exceptioned out of the main run.
# This should (hopeully) cause the OS to terminate any
# remaining threads.
# As it is, I've been having issues with the main thread failing
# with 'OSError: [Errno 24] Too many open files', killing the main thread
# and leaving some of the amqp interface threads dangling.
# Somehow, it's not being caught in the `except Exception:` handler
# in run(). NFI how.
import ctypes
ctypes.string_at(0)
示例5: xfer
# 需要导入模块: import ctypes [as 别名]
# 或者: from ctypes import string_at [as 别名]
def xfer(self, txbuff=None):
length = len(txbuff)
if PYTHON_MAJOR >= 3:
_txbuff = bytes(txbuff)
_txptr = ctypes.create_string_buffer(_txbuff)
else:
_txbuff = str(bytearray(txbuff))
_txptr = ctypes.create_string_buffer(_txbuff)
_rxptr = ctypes.create_string_buffer(length)
data = struct.pack("QQLLHBBL", #64 64 32 32 16 8 8 32 b = 32B
ctypes.addressof(_txptr),
ctypes.addressof(_rxptr),
length,
self.speed,
0, #delay
self.bits,
0, # cs_change,
0 # pad
)
fcntl.ioctl(self.fd, SPI_IOC_MESSAGE(len(data)), data)
_rxbuff = ctypes.string_at(_rxptr, length)
return bytearray(_rxbuff)
示例6: bytes_from_buffer
# 需要导入模块: import ctypes [as 别名]
# 或者: from ctypes import string_at [as 别名]
def bytes_from_buffer(buffer, maxlen=None):
if isinstance(buffer, _pointer_int_types):
return ctypes.string_at(buffer, maxlen)
if maxlen is not None:
return buffer.raw[0:maxlen]
return buffer.raw
示例7: native
# 需要导入模块: import ctypes [as 别名]
# 或者: from ctypes import string_at [as 别名]
def native(type_, value):
if isinstance(value, type_):
return value
if sys.version_info < (3,) and type_ == int and isinstance(value, int_types):
return value
if isinstance(value, ctypes.Array) and value._type_ == ctypes.c_byte:
return ctypes.string_at(ctypes.addressof(value), value._length_)
return type_(value.value)
示例8: struct_bytes
# 需要导入模块: import ctypes [as 别名]
# 或者: from ctypes import string_at [as 别名]
def struct_bytes(struct_):
return ctypes.string_at(struct_, ctypes.sizeof(struct_.contents))
示例9: cf_data_to_bytes
# 需要导入模块: import ctypes [as 别名]
# 或者: from ctypes import string_at [as 别名]
def cf_data_to_bytes(value):
"""
Extracts a bytestring from a CFData object
:param value:
A CFData object
:return:
A byte string
"""
start = CoreFoundation.CFDataGetBytePtr(value)
num_bytes = CoreFoundation.CFDataGetLength(value)
return string_at(start, num_bytes)
示例10: _checkError
# 需要导入模块: import ctypes [as 别名]
# 或者: from ctypes import string_at [as 别名]
def _checkError(error):
if bool(error):
message = ctypes.string_at(error)
_ldb.leveldb_free(ctypes.cast(error, ctypes.c_void_p))
raise Error(message)
示例11: key
# 需要导入模块: import ctypes [as 别名]
# 或者: from ctypes import string_at [as 别名]
def key(self):
length = ctypes.c_size_t(0)
val_p = _ldb.leveldb_iter_key(self._ref.ref, ctypes.byref(length))
assert bool(val_p)
return ctypes.string_at(val_p, length.value)
示例12: val
# 需要导入模块: import ctypes [as 别名]
# 或者: from ctypes import string_at [as 别名]
def val(self):
length = ctypes.c_size_t(0)
val_p = _ldb.leveldb_iter_value(self._ref.ref, ctypes.byref(length))
assert bool(val_p)
return ctypes.string_at(val_p, length.value)
示例13: get_tags
# 需要导入模块: import ctypes [as 别名]
# 或者: from ctypes import string_at [as 别名]
def get_tags(handle, tags = BASS_TAG_OGG):
result = []
addr = BASS_ChannelGetTags(handle, tags)
res = b''
while isinstance(res, (str, bytes)):
res = ctypes.string_at(addr)
#if sys.hexversion >= 0x03000000:
#res = ctypes.wstring_at(addr)
addr += len(res) + 1
if res:
if 32 < bass_ord(res[0]) < 256:
result.append(res)
else:
res = None
return result
示例14: get_tags_as_list
# 需要导入模块: import ctypes [as 别名]
# 或者: from ctypes import string_at [as 别名]
def get_tags_as_list(handle, tags = BASS_TAG_OGG):
result_as_list = []
addr = BASS_ChannelGetTags(handle, tags)
str_tag = ''
while isinstance(str_tag, str):
str_tag = ctypes.string_at(addr)
addr += len(str_tag) + 1
if str_tag:
if 32 < bass_ord(str_tag[0]) < 256:
result_as_list.append(tuple(str_tag.split('=')))
else:
str_tag = None
return result_as_list
示例15: get_tags_as_dict
# 需要导入模块: import ctypes [as 别名]
# 或者: from ctypes import string_at [as 别名]
def get_tags_as_dict(handle, tags = BASS_TAG_OGG):
result_as_dict = {}
addr = BASS_ChannelGetTags(handle, tags)
str_tag = ''
while isinstance(str_tag, str):
str_tag = ctypes.string_at(addr)
addr += len(str_tag) + 1
if str_tag:
if 32 < bass_ord(str_tag[0]) < 256:
key, value = str_tag.split('=')
result_as_dict[key] = value
else:
str_tag = None
return result_as_dict