• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

Python umsgpack.unpackb函数代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了Python中umsgpack.unpackb函数的典型用法代码示例。如果您正苦于以下问题:Python unpackb函数的具体用法?Python unpackb怎么用?Python unpackb使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。



在下文中一共展示了unpackb函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Python代码示例。

示例1: test_unpack_exceptions

 def test_unpack_exceptions(self):
     for (name, data, exception) in unpack_exception_test_vectors:
         print("\tTesting %s" % name)
         try:
             umsgpack.unpackb(data)
         except Exception as e:
             self.assertTrue(isinstance(e, exception))
开发者ID:cforger,项目名称:u-msgpack-python,代码行数:7,代码来源:test_umsgpack.py


示例2: main

def main():
	# Switch to API Mode
	print ">> Configuring Xbee"
	time.sleep(1)
	ser_xbee.write("+++")				# enter command mode
	time.sleep(1)
	if (ser_xbee.read(3) == "OK\r"):
		print "AT  \tOK"
		ser_xbee.write("ATAP 1\r")					# switch to API mode
		print "ATAP\t%s" %ser_xbee.read(3)			# wait for reply
		ser_xbee.write("ATID %s\r" %XBEE_MESH_ID)	# mesh id
		print "ATID\t%s" %ser_xbee.read(3)			# wait for reply
		ser_xbee.write("ATCH %s\r" %XBEE_MESH_CH)	# mesh ch
		print "ATCH\t%s" %ser_xbee.read(3)			# wait for reply
		ser_xbee.write("ATWR\r")					# apply settings
		print "ATWR\t%s" %ser_xbee.read(3)			# wait for reply
		ser_xbee.write("ATAG %s\r" %XBEE_MESH_DL)	# apply settings
		print "ATAG\t%s" %ser_xbee.read(3)			# wait for reply
		ser_xbee.write("ATCN\r")					# exit command mode	
	else:
		print "AT  \tFAIL"

	# Configure Xbee
	#xbee.at(command="CE", parameter="0")			# router mode
	#xbee.at(command="ID", parameter=XBEE_MESH_ID)	# mesh id 
	#xbee.at(command="CH", parameter=XBEE_MESH_CH)	# mesh channel
	#xbee.at(command="WR")							# apply
	#xbee.at(command="AG", parameter=XBEE_MESH_DL)	# broadcast as master

	# Receive packets
	frames = {}							# buffer for storing unprocessed frames
	packet = ""							# buffer for placing string after processing
	packets = []						# all packets received
	while True:
		frame = xbee.wait_read_frame()		# wait for frames
		print frame["source_addr"]
		frame = unpackb(frame["data"])		# decode json
		pid   = frame["id"]					# get id
		pnum  = frame["pn"]					# get packet number
		pdata = frame["dt"]					# get data

		if not pid in frames:				# if new packet stream
			frames[pid] = {}				# initialize slot
		frames[pid][pnum] = pdata			# store data from frame
		#print frame

		if 0 in frames[pid]:				# if we already have the header
			if frames[pid][0] == len(frames[pid]):	# and we have all the frames
				for i in range(1, frames[pid][0]):	# join data from frames
					packet += frames[pid][i]
				frames[pid] = {}
				packet = unpackb(packet)
				timestamp = time.strftime("%H:%M:%S", time.localtime())
				print "Got packet from: %s at %s" %(packet["ant_mac"], timestamp)
				packets += (timestamp, packet)
				packet = ""
开发者ID:luisbc92,项目名称:antenna_listener,代码行数:56,代码来源:antenna_listener.py


示例3: aes_decrypt

def aes_decrypt(word, key=config.aes_key, iv=None):
    if iv is None:
        word, iv = umsgpack.unpackb(word)
    else:
        raise Exception('no iv error')

    aes = AES.new(key, AES.MODE_CBC, iv)
    word = aes.decrypt(word)

    return umsgpack.unpackb(word)
开发者ID:BulletTrain,项目名称:qiandao,代码行数:10,代码来源:mcrypto.py


示例4: aes_decrypt

def aes_decrypt(word, key=config.aes_key, iv=None):
    if iv is None:
        word, iv = umsgpack.unpackb(word)
    else:
        raise Exception('no iv error')

    aes = AES.new(key, AES.MODE_CBC, iv)
    word = aes.decrypt(word)

    while word:
        try:
            return umsgpack.unpackb(word)
        except umsgpack.ExtraData:
            word = word[:-1]
开发者ID:Crooky,项目名称:qiandao,代码行数:14,代码来源:mcrypto.py


