# Path: zabby/core/exceptions.py
# class WrongArgumentError(Exception):
#     """ Wrong argument was passed to a function"""
# 
# Path: zabby/core/six.py
# def b(s):
#     return s.encode('utf-8')


import string
import struct
import logging
import sys
    import socketserver
    import SocketServer as socketserver
from zabby.core.exceptions import WrongArgumentError
from zabby.core.six import b
        Expects to receive header followed by the length of the key
        followed by the key.
        """
        received = client.recv(self.HEADER_LENGTH)
        if received == self.HEADER:
            expected_length = struct.unpack(
                'q', client.recv(self.EXPECTED_LENGTH_SIZE)
            )[0]
            key = client.recv(expected_length)
        else:
            if '\n' in received:
                key = received
            else:
                key = received + client.recv(self.MAX_KEY_LENGTH)
        return key.decode('utf-8')

    def send_value(self, client, value):
        """
        Formats value according to protocol and sends it to client
        """
        message = self._calculate_message(value)
        client.sendall(message)

    def _calculate_message(self, value):
        formatted_value = self._format(value)
        data_length = len(formatted_value)
        response = struct.pack(
            self.RESPONSE_FORMAT.format(data_length=data_length),
            self.HEADER,
            data_length,

# Path: zabby/core/exceptions.py
# class WrongArgumentError(Exception):
#     """ Wrong argument was passed to a function"""
# 
# Path: zabby/core/six.py
# def b(s):
#     return s.encode('utf-8')


# Path: zabby/agent.py
import string
import struct
import logging
import sys
    import socketserver
    import SocketServer as socketserver
from zabby.core.exceptions import WrongArgumentError
from zabby.core.six import b

        Expects to receive header followed by the length of the key
        followed by the key.
        """
        received = client.recv(self.HEADER_LENGTH)
        if received == self.HEADER:
            expected_length = struct.unpack(
                'q', client.recv(self.EXPECTED_LENGTH_SIZE)
            )[0]
            key = client.recv(expected_length)
        else:
            if '\n' in received:
                key = received
            else:
                key = received + client.recv(self.MAX_KEY_LENGTH)
        return key.decode('utf-8')

    def send_value(self, client, value):
        """
        Formats value according to protocol and sends it to client
        """
        message = self._calculate_message(value)
        client.sendall(message)

    def _calculate_message(self, value):
        formatted_value = self._format(value)
        data_length = len(formatted_value)
        response = struct.pack(
            self.RESPONSE_FORMAT.format(data_length=data_length),
            self.HEADER,
            data_length,

            b(formatted_value)