python类packb()的实例源码

protocols.py 文件源码 项目:zatt 作者: simonacca 项目源码 文件源码 阅读 26 收藏 0 点赞 0 评论 0
def send(self, message):
        self.transport.write(msgpack.packb(
            message, use_bin_type=True, default=extended_msgpack_serializer))
        self.transport.close()
Connection.py 文件源码 项目:zeronet-debian 作者: bashrc 项目源码 文件源码 阅读 17 收藏 0 点赞 0 评论 0
def send(self, message, streaming=False):
        if config.debug_socket:
            self.log("Send: %s, to: %s, streaming: %s, site: %s, inner_path: %s, req_id: %s" % (
                message.get("cmd"), message.get("to"), streaming,
                message.get("params", {}).get("site"), message.get("params", {}).get("inner_path"),
                message.get("req_id"))
            )
        self.last_send_time = time.time()
        try:
            if streaming:
                bytes_sent = StreamingMsgpack.stream(message, self.sock.sendall)
                message = None
                self.bytes_sent += bytes_sent
                self.server.bytes_sent += bytes_sent
            else:
                data = msgpack.packb(message)
                message = None
                self.bytes_sent += len(data)
                self.server.bytes_sent += len(data)
                self.sock.sendall(data)
        except Exception, err:
            self.log("Send errror: %s" % Debug.formatException(err))
            self.close()
            return False
        self.last_sent_time = time.time()
        return True

    # Stream raw file to connection
indexer.py 文件源码 项目:lemongraph 作者: NationalSecurityAgency 项目源码 文件源码 阅读 31 收藏 0 点赞 0 评论 0
def key(self, name, value, smash=True):
        hash(value)
        return str(name), pack('=i',crc32(msgpack.packb(value)))
serializer.py 文件源码 项目:lemongraph 作者: NationalSecurityAgency 项目源码 文件源码 阅读 29 收藏 0 点赞 0 评论 0
def msgpack_encode_hashable(x):
    if not isinstance(x, collections.Hashable):
        raise ValueError(x)
    return messagepack.packb(x)
serializer.py 文件源码 项目:lemongraph 作者: NationalSecurityAgency 项目源码 文件源码 阅读 25 收藏 0 点赞 0 评论 0
def msgpack(hashable=False):
        return Serializer(encode=msgpack_encode_hashable, decode=msgpack_decode_hashable) if hashable else Serializer(encode=messagepack.packb, decode=messagepack.unpackb)
server.py 文件源码 项目:lemongraph 作者: NationalSecurityAgency 项目源码 文件源码 阅读 16 收藏 0 点赞 0 评论 0
def mp_dumps(obj, pretty=False):
    return msgpack.packb(obj)
vnrpc.py 文件源码 项目:InplusTrader_Linux 作者: zhengwsh 项目源码 文件源码 阅读 15 收藏 0 点赞 0 评论 0
def __msgpackPack(self, data):
        """??msgpack??"""
        return packb(data)

    #----------------------------------------------------------------------
images.py 文件源码 项目:deb-python-falcon 作者: openstack 项目源码 文件源码 阅读 21 收藏 0 点赞 0 评论 0
def on_get(self, req, resp):
        doc = {
            'images': [
                {
                    'href': '/images/1eaf6ef1-7f2d-4ecc-a8d5-6e8adba7cc0e.png'
                }
            ]
        }

        resp.data = msgpack.packb(doc, use_bin_type=True)
        resp.content_type = 'application/msgpack'
        resp.status = falcon.HTTP_200
msfrpc.py 文件源码 项目:mitmfnz 作者: dropnz 项目源码 文件源码 阅读 17 收藏 0 点赞 0 评论 0
def encode(self, data):
        return msgpack.packb(data)
_component.py 文件源码 项目:bowtie 作者: jwkvam 项目源码 文件源码 阅读 21 收藏 0 点赞 0 评论 0
def pack(x):
    """Encode ``x`` into msgpack with additional encoders."""
    return bytes(msgpack.packb(x, default=encoders))
serialization.py 文件源码 项目:katana-sdk-python2 作者: kusanagi 项目源码 文件源码 阅读 18 收藏 0 点赞 0 评论 0
def pack(data):
    """Pack python data to a binary stream.

    :param data: A python object to pack.

    :rtype: bytes.

    """

    return msgpack.packb(data, default=encode, encoding='utf-8')
