Unpack the notification from binary string.
481420
def from_binary_string(self, notification):
        """"""
        command = struct.unpack('>B', notification[0])[0]

        if command != self.COMMAND:
            raise NotificationInvalidCommandError()

        length = struct.unpack('>I', notification[1:5])[0]
        notification = notification[5:]
        offset = 0

        def next_item(offset):
            iden, length = struct.unpack('>BH', notification[offset:offset+3])
            offset += 3
            payload = notification[offset:offset+length]
            offset += length

            if iden == self.PAYLOAD:
                payload = struct.unpack('>{0}s'.format(length), payload)[0]
                self.payload = json.loads(payload)
            elif iden == self.TOKEN:
                payload = struct.unpack('>{0}s'.format(length), payload)[0]
                self.token = binascii.hexlify(payload)
            elif iden == self.PRIORITY:
                self.priority = struct.unpack('>B', payload)[0]
            elif iden == self.NOTIFICATION_ID:
                self.iden = struct.unpack('>I', payload)[0]
            elif iden == self.EXPIRE:
                payload = struct.unpack('>I', payload)[0]
                self.expire = (self.EXPIRE_IMMEDIATELY if payload == 0 else
                               datetime.fromtimestamp(payload))
            else:
                raise NotificationInvalidIdError()

            return offset

        while offset < length:
            offset = next_item(offset)
544857
def parse_message(self):
		""""""
		parser = parse_chain(self.parse_net32int,  # authid
							lambda *_: self.parse_net32int(),  # authlen
							lambda *_: self.parse_net32int(),  # opcode
							lambda *_: self.parse_net32int(),  # handle
							lambda *_: self.parse_net32int(),  # tid
							lambda *_: self.parse_net32int(),  # rid
							lambda *_: self.parse_bindict(),  # message
							lambda *_: self.parse_bindict(),  # object
							lambda *args: self.parse_fixedbuffer(args[1]))  # signature
		return parse_map(lambda args:  # skip authlen in args:
				OmapiMessage(*(args[0:1] + args[2:])), parser)
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]
1284235
def from_raw_message(cls, rawmessage):
        """"""
        if (rawmessage[5] &
                MESSAGE_FLAG_EXTENDED_0X10) == MESSAGE_FLAG_EXTENDED_0X10:
            if len(rawmessage) >= ExtendedSend.receivedSize:
                msg = ExtendedSend.from_raw_message(rawmessage)
            else:
                msg = None
        else:
            msg = StandardSend(rawmessage[2:5],
                               {'cmd1': rawmessage[6],
                                'cmd2': rawmessage[7]},
                               flags=rawmessage[5],
                               acknak=rawmessage[8:9])
        return msg
237416
def unpack_xml(text) -> ET.ElementTree:
    """"""
    etree: ET.ElementTree = ET.parse(io.StringIO(text))
    _check_for_errors(etree)
    return etree
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')
138101
def unpack_from(self, buff, offset=0):
        """"""
        return self._create(super(DictStruct, self).unpack_from(buff, offset))
1228921
def from_string(cls, s):
        """"""
        for num, text in cls._STATUS2STR.items():
            if text == s:
                return cls(num)
        else:
            raise ValueError("Wrong string %s" % s)
114001
def get(self):
        """"""

        # First retrieve all header bytes in order to extract
        # length of the message remainder.
        header = ''
        while len(header) < self.HEADER_LENGTH:
            chunk = self._sock.recv(self.HEADER_LENGTH - len(header))
            chunk = chunk.decode() if self._encode else chunk
            if chunk == '':
                return None
            header += chunk
        length = int(header)

        # Then retrieve the remainder of the message.
        message = ''
        while len(message) < length:
            chunk = self._sock.recv(length - len(message))
            chunk = chunk.decode() if self._encode else chunk
            if chunk == '':
                return None
            message += chunk
        return message
841109
def decode_pc11_message(raw_string):
    """"""

    data = {}
    spot = raw_string.split("^")
    data[const.FREQUENCY] = float(spot[1])
    data[const.DX] = spot[2]
    data[const.TIME] = datetime.fromtimestamp(mktime(strptime(spot[3]+" "+spot[4][:-1], "%d-%b-%Y %H%M")))
    data[const.COMMENT] = spot[5]
    data[const.SPOTTER] = spot[6]
    data["node"] = spot[7]
    data["raw_spot"] = raw_string
    return data
925922
def unpack(str)
      str.bytes.reverse.reduce(0) { |s, c| s * 256 + c }
    end
