# 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 *
        return Message(type, flags, seq, service_template=st)
    
    def __init__(self, type, flags=0, seq=-1, service_template=None):
        """Used for creating Netlink messages."""
        self.type = type
        self.flags = flags
        self.seq = seq
        self.pid = 0
        self.service_template = service_template
        self.service_template.message = self

    def __len__(self):
        """Aligned length of service template message + attributes."""
        return align(self.nlmsghdr.size + len(self.payload))
    
    def pack_header(self):
        return self.nlmsghdr.pack(len(self), self.type, self.flags, self.seq, self.pid)

    def pack(self):
        return self.pack_header() + self.payload

    @property
    def payload(self):
        return self.service_template.pack()
    
    def __repr__(self):
        return '<netlink message type=%s, pid=%s, seq=%s, flags=0x%x>' % (
            self.type, self.pid, self.seq, self.flags)



# 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 *

        return Message(type, flags, seq, service_template=st)
    
    def __init__(self, type, flags=0, seq=-1, service_template=None):
        """Used for creating Netlink messages."""
        self.type = type
        self.flags = flags
        self.seq = seq
        self.pid = 0
        self.service_template = service_template
        self.service_template.message = self

    def __len__(self):
        """Aligned length of service template message + attributes."""
        return align(self.nlmsghdr.size + len(self.payload))
    
    def pack_header(self):
        return self.nlmsghdr.pack(len(self), self.type, self.flags, self.seq, self.pid)

    def pack(self):
        return self.pack_header() + self.payload

    @property
    def payload(self):
        return self.service_template.pack()
    
    def __repr__(self):
        return '<netlink message type=%s, pid=%s, seq=%s, flags=0x%x>' % (
            self.type, self.pid, self.seq, self.flags)



class ServiceTemplate(InterpreterMixin):