示例5: keep_alive

    async def keep_alive(self):
        """
        This method is used to keep the server up and running when not connected to Scratch
        :return:
        """
        while True:

            # check for reporter messages
            try:
                [address, contents] = self.router_socket.recv_multipart(zmq.NOBLOCK)
                payload = umsgpack.unpackb(contents)
                # print("[%s] %s" % (address, payload))
                board_num = address.decode()
                board_num = board_num[1]
                command = payload['command']
                if command == 'problem':
                    data_string = command + '/' + board_num + ' ' + payload['problem']
                else:
                    pin = payload['pin']
                    value = payload['value']
                    data_string = command + '/' + board_num + '/' + pin + ' ' + value + '\n'
                # print(data_string)
                self.poll_reply += data_string

            except zmq.error.Again:
                pass
            await asyncio.sleep(.001)
开发者ID:MrYsLab,项目名称:xideco,代码行数:27,代码来源:xihbt.py


示例6: test_invalid_name

    def test_invalid_name(self):
        created = signal.create(self.btctxstore, self.wif, "test")

        # repack to eliminate namedtuples and simulate io
        repacked = umsgpack.unpackb(umsgpack.packb(created))

        self.assertIsNone(signal.read(self.btctxstore, repacked, "wrongname"))
开发者ID:bookchin,项目名称:storjnode,代码行数:7,代码来源:signal.py


示例7: receive_loop

 def receive_loop(self):
     """
     This is the receive loop for zmq messages
     It is assumed that this method may be overwritten to meet the needs of the application
     It returns payload via user provided callback method
     :return:
     """
     while True:
         try:
             data = self.subscriber.recv_multipart(zmq.NOBLOCK)
             self.incoming_message_processing(data[0].decode(), umsgpack.unpackb(data[1]))
             time.sleep(.001)
         except zmq.error.Again:
             try:
                 time.sleep(.001)
                 self.root.update()
             except KeyboardInterrupt:
                 self.root.destroy()
                 self.publisher.close()
                 self.subscriber.close()
                 self.context.term()
                 sys.exit(0)
         except KeyboardInterrupt:
             self.root.destroy()
             self.publisher.close()
             self.subscriber.close()
             self.context.term()
             sys.exit(0)
开发者ID:MrYsLab,项目名称:xideco,代码行数:28,代码来源:gui2.py


示例8: keep_alive

    async def keep_alive(self):
        """
        This method is used to keep the server up and running when not connected to Scratch
        :return:
        """
        while True:

            # check for reporter messages
            try:
                [address, contents] = self.subscriber.recv_multipart(zmq.NOBLOCK)
                payload = umsgpack.unpackb(contents)
                # print("[%s] %s" % (address, payload))
                board_num = address.decode()
                board_num = board_num[1]
                command = payload['command']
                # we will ignore any i2c_replies
                if command == 'i2c_reply' or command == 'i2c_request':
                    continue
                elif command == 'problem':
                    data_string = command + '/' + board_num + ' ' + payload['problem']
                else:
                    # noinspection PyPep8
                    if not 'pin' in payload:
                        continue
                    else:
                        pin = payload['pin']
                        value = payload['value']
                        data_string = command + '/' + board_num + '/' + pin + ' ' + value + '\n'
                    # print(data_string)
                self.poll_reply += data_string

            except zmq.error.Again:
                await asyncio.sleep(.001)
开发者ID:MrYsLab,项目名称:xideco,代码行数:33,代码来源:xihb.py


示例9: _load_cache_settings

    def _load_cache_settings(self):
        """Load settings from cache to self.cached_settings."""

        successful = _ensure_file(self.cache_file)

        if not successful:
            LOG.debug("Unable to load cache.")
            return

        with open(self.cache_file, "rb") as stream:
            LOG.debug("Opening subscription cache to retrieve subscriptions.")
            data = stream.read()

        if data == b"":
            LOG.debug("Received empty string from cache.")
            return False

        for encoded_sub in umsgpack.unpackb(data):
            try:
                decoded_sub = Subscription.Subscription.decode_subscription(encoded_sub)

            except Error.MalformedSubscriptionError as exception:
                LOG.debug("Encountered error in subscription decoding:")
                LOG.debug(exception)
                LOG.debug("Skipping this sub.")
                continue

            self.cache_map["by_name"][decoded_sub.name] = decoded_sub
            self.cache_map["by_url"][decoded_sub.original_url] = decoded_sub

        return True
开发者ID:andrewmichaud,项目名称:puckfetcher,代码行数:31,代码来源:config.py


示例10: get_current_user

 def get_current_user(self):
     ret = self.get_secure_cookie('user', max_age_days=config.cookie_days)
     if not ret:
         return ret
     user = umsgpack.unpackb(ret)
     user['isadmin'] = 'admin' in user['role'] if user['role'] else False
     return user
