# Path: python/beng_proxy/translation/serialize.py
# def packet_header(command, length=0):
#     """Generate the header of a translation packet."""
# 
#     assert length <= 0xffff
#     return struct.pack('HH', length, command)


import six
import array, struct
    from urllib.parse import urlparse
    from urlparse import urlparse
from .protocol import *
from .serialize import packet_header
            from socket import gethostbyname
            from socket import gethostbyname
    """Generator for a translation response.  The BEGIN and END
    packets are generated automatically.  When you are done with the
    response, call finish().  This method returns the full response
    (all serialized packets) as a string."""

    def __init__(self, protocol_version=0):
        assert isinstance(protocol_version, int)
        assert protocol_version >= 0
        assert protocol_version <= 0xff

        self._data = b''

        payload = b''
        if protocol_version > 0:
            payload = struct.pack('B', protocol_version)
        self.packet(TRANSLATE_BEGIN, payload)

    def finish(self):
        """Finish the response, and return it as a string."""
        self._data += packet_header(TRANSLATE_END)
        return self._data

    def packet(self, command, payload = b''):
        """Append a packet."""

        # this automatic conversion allows passing a `str` payload in
        # Python 3
        payload = six.ensure_binary(payload)

        assert isinstance(payload, bytes)

# Path: python/beng_proxy/translation/serialize.py
# def packet_header(command, length=0):
#     """Generate the header of a translation packet."""
# 
#     assert length <= 0xffff
#     return struct.pack('HH', length, command)


# Path: python/beng_proxy/translation/response.py
import six
import array, struct
    from urllib.parse import urlparse
    from urlparse import urlparse
from .protocol import *
from .serialize import packet_header
            from socket import gethostbyname
            from socket import gethostbyname

    """Generator for a translation response.  The BEGIN and END
    packets are generated automatically.  When you are done with the
    response, call finish().  This method returns the full response
    (all serialized packets) as a string."""

    def __init__(self, protocol_version=0):
        assert isinstance(protocol_version, int)
        assert protocol_version >= 0
        assert protocol_version <= 0xff

        self._data = b''

        payload = b''
        if protocol_version > 0:
            payload = struct.pack('B', protocol_version)
        self.packet(TRANSLATE_BEGIN, payload)

    def finish(self):
        """Finish the response, and return it as a string."""
        self._data += packet_header(TRANSLATE_END)
        return self._data

    def packet(self, command, payload = b''):
        """Append a packet."""

        # this automatic conversion allows passing a `str` payload in
        # Python 3
        payload = six.ensure_binary(payload)

        assert isinstance(payload, bytes)

        self._data += packet_header(command, len(payload))