當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。