Unpack binary data into python object.
186159
def unpack(self, buff, offset=0):
        """"""
        super().unpack(buff, offset)
        code_class = ErrorType(self.error_type).get_class()
        self.code = code_class(self.code)
1152841
def unpack(data):
    ''''''
    size, position = decoder._DecodeVarint(data, 0)
    envelope = wire.Envelope() 
    envelope.ParseFromString(data[position:position+size])
    return envelope
959053
def unpackfile(filename, destdir):
    """"""
    if filename.endswith(".mar"):
        return unpackmar(filename, destdir)
    elif filename.endswith(".exe"):
        return unpackexe(filename, destdir)
    elif filename.endswith(".tar") or filename.endswith(".tar.gz") \
            or filename.endswith(".tgz"):
        return unpacktar(filename, destdir)
    else:
        raise ValueError("Unknown file type: %s" % filename)
821188
def parse(binary, **params):
    """"""
    binary = io.BytesIO(binary)
    collection = list()
    with tarfile.TarFile(fileobj=binary, mode='r') as tar:
        for tar_info in tar.getmembers():
            content_type, encoding = mimetypes.guess_type(tar_info.name)
            content = tar.extractfile(tar_info)
            content = content_encodings.get(encoding).decode(content)
            content = content_types.get(content_type).parse(content, **params)
            collection.apppend((tar_info.name, content))
    return collection
638295
def _deserialize_dict(cls, data):
        '''
        
        '''
        return cPickle.loads(zlib.decompress(b64decode(data.encode())))
1341126
def _take_bits(buf, count):
    """"""

    # TODO: Verify output
    bytes_count = (count + 7) // 8
    bytes_mod = count % 8
    data = _unpack_from(buf, 'B', bytes_count)
    values = []
    for i, byte in enumerate(data):
        for _ in range(8 if i != bytes_count - 1 else bytes_mod):
            # TODO: Convert to True / False
            values.append(byte & 0b10000000)
            byte <<= 1
    return values
497862
def _swap_bytes(data):
    """"""

    a, b = data[1::2], data[::2]
    data = bytearray().join(bytearray(x) for x in zip(a, b))
    if len(b) > len(a):
        data += b[-1:]
    return bytes(data)
462205
def _unpack_from(buf, format_s, count=None, little_endian=True):
    """"""

    if count is not None:
        assert count > 0
        format_s = '%i%s' % (count, format_s)

    if little_endian is True:
        format_s = '<' + format_s
    else:
        format_s = '>' + format_s

    size = struct.calcsize(format_s)
    res = struct.unpack_from(format_s, buf.read(size))

    if count is not None:
        return res
    else:
        return res[0]
537226
def to_python(self, data):
        
        if data is None:
            return data
        if self.datatype:
            return self.datatype(data)
        else:
            return data
26857
def _unpack_data(data):
    
    xs = [None] * len(data)
    ys = [None] * len(data)
    metadata = [None] * len(data)
    for idx, example in enumerate(data):
        if isinstance(example, (list, tuple)):
            xs[idx], ys[idx], metadata[idx] = _unpack_list(example)
        if isinstance(example, dict):
            xs[idx], ys[idx], metadata[idx] = _unpack_dict(example)

    return xs, ys, metadata
793044
def _pfp__unpack_data(self, raw_data):
        
        if self._pfp__pack_type is None:
            return
        if self._pfp__no_unpack:
            return

        unpack_func = self._pfp__packer
        unpack_args = []
        if self._pfp__packer is not None:
            unpack_func = self._pfp__packer
            unpack_args = [false(), raw_data]

        elif self._pfp__unpack is not None:
            unpack_func = self._pfp__unpack
            unpack_args = [raw_data]

        # does not need to be converted to a char array
        if not isinstance(unpack_func, functions.NativeFunction):
            io_stream = bitwrap.BitwrappedStream(six.BytesIO(raw_data))
            unpack_args[-1] = Array(len(raw_data), Char, io_stream)

        res = unpack_func.call(unpack_args, *self._pfp__pack_func_call_info, no_cast=True)
        if isinstance(res, Array):
            res = res._pfp__build()

        io_stream = six.BytesIO(res)
        tmp_stream = bitwrap.BitwrappedStream(io_stream)

        tmp_stream.padded = self._pfp__interp.get_bitfield_padded()

        self._ = self._pfp__parsed_packed = self._pfp__pack_type(tmp_stream)

        self._._pfp__watch(self)
132298
def unpack_bytes(self, obj_bytes, encoding=None):
        """"""
        assert self.bytes_to_dict or self.string_to_dict
        encoding = encoding or self.default_encoding
        LOGGER.debug('%r decoding %d bytes with encoding of %s',
                     self, len(obj_bytes), encoding)
        if self.bytes_to_dict:
            return escape.recursive_unicode(self.bytes_to_dict(obj_bytes))
        return self.string_to_dict(obj_bytes.decode(encoding))
524401
def unpack(packed, object_hook=decode,
           list_hook=None, use_list=False, encoding='utf-8',
           unicode_errors='strict', object_pairs_hook=None,
           max_buffer_size=0, ext_hook=ExtType):
    

    return Unpacker(packed, object_hook=object_hook,
                    list_hook=list_hook,
                    use_list=use_list, encoding=encoding,
                    unicode_errors=unicode_errors,
                    object_pairs_hook=object_pairs_hook,
                    max_buffer_size=max_buffer_size,
                    ext_hook=ext_hook)
728700
def to_binary(self):
        """"""
        node = self.node.to_binary()
        if node is self.node:
            return self
        else:
            return _expr(node)
321925
def unpack_rgb(packed):

    '''

    '''

    orig_shape = None

    if isinstance(packed, np.ndarray):
        assert packed.dtype == int
        orig_shape = packed.shape
        packed = packed.reshape((-1, 1))

    rgb = ((packed >> 16) & 0xff,
           (packed >> 8) & 0xff,
           (packed) & 0xff)

    if orig_shape is None:
        return rgb
    else:
        return np.hstack(rgb).reshape(orig_shape + (3,))
230515
def _get_float(data, position, dummy0, dummy1, dummy2):
    """"""
    end = position + 8
    return _UNPACK_FLOAT(data[position:end])[0], end
521236
def unpack_from(cls, payload, expected_parts):
        """"""

        for num_part in iter_range(expected_parts):
            hdr = payload.read(cls.header_size)
            try:
                part_header = PartHeader(*cls.header_struct.unpack(hdr))
            except struct.error:
                raise InterfaceError("No valid part header")

            if part_header.payload_size % 8 != 0:
                part_payload_size = part_header.payload_size + 8 - (part_header.payload_size % 8)
            else:
                part_payload_size = part_header.payload_size
            pl = payload.read(part_payload_size)
            part_payload = io.BytesIO(pl)
            try:
                _PartClass = PART_MAPPING[part_header.part_kind]
            except KeyError:
                raise InterfaceError("Unknown part kind %s" % part_header.part_kind)

            debug('%s (%d/%d): %s', _PartClass.__name__, num_part+1, expected_parts, str(part_header))
            debug('Read %d bytes payload for part %d', part_payload_size, num_part + 1)

            init_arguments = _PartClass.unpack_data(part_header.argument_count, part_payload)
            debug('Part data: %s', init_arguments)
            part = _PartClass(*init_arguments)
            part.header = part_header
            part.attribute = part_header.part_attributes
            part.source = 'server'
            if pyhdb.tracing:
                part.trace_header = humanhexlify(hdr[:part_header.payload_size])
                part.trace_payload = humanhexlify(pl, 30)
            yield part