# Path: shapy/framework/utils.py
# def align(l, alignto=4):
#     """Aligned length to nearest multiple of 4."""
#     return (l + alignto - 1) & ~(alignto - 1)
# 
# class InterpreterMixin(object):
#     interpreters = {}
#     
#     @classmethod
#     def register(cls, interpreter, content_types):
#         for type in content_types:
#             cls.interpreters.update({type: interpreter})
#     
#     @classmethod
#     def select(cls, selector):
#         """Selects interpreter object based on the selector."""
#         return cls.interpreters[selector]


import quopri, binascii
import struct
from struct import Struct
from shapy.framework.utils import align, InterpreterMixin
from .constants import *
    #};
    
    rtattr = Struct('HH')
    
    @classmethod
    def unpack(cls, data):
        length, type = cls.rtattr.unpack(data[:cls.rtattr.size])
        data_len = length-cls.rtattr.size
        attr_data = struct.unpack('{0}s'.format(data_len),
                             data[cls.rtattr.size:cls.rtattr.size+data_len])[0]
        return cls(type, attr_data), data[align(length):]
    
    def __init__(self, rta_type, payload):
        self.rta_type = rta_type
        self.payload = payload
        self.data = self.unpack_data()
        
    def pack(self):
        data = struct.pack('{0}s'.format(len(self.payload)), self.payload)
        rta_len = self.rtattr.size+len(data)
        return struct.pack('{0}{1}s'.format(self.rtattr.format, align(len(data))),
                           rta_len, self.rta_type, data)
    
    def unpack_data(self):
        if hasattr(self, 'data_format') and hasattr(self, 'data_struct'):
            return self.data_struct._make(self.data_format.unpack(self.payload))
        return None
    
    def __repr__(self):
        return """<rtattr datalen=%d rta_type=%d data="%s">""" % (

# Path: shapy/framework/utils.py
# def align(l, alignto=4):
#     """Aligned length to nearest multiple of 4."""
#     return (l + alignto - 1) & ~(alignto - 1)
# 
# class InterpreterMixin(object):
#     interpreters = {}
#     
#     @classmethod
#     def register(cls, interpreter, content_types):
#         for type in content_types:
#             cls.interpreters.update({type: interpreter})
#     
#     @classmethod
#     def select(cls, selector):
#         """Selects interpreter object based on the selector."""
#         return cls.interpreters[selector]


# Path: shapy/framework/netlink/message.py
import quopri, binascii
import struct
from struct import Struct
from shapy.framework.utils import align, InterpreterMixin
from .constants import *

    #};
    
    rtattr = Struct('HH')
    
    @classmethod
    def unpack(cls, data):
        length, type = cls.rtattr.unpack(data[:cls.rtattr.size])
        data_len = length-cls.rtattr.size
        attr_data = struct.unpack('{0}s'.format(data_len),
                             data[cls.rtattr.size:cls.rtattr.size+data_len])[0]
        return cls(type, attr_data), data[align(length):]
    
    def __init__(self, rta_type, payload):
        self.rta_type = rta_type
        self.payload = payload
        self.data = self.unpack_data()
        
    def pack(self):
        data = struct.pack('{0}s'.format(len(self.payload)), self.payload)
        rta_len = self.rtattr.size+len(data)
        return struct.pack('{0}{1}s'.format(self.rtattr.format, align(len(data))),
                           rta_len, self.rta_type, data)
    
    def unpack_data(self):
        if hasattr(self, 'data_format') and hasattr(self, 'data_struct'):
            return self.data_struct._make(self.data_format.unpack(self.payload))
        return None
    
    def __repr__(self):
        return """<rtattr datalen=%d rta_type=%d data="%s">""" % (

            align(len(self.payload)), self.rta_type,