# Path: utils.py
# class ProtocolViolation(Exception):
#     """Indicates that the communication protocol between this and a remote
#     client has been violated. In this case we abort from the communication."""
#     def __init__(self, reason="unknown"):
#         self.reason = reason
#     def __repr__(self):
#         return "ProtocolViolation(%s)"%self.reason


from utils import ProtocolViolation
from socket import inet_ntoa, inet_aton
import struct
        self = cls.__new__(cls)
        for (field, type) in self.bfields:
            obj, bdata = type.frombinary(bdata)
            self.__setattr__(field, obj)
        if rest:
            return self, bdata
        else:
            if bdata != "":
                raise ProtocolViolation()
            else:
                return self
def structfmt(fmt):
    """Produce a serialization object for a value understood by struct.
e.g. structfmt("<I") for 4-byte integers"""
    fmtsize = struct.calcsize(fmt)
    class _():
        @staticmethod
        def tobinary(obj):
            return struct.pack(fmt, obj)
        @staticmethod
        def frombinary(bdata):
            try:
                return struct.unpack(fmt, bdata[:fmtsize])[0], bdata[fmtsize:]
            except struct.error:
                raise ProtocolViolation()
    return _

class Str():
    @staticmethod
    def tobinary(obj):

# Path: utils.py
# class ProtocolViolation(Exception):
#     """Indicates that the communication protocol between this and a remote
#     client has been violated. In this case we abort from the communication."""
#     def __init__(self, reason="unknown"):
#         self.reason = reason
#     def __repr__(self):
#         return "ProtocolViolation(%s)"%self.reason


# Path: bserialize.py
from utils import ProtocolViolation
from socket import inet_ntoa, inet_aton
import struct

        self = cls.__new__(cls)
        for (field, type) in self.bfields:
            obj, bdata = type.frombinary(bdata)
            self.__setattr__(field, obj)
        if rest:
            return self, bdata
        else:
            if bdata != "":
                raise ProtocolViolation()
            else:
                return self
def structfmt(fmt):
    """Produce a serialization object for a value understood by struct.
e.g. structfmt("<I") for 4-byte integers"""
    fmtsize = struct.calcsize(fmt)
    class _():
        @staticmethod
        def tobinary(obj):
            return struct.pack(fmt, obj)
        @staticmethod
        def frombinary(bdata):
            try:
                return struct.unpack(fmt, bdata[:fmtsize])[0], bdata[fmtsize:]
            except struct.error:
                raise ProtocolViolation()
    return _

class Str():
    @staticmethod
    def tobinary(obj):

        return obj.encode("ascii") + '\0'