Get and return a message using a Basic.Get frame.

        :param Basic.Get get_frame:
        :param bool auto_decode: Auto-decode strings when possible.

        :rtype: Message
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)
472056
def _decode(obj):  # type: (bytes or str or unicode or object) -> unicode # noqa ignore=F821
    
    if obj is None:
        return u''
    if six.PY3 and isinstance(obj, six.binary_type):
        # transforms a byte string (b'') in unicode
        return obj.decode('latin1')
    elif six.PY3:
        # PY3 strings are unicode.
        return str(obj)
    elif isinstance(obj, six.text_type):
        # returns itself if it is unicode
        return obj
    else:
        # decodes pY2 string to unicode
        return str(obj).decode('utf-8')
469986
def text_frame(self):
        
        if len(self._text['frames']) == 1:
            if self._text_color:
                return colored_frame(self._text['frames'][0], self._text_color)

            # Return first frame (can't return original text because at this point it might be ellipsed)
            return self._text['frames'][0]

        frames = self._text['frames']
        frame = frames[self._text_index]

        self._text_index += 1
        self._text_index = self._text_index % len(frames)

        if self._text_color:
            return colored_frame(frame, self._text_color)

        return frame
1211188
def decode(self, envelope, session, **kwargs):
		
		return WMessengerBytesEnvelope(bytes(WUnHex(envelope.message())), meta=envelope)
15628
def read_message(self):
        
        opcode = None
        message = None
        while True:
            header, payload = self.read_frame()
            f_opcode = header.opcode
            if f_opcode in (self.OPCODE_TEXT, self.OPCODE_BINARY):
                # a new frame
                if opcode:
                    raise WebSocketError("The opcode in non-fin frame is expected to be zero, got {0!r}".format(f_opcode))
                # Start reading a new message, reset the validator
                self.utf8validator.reset()
                self.utf8validate_last = (True, True, 0, 0)
                opcode = f_opcode
            elif f_opcode == self.OPCODE_CONTINUATION:
                if not opcode:
                    raise WebSocketError("Unexpected frame with opcode=0")
            elif f_opcode == self.OPCODE_PING:
                self.handle_ping(header, payload)
                continue
            elif f_opcode == self.OPCODE_PONG:
                self.handle_pong(header, payload)
                continue
            elif f_opcode == self.OPCODE_CLOSE:
                self.handle_close(header, payload)
                return
            else:
                raise WebSocketError("Unexpected opcode={0!r}".format(f_opcode))
            if opcode == self.OPCODE_TEXT:
                self.validate_utf8(payload)
                if six.PY3:
                    payload = payload.decode()
            if message is None:
                message = six.text_type() if opcode == self.OPCODE_TEXT else six.binary_type()
            message += payload
            if header.fin:
                break
        if opcode == self.OPCODE_TEXT:
            if six.PY2:
                self.validate_utf8(message)
            else:
                self.validate_utf8(message.encode())
            return message
        else:
            return bytearray(message)
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
1265375
def decode(s):
    
    if isinstance(s, bytes):
        return s.decode(sys.getdefaultencoding())
    else:
        return s
191587
def _auto_decode(data):
    
    assert isinstance(data, six.binary_type)

    for e in ENCODINGS:
        try:
            return data.decode(e), e
        except UnicodeDecodeError:
            pass

    return data.decode('utf-8', 'ignore')
728174
def get(self, key, default=None, msg_if_none=None):
        
        out = getattr(self, key, default)

        if (out is None) and (msg_if_none is not None):
            raise ValueError(msg_if_none)

        return out
1015161
function DecodeMessage (raw) {
  if (!(raw instanceof BufferList)) {
    raw = new BufferList(raw)
  }

  var version = msgpack.decode(raw)
  var messageType = msgpack.decode(raw)
  var MessageClass = messageTypeToFunction[messageType]

  if (!MessageClass) {
    throw new DxlError('Unknown message type: ' + messageType)
  }

  var message = new MessageClass()
  message.version = version
  message._unpackMessage(raw)
  if (version > 0) {
    message._unpackMessagev1(raw)
  }
  if (version > 1) {
    message._unpackMessagev2(raw)
  }

  return message
}
729581
def from_raw(conn, raw):
        ''''''
        frame_type = struct.unpack('>l', raw[0:4])[0]
        message = raw[4:]
        if frame_type == FRAME_TYPE_MESSAGE:
            return Message(conn, frame_type, message)
        elif frame_type == FRAME_TYPE_RESPONSE:
            return Response(conn, frame_type, message)
        elif frame_type == FRAME_TYPE_ERROR:
            return Error(conn, frame_type, message)
        else:
            raise TypeError('Unknown frame type: %s' % frame_type)