1321517
def unpack(cls, msg, client, server, request_id):
        
        payload_document = OrderedDict()
        flags, = _UNPACK_UINT(msg[:4])
        pos = 4
        if flags != 0 and flags != 2:
            raise ValueError('OP_MSG flag must be 0 or 2 not %r' % (flags,))

        while pos < len(msg):
            payload_type, = _UNPACK_BYTE(msg[pos:pos + 1])
            pos += 1
            payload_size, = _UNPACK_INT(msg[pos:pos + 4])
            if payload_type == 0:
                doc = bson.decode_all(msg[pos:pos + payload_size],
                                      CODEC_OPTIONS)[0]
                payload_document.update(doc)
                pos += payload_size
            elif payload_type == 1:
                section_size, = _UNPACK_INT(msg[pos:pos + 4])
                pos += 4
                identifier, pos = _get_c_string(msg, pos)
                # Section starts w/ 4-byte size prefix, identifier ends w/ nil.
                documents_len = section_size - len(identifier) - 1 - 4
                documents = bson.decode_all(msg[pos:pos + documents_len],
                                            CODEC_OPTIONS)
                payload_document[identifier] = documents
                pos += documents_len

        database = payload_document['$db']
        return OpMsg(payload_document, namespace=database, flags=flags,
                     _client=client, request_id=request_id,
                     _server=server)
939939
def bin_to_int(string):
    """"""
    if isinstance(string, str):
        return struct.unpack("b", string)[0]
    else:
        return struct.unpack("b", bytes([string]))[0]
1265991
def from_raw_message(cls, rawmessage):
        """"""
        return StandardReceive(rawmessage[2:5],
                               rawmessage[5:8],
                               {'cmd1': rawmessage[9],
                                'cmd2': rawmessage[10]},
                               flags=rawmessage[8])
672325
def split(self, text):
        """"""
        text = cleanup(text)
        return self.sent_detector.tokenize(text.strip())
71441
def _unpack_msg(self, *msg):
        
        l = []
        for m in msg:
            l.append(str(m))
        return " ".join(l)
1027921
def ctcp_unpack_message(info):
    """"""
    verb = info['verb']
    message = info['params'][1]

    # NOTE: full CTCP dequoting and unpacking is not done here, only a subset
    #   this is because doing the full thing breaks legitimate messages

    # basics
    infos = []

    X_QUOTE = '\\'
    X_DELIM = '\x01'

    # tagged data
    messages = str(message).split(X_DELIM)

    for i in range(len(messages)):
        msg = messages[i]
        new_info = dict(info)

        if i % 2 == 0:  # is normal message)
            if not msg:
                continue
            new_info['params'] = new_info['params'][:1]
            new_info['params'].append(msg)
        else:
            if verb in ['privnotice', 'pubnotice']:
                new_info['verb'] = 'ctcp_reply'
            else:
                new_info['verb'] = 'ctcp'
            if ' ' in msg.lstrip():
                new_info['ctcp_verb'], new_info['ctcp_text'] = msg.lstrip().split(' ', 1)
            else:
                new_info['ctcp_verb'] = msg.lstrip()
                new_info['ctcp_text'] = ''

            new_info['ctcp_verb'] = new_info['ctcp_verb'].lower()

        infos.append([new_info['verb'], new_info])

    # ctcp-level dequoting
    for i in range(len(infos)):
        if infos[i][NAME_ATTR] == 'ctcp':
            attrs = ['ctcp_verb', 'ctcp_text']
        else:
            attrs = ['params']

        for attr in attrs:
            if isinstance(infos[i][INFO_ATTR][attr], (list, tuple)):
                raw_messages = infos[i][INFO_ATTR][attr]
            else:
                raw_messages = [infos[i][INFO_ATTR][attr]]

            messages = []
            for raw in raw_messages:
                unquoted = ''
                while len(raw):
                    char = raw[0]
                    raw = raw[1:]

                    if char == X_QUOTE:
                        if not len(raw):
                            continue
                        key = raw[0]
                        raw = raw[1:]

                        if key == 'a':
                            unquoted += X_DELIM
                        elif key == X_QUOTE:
                            unquoted += X_QUOTE
                        else:
                            unquoted += key
                    else:
                        unquoted += char
                messages.append(unquoted)

            if isinstance(infos[i][INFO_ATTR][attr], (list, tuple)):
                infos[i][INFO_ATTR][attr] = messages
            else:
                infos[i][INFO_ATTR][attr] = messages[0]

    return infos