开发者ID:BulletTrain,项目名称:qiandao,代码行数:7,代码来源:base.py


示例11: test_invalid_peer_type

    def test_invalid_peer_type(self):
        created = base.create(self.btctxstore, self.wif, "peers", None)

        # repack to eliminate namedtuples and simulate io
        repacked = umsgpack.unpackb(umsgpack.packb(created))

        self.assertIsNone(peers.read(self.btctxstore, repacked))
开发者ID:bookchin,项目名称:storjnode,代码行数:7,代码来源:peers.py


示例12: process

 def process(self, message):
     datagram, host, port =  umsgpack.unpackb(message[0])
     reply = self.processAuth(datagram, host, port)
     logger.info("[Radiusd] :: Send radius response: %s" % repr(reply))
     if self.config.system.debug:
         logger.debug(reply.format_str())
     self.pusher.push(umsgpack.packb([reply.ReplyPacket(),host,port]))
开发者ID:niebaopeng,项目名称:ToughRADIUS,代码行数:7,代码来源:radiusd.py


示例13: get_next_message

    async def get_next_message(self):
        """
        This method uses an async future to retrieve the next message from the network.
        :return: If not message is available, None is returned, else the message is returned as a list containing
        the topic and payload.
        """
        # create an asyncio Future
        future = asyncio.Future()

        try:
            # get the next available message
            data = self.subscriber.recv_multipart(zmq.NOBLOCK)

            # get the topic and unpack the payload
            topic = data[0].decode()
            payload = umsgpack.unpackb(data[1])

            # place them into a list
            message = [topic, payload]

            # place the message in the future result
            future.set_result(message)

            # wait until the future reports that it is complete and then return the topic, payload list
            while not future.done():
                await asyncio.sleep(.01)
            return future.result()
        except zmq.error.Again:
            # if no message is available, zmq throws the Again exception, so just return None
            return None
开发者ID:MrYsLab,项目名称:xibot,代码行数:30,代码来源:xirb.py


示例14: test_40_with_rpc

 def test_40_with_rpc(self):
     data = dict(self.sample_task_http)
     data["url"] = "data:,hello"
     result = umsgpack.unpackb(self.rpc.fetch(data).data)
     self.assertEqual(result["status_code"], 200)
     self.assertIn("content", result)
     self.assertEqual(result["content"], "hello")
开发者ID:hemengsi123,项目名称:pyspider,代码行数:7,代码来源:test_fetcher.py


示例15: test_invalid_info_len

    def test_invalid_info_len(self):
        created = base.create(self.btctxstore, self.wif, "info", [])

        # repack to eliminate namedtuples and simulate io
        repacked = umsgpack.unpackb(umsgpack.packb(created))

        self.assertIsNone(info.read(self.btctxstore, repacked))
开发者ID:welfeng2016,项目名称:storjnode,代码行数:7,代码来源:info.py


示例16: run_bb_i2c_bridge

    def run_bb_i2c_bridge(self):
        """
        Start up the bridge
        :return:
        """
        # self.pi.set_mode(11, pigpio.INPUT)
        # cb1 = self.pi.callback(11, pigpio.EITHER_EDGE, self.cbf)
        while True:
            # noinspection PyBroadException
            try:
                z = self.subscriber.recv_multipart(zmq.NOBLOCK)
                self.payload = umsgpack.unpackb(z[1])
                # print("[%s] %s" % (z[0], self.payload))

                # print(self.payload)
                command = self.payload['command']
                if command == 'i2c_request':
                    self.i2c_request()
                else:
                    # print("can't execute unknown command'")
                    pass
                time.sleep(.0001)
            except KeyboardInterrupt:
                sys.exit(0)
            except zmq.error.Again:
                time.sleep(.0001)
开发者ID:MrYsLab,项目名称:xideco,代码行数:26,代码来源:xibbi2c.py


示例17: _decrypt_metadata

    async def _decrypt_metadata(self, encrypted_metadata, user_vault_key):
        import zipfile
        from io import BytesIO
        from syncrypt.pipes import SnappyDecompress
        import umsgpack

        # decrypt package
        export_pipe = Once(user_vault_key) \
            >> DecryptRSA_PKCS1_OAEP(self.identity.private_key)

        package_info = await export_pipe.readall()

        zipf = zipfile.ZipFile(BytesIO(package_info), 'r')

        vault_public_key = zipf.read('.vault/id_rsa.pub')
        vault_key = zipf.read('.vault/id_rsa')

        vault_identity = Identity.from_key(vault_public_key, self.config, private_key=vault_key)

        sink = Once(encrypted_metadata) \
                >> DecryptRSA_PKCS1_OAEP(vault_identity.private_key) \
                >> SnappyDecompress()

        serialized_metadata = await sink.readall()
        return umsgpack.unpackb(serialized_metadata)
