当前位置: 首页>>代码示例>>Python>>正文


Python ctypes.string_at方法代码示例

本文整理汇总了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 
开发者ID:jtolio,项目名称:leveldb-py,代码行数:23,代码来源:leveldb.py

示例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 
开发者ID:unode,项目名称:firefox_decrypt,代码行数:21,代码来源:firefox_decrypt.py

示例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) 
开发者ID:adafruit,项目名称:Adafruit_Python_PureIO,代码行数:21,代码来源:spi.py

示例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) 
开发者ID:fake-name,项目名称:ReadableWebProxy,代码行数:22,代码来源:server.py

示例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) 
开发者ID:thortex,项目名称:rpi3-webiopi,代码行数:26,代码来源:spi.py

示例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 
开发者ID:wbond,项目名称:oscrypto,代码行数:8,代码来源:_ffi.py

示例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) 
开发者ID:wbond,项目名称:oscrypto,代码行数:10,代码来源:_ffi.py

示例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)) 
开发者ID:wbond,项目名称:oscrypto,代码行数:4,代码来源:_ffi.py

示例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) 
开发者ID:wbond,项目名称:oscrypto,代码行数:16,代码来源:_core_foundation_ctypes.py

示例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) 
开发者ID:jtolio,项目名称:leveldb-py,代码行数:7,代码来源:leveldb.py

示例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) 
开发者ID:jtolio,项目名称:leveldb-py,代码行数:7,代码来源:leveldb.py

示例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) 
开发者ID:jtolio,项目名称:leveldb-py,代码行数:7,代码来源:leveldb.py

示例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 
开发者ID:Wyliodrin,项目名称:pybass,代码行数:17,代码来源:pybass.py

示例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 
开发者ID:Wyliodrin,项目名称:pybass,代码行数:15,代码来源:pybass.py

示例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 
开发者ID:Wyliodrin,项目名称:pybass,代码行数:16,代码来源:pybass.py


注:本文中的ctypes.string_at方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。