Create a Message instance from data, data will be loaded
        via munge according to the codec specified in the
        transport_content_type attribute

        Returns:

            Message: message object
436028
def make_message(self, data):

        

        data = self.codec.loads(data)
        msg = Message(
            data.get("data"),
            *data.get("args",[]),
            **data.get("kwargs",{})
        )
        msg.meta.update(data.get("meta"))
        self.trigger("make_message", data, msg)
        return msg
740466
def get_message(self, transport, http_version: str, method: bytes,
                    url: bytes, headers: List[List[bytes]]) -> Dict[str, Any]:
        '''
        
        '''
        url_obj = parse_url(url)
        if url_obj.schema is None:
            if transport.get_extra_info('sslcontext'):
                scheme = 'https'
            else:
                scheme = 'http'
        else:
            scheme = url_obj.schema.decode()
        path = '' if url_obj.path is None else url_obj.path.decode('utf-8')
        query = b'' if url_obj.query is None else url_obj.query
        return {
            'channel': 'http.request',
            'reply_channel': None,
            'http_version': http_version,
            'method': method.decode(),
            'scheme': scheme,
            'path': path,
            'query_string': query,
            'root_path': '',
            'headers': headers,
            'body': b'',
            'body_channel': None,
            'client': transport.get_extra_info('peername'),
            'server': transport.get_extra_info('sockname')
        }
227810
def to_bytes(data):
    
    if isinstance(data, six.string_types) and not isinstance(data, bytes):
        return codecs.encode(data, TEXT_ENCODING)
    return data
1324998
def _unpack(self, data):
        
        msg_magic, msg_length, msg_type = self._unpack_header(data)
        msg_size = self._struct_header_size + msg_length
        # XXX: Message shouldn't be any longer than the data
        payload = data[self._struct_header_size:msg_size]
        return payload.decode('utf-8', 'replace')
193930
def _get_message(self, get_frame, auto_decode):
        
        message_uuid = self._channel.rpc.register_request(
            get_frame.valid_responses + ['ContentHeader', 'ContentBody']
        )
        try:
            self._channel.write_frame(get_frame)
            get_ok_frame = self._channel.rpc.get_request(message_uuid,
                                                         raw=True,
                                                         multiple=True)
            if isinstance(get_ok_frame, specification.Basic.GetEmpty):
                return None
            content_header = self._channel.rpc.get_request(message_uuid,
                                                           raw=True,
                                                           multiple=True)
            body = self._get_content_body(message_uuid,
                                          content_header.body_size)
        finally:
            self._channel.rpc.remove(message_uuid)
        return Message(channel=self._channel,
                       body=body,
                       method=dict(get_ok_frame),
                       properties=dict(content_header.properties),
                       auto_decode=auto_decode)
773490
def create(self, msgtype, *args, **kwargs):
        ''' 

        '''
        if msgtype not in self._messages:
            raise ProtocolError("Unknown message type %r for protocol version %s" % (msgtype, self._version))
        return self._messages[msgtype].create(*args, **kwargs)
1153988
def from_raw_message(cls, rawmessage):
        """"""
        userdata = Userdata.from_raw_message(rawmessage[11:25])
        return ExtendedReceive(rawmessage[2:5],
                               rawmessage[5:8],
                               {'cmd1': rawmessage[9],
                                'cmd2': rawmessage[10]},
                               userdata,
                               flags=rawmessage[8])
391548
def compress_message(data_to_compress):
    
    compressed_content = cms.ParsableOctetString(
        zlib.compress(data_to_compress))
    return cms.ContentInfo({
        'content_type': cms.ContentType('compressed_data'),
        'content': cms.CompressedData({
            'version': cms.CMSVersion('v0'),
            'compression_algorithm':
                cms.CompressionAlgorithm({
                    'algorithm': cms.CompressionAlgorithmId('zlib')
                }),
            'encap_content_info': cms.EncapsulatedContentInfo({
                'content_type': cms.ContentType('data'),
                'content': compressed_content
            })
        })
    }).dump()