945630
def receive(self, decode=True):
        
        payload = self.socket.recv()
        payload = self.verify(payload)
        if decode:
            payload = self.decode(payload)
        return payload
634791
def getMessage(self, message):
        '''
        
        '''
        if message.filename != self._filename:
            raise RuntimeError(
                'Message filename ({:}) does not match batch filename ({:}).'
                .format(message.filename, self._filename))
        self._file.seek(message.offset)
        self._logger.debug(
            'Retrieved message offset={:}, size={:}'
            .format(message.offset, message.size))
        return self._file.read(message.size)
13253
def parse_frame(frame):
    
    f = Frame()
    if frame == b'\x0a':
        f.cmd = 'heartbeat'
        return f

    mat = PREAMBLE_END_RE.search(frame)
    if mat:
        preamble_end = mat.start()
        body_start = mat.end()
    else:
        preamble_end = len(frame)
        body_start = preamble_end
    preamble = decode(frame[0:preamble_end])
    preamble_lines = LINE_END_RE.split(preamble)
    preamble_len = len(preamble_lines)
    f.body = frame[body_start:]

    # Skip any leading newlines
    first_line = 0
    while first_line < preamble_len and len(preamble_lines[first_line]) == 0:
        first_line += 1

    if first_line >= preamble_len:
        return None

    # Extract frame type/command
    f.cmd = preamble_lines[first_line]

    # Put headers into a key/value map
    f.headers = parse_headers(preamble_lines, first_line + 1)

    return f
1163401
def load(cls, bmessage):
        
        message_dict = msgpack.loads(bmessage, encoding="utf8", use_list=False)

        try:
            obj = MessageMeta._registered_messages[message_dict["type"]].__new__(MessageMeta._registered_messages[message_dict["type"]])
            object.__setattr__(obj, "__dict__", message_dict)
        except:
            raise TypeError("Unknown message type") from None

        if not obj._verify():  # pylint: disable=protected-access
            raise TypeError("Invalid message content")

        return obj
910768
def encode(self, frame: Frame) -> Frame:
        
        # Skip control frames.
        if frame.opcode in CTRL_OPCODES:
            return frame

        # Since we always encode and never fragment messages, there's no logic
        # similar to decode() here at this time.

        if frame.opcode != OP_CONT:
            # Re-initialize per-message decoder.
            if self.local_no_context_takeover:
                self.encoder = zlib.compressobj(
                    wbits=-self.local_max_window_bits, **self.compress_settings
                )

        # Compress data frames.
        data = self.encoder.compress(frame.data) + self.encoder.flush(zlib.Z_SYNC_FLUSH)
        if frame.fin and data.endswith(_EMPTY_UNCOMPRESSED_BLOCK):
            data = data[:-4]

        # Allow garbage collection of the encoder if it won't be reused.
        if frame.fin and self.local_no_context_takeover:
            del self.encoder

        return frame._replace(data=data, rsv1=True)
223333
async def get(self, *, encoding=None, decoder=None):
        
        assert decoder is None or callable(decoder), decoder
        if self._queue.exhausted:
            raise ChannelClosedError()
        msg = await self._queue.get()
        if msg is EndOfStream:
            # TODO: maybe we need an explicit marker for "end of stream"
            #       currently, returning None may overlap with
            #       possible return value from `decoder`
            #       so the user would have to check `ch.is_active`
            #       to determine if its EoS or payload
            return
        if self._is_pattern:
            dest_channel, msg = msg
        if encoding is not None:
            msg = msg.decode(encoding)
        if decoder is not None:
            msg = decoder(msg)
        if self._is_pattern:
            return dest_channel, msg
        return msg