

@staticmethod
def unpack(data):

    def _key_values(name, data):
        if (len(data) < 2):
            raise Notify(2, 0, ('Bad length for OPEN %s (<2) %s' % (name, Capability.hex(data))))
        l = ord(data[1])
        boundary = (l + 2)
        if (len(data) < boundary):
            raise Notify(2, 0, ('Bad length for OPEN %s (buffer underrun) %s' % (name, Capability.hex(data))))
        key = ord(data[0])
        value = data[2:boundary]
        rest = data[boundary:]
        return (key, value, rest)
    capabilities = Capabilities()
    option_len = ord(data[0])
    if option_len:
        data = data[1:]
        while data:
            (key, value, data) = _key_values('parameter', data)
            if (key == Parameter.AUTHENTIFICATION_INFORMATION):
                raise Notify(2, 5)
            if (key == Parameter.CAPABILITIES):
                while value:
                    (capability, capv, value) = _key_values('capability', value)
                    capabilities[capability] = Capability.unpack(capability, capabilities, capv)
            else:
                raise Notify(2, 0, ('Unknow OPEN parameter %s' % hex(key)))
    return capabilities

dataset/ETHPy150Open Exa-Networks/exabgp/lib/exabgp/bgp/message/open/capability/capabilities.py Capabilities.unpack/original