126217
def read_message(self, message_type, compressed=False, read_size=True):
        
        if read_size:
            size = self.read_vint32()
            b = self.read(size)
        else:
            b = self.read()

        if compressed:
            b = snappy.decompress(b)

        m = message_type()
        m.ParseFromString(b)
        return m
692123
def get_body_from_message(message, maintype, subtype):
    
    body = six.text_type('')
    for part in message.walk():
        if part.get('content-disposition', '').startswith('attachment;'):
            continue
        if part.get_content_maintype() == maintype and \
                part.get_content_subtype() == subtype:
            charset = part.get_content_charset()
            this_part = part.get_payload(decode=True)
            if charset:
                try:
                    this_part = this_part.decode(charset, 'replace')
                except LookupError:
                    this_part = this_part.decode('ascii', 'replace')
                    logger.warning(
                        'Unknown encoding %s encountered while decoding '
                        'text payload.  Interpreting as ASCII with '
                        'replacement, but some data may not be '
                        'represented as the sender intended.',
                        charset
                    )
                except ValueError:
                    this_part = this_part.decode('ascii', 'replace')
                    logger.warning(
                        'Error encountered while decoding text '
                        'payload from an incorrectly-constructed '
                        'e-mail; payload was converted to ASCII with '
                        'replacement, but some data may not be '
                        'represented as the sender intended.'
                    )
            else:
                this_part = this_part.decode('ascii', 'replace')

            body += this_part

    return body
951779
async def message(self, msg, msg_type=None):
        
        elem_type = msg_type if msg_type is not None else msg.__class__

        if hasattr(elem_type, 'blob_serialize'):
            msg = elem_type() if msg is None else msg
            return await msg.blob_serialize(self)

        fields = elem_type.f_specs()
        for field in fields:
            await self.message_field(msg=msg, field=field)

        return msg
734314
def from_bytes(self, raw):
        ''''''
        if len(raw) < TCP._MINLEN:
            raise NotEnoughDataError("Not enough bytes ({}) to reconstruct an TCP object".format(len(raw)))
        fields = struct.unpack(TCP._PACKFMT, raw[:TCP._MINLEN])
        self._src = fields[0]
        self._dst = fields[1]
        self._seq = fields[2]        
        self._ack = fields[3]
        offset = fields[4] >> 12
        self._flags = fields[4] & 0x01ff
        self._window = fields[5]
        csum = fields[6]
        self._urg = fields[7]
        headerlen = offset * 4
        optlen = headerlen - TCP._MINLEN
        self._options.from_bytes(raw[TCP._MINLEN:headerlen])
        return raw[headerlen:]
659243
def from_data(cls, type, **data):
        
        try:
            return cls._types[type](**data)
        except KeyError:
            return cls(type=type, **data)
        except TypeError as e:
            error = 'could not create {!r} attachment'.format(type)
            raise TypeError('{}: {}'.format(error, e.args[0]))
989246
def build_message(self):
        '''
        '''
        if self._text is None:
            raise InvalidPayloadError('text is required')

        message = {
            'text': self._text,
            'markdown': self._markdown
        }

        if self._channel != Incoming.DEFAULT_CHANNEL:
            message['channel'] = self._channel

        if self._attachments:
            message['attachments'] = []
            for attachment in self._attachments:
                if 'title' not in attachment and 'text' not in attachment:
                    raise InvalidPayloadError('title or text is required')
                message['attachments'].append(attachment)

        return message
258392
def get_message(self):
        """"""

        result = ''
        if self._data_struct is not None:
            result = self._data_struct[KEY_MESSAGE]
        return result
359056
def from_message(cls, message):
        
        type_ = message.get_text()
        return cls(type_=type_, blob=message.asbytes())
313975
def __pack_message(operation, data):
    
    request_id = _randint()
    message = struct.pack("<i", 16 + len(data))
    message += struct.pack("<i", request_id)
    message += _ZERO_32  # responseTo
    message += struct.pack("<i", operation)
    return (request_id, message + data)