encoding.py 文件源码 项目:dd-trace-py 作者: DataDog 项目源码 文件源码 阅读 32 收藏 0 点赞 0 评论 0
def _encode(self, obj):
        return msgpack.packb(obj, **MSGPACK_PARAMS)
msgpack_serializer.py 文件源码 项目:pysoa 作者: eventbrite 项目源码 文件源码 阅读 19 收藏 0 点赞 0 评论 0
def dict_to_blob(self, data_dict):
        assert isinstance(data_dict, dict), 'Input must be a dict'
        try:
            return msgpack.packb(data_dict, default=self.default, use_bin_type=True)
        except TypeError as e:
            raise InvalidField(*e.args)
Client.py 文件源码 项目:server 作者: arrchat 项目源码 文件源码 阅读 16 收藏 0 点赞 0 评论 0
def send_outgoing_packet(self, packet):
            data = packet.build_data()
            if not isinstance(packet, (Packets.OutgoingPacket.ResponsePacket, Packets.OutgoingPacket.ConfirmationPacket)):
                data.update({'query_id': self._outgoing_packet_id})
                self._outgoing_packet_id += 1
            self.logger.debug('Outgoing: %s', json.dumps(data))
            raw = msgpack.packb(data)
            self.socket.sync_write_message(raw)
minimizer.py 文件源码 项目:distiller 作者: pyoor 项目源码 文件源码 阅读 20 收藏 0 点赞 0 评论 0
def insert_seeds(self):
        print "[ +D+ ] - Begin seed insertion for minimization"
        bs = beanstalkc.Connection(host='127.0.0.1', port=11300)
        bs.use('min-queue')

        try:
            self.c.execute('''SELECT seed_name FROM results''')
            seeds = self.c.fetchall()
            for seed_name in seeds:
                if not self.is_minimized(seed_name):
                    with open(os.path.join(self.seed_dir, seed_name), 'rb') as d:
                        seed_data = d.read()

                    data = {
                        'name': seed_name,
                        'data': seed_data
                    }

                    seed_pack = msgpack.packb(data, use_bin_type=True)

                    while True:
                        if bs.stats_tube('minimize')['current-jobs-ready'] < 20:
                            print "[ +D+ ] - Pushing seed: %s" % seed_name

                            # Allow 4 hours for minimization - hackish
                            # Fix this later by touching the job after each successful action
                            bs.put(seed_pack, ttr=14400)
                            break
                        else:
                            sleep(1)
        finally:
            bs.close()
            self.sql.close()
            print "[ +D+ ] - All seeds inserted for minimization"
packer.py 文件源码 项目:distiller 作者: pyoor 项目源码 文件源码 阅读 19 收藏 0 点赞 0 评论 0
def pack(job):
    data = zlib.compress(msgpack.packb(job, use_bin_type=True), 9)
    return data
backend.py 文件源码 项目:aetros-cli 作者: aetros 项目源码 文件源码 阅读 28 收藏 0 点赞 0 评论 0
def send_message(self, message):
        """
        Internal. Sends the actual message from a queue entry.
        """
        if not self.connected:
            return False

        message['_sending'] = True

        msg = msgpack.packb(message, default=invalid_json_values)

        try:
            self.ssh_stream_stdin.write(msg)
            message['_sent'] = True
            self.ssh_stream_stdin.flush()

            return len(msg)
        except KeyboardInterrupt:

            if message['_sent']:
                return len(msg)

            return False

        except Exception as error:
            self.connection_error(error)
            return False
msgpack.py 文件源码 项目:serialize 作者: hgrecco 项目源码 文件源码 阅读 19 收藏 0 点赞 0 评论 0
def dumps(obj):
    return msgpack.packb(obj, default=all.encode)
cmq_rpc.py 文件源码 项目:pyktrader2 作者: harveywwu 项目源码 文件源码 阅读 17 收藏 0 点赞 0 评论 0
def __msgpack_pack(self, data):
        return msgpack.packb(data)
msfrpc.py 文件源码 项目:piSociEty 作者: paranoidninja 项目源码 文件源码 阅读 18 收藏 0 点赞 0 评论 0
def encode(self, data):
        return msgpack.packb(data)


问题


面经


文章

微信
公众号

扫码关注公众号