开发者ID:syncrypt,项目名称:client,代码行数:25,代码来源:syncrypt.py


示例18: webui

def webui(ctx, host, port, cdn, scheduler_rpc, fetcher_rpc, max_rate, max_burst,
          username, password, need_auth, webui_instance):
    """
    Run WebUI
    """
    app = load_cls(None, None, webui_instance)

    g = ctx.obj
    app.config['taskdb'] = g.taskdb
    app.config['projectdb'] = g.projectdb
    app.config['resultdb'] = g.resultdb
    app.config['cdn'] = cdn

    if max_rate:
        app.config['max_rate'] = max_rate
    if max_burst:
        app.config['max_burst'] = max_burst
    if username:
        app.config['webui_username'] = username
    if password:
        app.config['webui_password'] = password
    app.config['need_auth'] = need_auth

    # fetcher rpc
    if isinstance(fetcher_rpc, six.string_types):
        import umsgpack
        fetcher_rpc = connect_rpc(ctx, None, fetcher_rpc)
        app.config['fetch'] = lambda x: umsgpack.unpackb(fetcher_rpc.fetch(x).data)
    else:
        # get fetcher instance for webui
        fetcher_config = g.config.get('fetcher', {})
        scheduler2fetcher = g.scheduler2fetcher
        fetcher2processor = g.fetcher2processor
        testing_mode = g.get('testing_mode', False)
        g['scheduler2fetcher'] = None
        g['fetcher2processor'] = None
        g['testing_mode'] = True
        webui_fetcher = ctx.invoke(fetcher, async=False, **fetcher_config)
        g['scheduler2fetcher'] = scheduler2fetcher
        g['fetcher2processor'] = fetcher2processor
        g['testing_mode'] = testing_mode

        app.config['fetch'] = lambda x: webui_fetcher.fetch(x)[1]

    if isinstance(scheduler_rpc, six.string_types):
        scheduler_rpc = connect_rpc(ctx, None, scheduler_rpc)
    if scheduler_rpc is None and os.environ.get('SCHEDULER_NAME'):
        app.config['scheduler_rpc'] = connect_rpc(ctx, None, 'http://%s/' % (
            os.environ['SCHEDULER_PORT_23333_TCP'][len('tcp://'):]))
    elif scheduler_rpc is None:
        app.config['scheduler_rpc'] = connect_rpc(ctx, None, 'http://localhost:23333/')
    else:
        app.config['scheduler_rpc'] = scheduler_rpc

    app.debug = g.debug
    g.instances.append(app)
    if g.get('testing_mode'):
        return app

    app.run(host=host, port=port)
开发者ID:SMWARREN,项目名称:pyspider,代码行数:60,代码来源:run.py


示例19: run_bb_bridge

    def run_bb_bridge(self):
        """
        Start up the bridge
        :return:
        """
        # self.pi.set_mode(11, pigpio.INPUT)
        # cb1 = self.pi.callback(11, pigpio.EITHER_EDGE, self.cbf)
        while True:
            if self.last_problem:
                self.report_problem()
            # noinspection PyBroadException
            try:
                z = self.subscriber.recv_multipart(zmq.NOBLOCK)
                self.payload = umsgpack.unpackb(z[1])
                # print("[%s] %s" % (z[0], self.payload))

                command = self.payload['command']
                if command == 'i2c_request':
                    time.sleep(.001)
                    continue
                elif command in self.command_dict:
                    self.command_dict[command]()
                else:
                    print("can't execute unknown command", str(command))
                    # time.sleep(.001)
            except KeyboardInterrupt:
                self.cleanup()
                sys.exit(0)
            except zmq.error.Again:
                time.sleep(.001)
开发者ID:MrYsLab,项目名称:xideco,代码行数:30,代码来源:xibb.py


示例20: test_unpack_composite

    def test_unpack_composite(self):
        for (name, obj, data) in composite_test_vectors:
            obj_repr = repr(obj)
            print("\tTesting %s: object %s" %
                  (name, obj_repr if len(obj_repr) < 24 else obj_repr[0:24] + "..."))

            self.assertEqual(umsgpack.unpackb(data), obj)
开发者ID:vsergeev,项目名称:u-msgpack-python,代码行数:7,代码来源:test_umsgpack.py



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


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Python uncertainties.correlated_values函数代码示例发布时间:2022-05-27
下一篇:
Python umsgpack.packb函数代码示例发布时间:2022-05-27
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap