How to use the msgpack.exceptions.ExtraData function in msgpack

To help you get started, we’ve selected a few msgpack examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github makinacorpus / makina-states / doc / mc_states / modules / mc_macros.py View on Github external
def pack_load_local_registry(name, registryf=None):
    value = {}
    regpath = get_registry_path(name,
                                registryf=registryf,
                                registry_format='pack')
    try:
        if os.path.exists(regpath):
            with open(regpath) as fic:
                rvalue = fic.read()
                value = __salt__['mc_utils.msgpack_load'](
                    rvalue)
    except (msgpack.exceptions.UnpackValueError,
            msgpack.exceptions.ExtraData):
        log.error('decoding error, removing stale {0}'.format(regpath))
        os.unlink(regpath)
        value = {}
    return value
github makinacorpus / makina-states / mc_states / modules / mc_macros.py View on Github external
def pack_load_local_registry(name, registryf=None):
    value = {}
    regpath = get_registry_path(name,
                                registryf=registryf,
                                registry_format='pack')
    try:
        if os.path.exists(regpath):
            with open(regpath) as fic:
                rvalue = fic.read()
                value = __salt__['mc_utils.msgpack_load'](
                    rvalue)
    except (msgpack.exceptions.UnpackValueError,
            msgpack.exceptions.ExtraData):
        log.error('decoding error, removing stale {0}'.format(regpath))
        os.unlink(regpath)
        value = {}
    return value
github pypa / warehouse / warehouse / sessions.py View on Github external
session_id = session_id.decode("utf8")
        except crypto.BadSignature:
            return Session()

        # Fetch the serialized data from redis
        bdata = self.redis.get(self._redis_key(session_id))

        # If the session didn't exist in redis, we'll give the user a new
        # session.
        if bdata is None:
            return Session()

        # De-serialize our session data
        try:
            data = msgpack.unpackb(bdata, encoding="utf8", use_list=True)
        except (msgpack.exceptions.UnpackException, msgpack.exceptions.ExtraData):
            # If the session data was invalid we'll give the user a new session
            return Session()

        # If we were able to load existing session data, load it into a
        # Session class
        session = Session(data, session_id, False)

        return session
github JordanDelcros / OBJImg / resources / three / 73 / utils / converters / msgpack / msgpack / fallback.py View on Github external
def unpackb(packed, **kwargs):
    """
    Unpack an object from `packed`.

    Raises `ExtraData` when `packed` contains extra bytes.
    See :class:`Unpacker` for options.
    """
    unpacker = Unpacker(None, **kwargs)
    unpacker.feed(packed)
    try:
        ret = unpacker._fb_unpack()
    except OutOfData:
        raise UnpackValueError("Data is not enough.")
    if unpacker._fb_got_extradata():
        raise ExtraData(ret, unpacker._fb_get_extradata())
    return ret
github pymedusa / Medusa / ext / msgpack / fallback.py View on Github external
def unpackb(packed, **kwargs):
    """
    Unpack an object from `packed`.

    Raises `ExtraData` when `packed` contains extra bytes.
    See :class:`Unpacker` for options.
    """
    unpacker = Unpacker(None, **kwargs)
    unpacker.feed(packed)
    try:
        ret = unpacker._unpack()
    except OutOfData:
        raise UnpackValueError("Data is not enough.")
    if unpacker._got_extradata():
        raise ExtraData(ret, unpacker._get_extradata())
    return ret
github Omegastick / pytorch-cpp-rl / gym_server / zmq_client.py View on Github external
def receive(self) -> bytes:
        """
        Gets a message from the client.
        Blocks until a message is received.
        """
        message = self.socket.recv()
        try:
            response = msgpack.unpackb(message, raw=False)
        except msgpack.exceptions.ExtraData:
            response = message
        return response
github JordanDelcros / OBJImg / resources / three / 73 / utils / converters / msgpack / msgpack / fallback.py View on Github external
def unpack(stream, **kwargs):
    """
    Unpack an object from `stream`.

    Raises `ExtraData` when `packed` contains extra bytes.
    See :class:`Unpacker` for options.
    """
    unpacker = Unpacker(stream, **kwargs)
    ret = unpacker._fb_unpack()
    if unpacker._fb_got_extradata():
        raise ExtraData(ret, unpacker._fb_get_extradata())
    return ret
github SBRG / ssbio / ssbio / core / protein.py View on Github external
continue
                    # TODO: add try/except to download cif file as fallback like below?

                if rez_cutoff and pdb.resolution:
                    if pdb.resolution > rez_cutoff:
                        log.debug('{}: structure does not meet experimental resolution cutoff'.format(pdb, pdb_file_type))
                        continue
                # TODO: clean up these try/except things
                try:
                    self.align_seqprop_to_structprop(seqprop=self.representative_sequence,
                                                     structprop=pdb,
                                                     outdir=seq_outdir,
                                                     engine=engine,
                                                     parse=True,
                                                     force_rerun=force_rerun)
                except (PDBConstructionException, ExtraData) as e:
                    log.error('{}: unable to parse structure file as {}. Falling back to mmCIF format.'.format(pdb, pdb_file_type))
                    print(e)
                    # Fall back to using mmCIF file if structure cannot be parsed
                    try:
                        pdb.download_structure_file(outdir=struct_outdir, file_type='cif',
                                                    force_rerun=force_rerun)
                        # Download the mmCIF header file to get additional information
                        if 'cif' not in pdb_file_type:
                            pdb.download_cif_header_file(outdir=struct_outdir, force_rerun=force_rerun)
                    except (requests.exceptions.HTTPError, URLError):
                        log.error('{}: structure file could not be downloaded'.format(pdb))
                        continue
                    self.align_seqprop_to_structprop(seqprop=self.representative_sequence,
                                                     structprop=pdb,
                                                     outdir=seq_outdir,
                                                     engine=engine,