# 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
Each binary-serialization class has two methods tobinary() and frombinary().
The tobinary() method takes an object as its first argument and returns it as a
bytes object. The frombinary() method takes a bytestring as its first
argument and returns (obj, rest of bytestring).

Throws ProtocolViolation when fed junk.
"""



class Entity(object):
    def __init__(self, **kwargs):
        for k, v in kwargs.items():
            setattr(self, k, v)

    def tobinary(self):
        retval = b""
        for (field, type) in self.bfields:
            retval += type.tobinary(self.__getattribute__(field))
        return retval
    @classmethod
    def frombinary(cls, bdata, rest=True):
        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 != "":

# 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

Each binary-serialization class has two methods tobinary() and frombinary().
The tobinary() method takes an object as its first argument and returns it as a
bytes object. The frombinary() method takes a bytestring as its first
argument and returns (obj, rest of bytestring).

Throws ProtocolViolation when fed junk.
"""



class Entity(object):
    def __init__(self, **kwargs):
        for k, v in kwargs.items():
            setattr(self, k, v)

    def tobinary(self):
        retval = b""
        for (field, type) in self.bfields:
            retval += type.tobinary(self.__getattribute__(field))
        return retval
    @classmethod
    def frombinary(cls, bdata, rest=True):
        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()