import msgpack
import logging


class MessageFormatError(Exception):
    def __init__(self, value):
        self.value = value

    def __str__(self):
        return repr(self.value)


class Request(object):
    """Handler objects for frontend->backend objects messages"""
    def __init__(self, raw_message, compressed=False):
        errors_logger = logging.getLogger("errors_logger")
        message = msgpack.unpackb(raw_message)
        try:
            self.db_uid = message.pop('DB_UID')
            self.command = message.pop('COMMAND')
            self.data = message.pop('ARGS')
        except KeyError:
            errors_logger.exception("Invalid request message : %s" %
                                    message)
            raise MessageFormatError("Invalid request message")


class Response(tuple):
    """Handler objects for frontend->backend objects messages"""
    def __new__(cls, id, *args, **kwargs):
        response = {
            'STATUS': kwargs.pop('status', 0),
            'DATAS': kwargs.pop('datas', [])
        }

        response['DATAS'] = cls._format_datas(response['DATAS'])
        msg = [id, msgpack.packb(response)]
        return tuple.__new__(cls, msg)

    @classmethod
    def _format_datas(cls, datas):
        if datas and not isinstance(datas, (tuple, list)):
            datas = [datas]
        return [unicode(d) for d in datas]


import msgpack
import logging


class MessageFormatError(Exception):
    def __init__(self, value):
        self.value = value

    def __str__(self):
        return repr(self.value)


class Request(object):
    """Handler objects for frontend->backend objects messages"""
    def __init__(self, raw_message, compressed=False):
        errors_logger = logging.getLogger("errors_logger")
        message = msgpack.unpackb(raw_message)
        try:
            self.db_uid = message.pop('DB_UID')
            self.command = message.pop('COMMAND')
            self.data = message.pop('ARGS')
        except KeyError:
            errors_logger.exception("Invalid request message : %s" %
                                    message)
            raise MessageFormatError("Invalid request message")


class Response(tuple):
    """Handler objects for frontend->backend objects messages"""
    def __new__(cls, id, *args, **kwargs):
        response = {
            'STATUS': kwargs.pop('status', 0),
            'DATAS': kwargs.pop('datas', [])
        }

        response['DATAS'] = cls._format_datas(response['DATAS'])
        msg = [id, msgpack.packb(response)]
        return tuple.__new__(cls, msg)

    @classmethod
    def _format_datas(cls, datas):
        if datas and not isinstance(datas, (tuple, list)):
            datas = [datas]
        return datas

Fix : response datas list should not be unicoded
Fix : response datas list should not be unicoded

  import msgpack
  import logging
  
  
  class MessageFormatError(Exception):
      def __init__(self, value):
          self.value = value
  
      def __str__(self):
          return repr(self.value)
  
  
  class Request(object):
      """Handler objects for frontend->backend objects messages"""
      def __init__(self, raw_message, compressed=False):
          errors_logger = logging.getLogger("errors_logger")
          message = msgpack.unpackb(raw_message)
          try:
              self.db_uid = message.pop('DB_UID')
              self.command = message.pop('COMMAND')
              self.data = message.pop('ARGS')
          except KeyError:
              errors_logger.exception("Invalid request message : %s" %
                                      message)
              raise MessageFormatError("Invalid request message")
  
  
  class Response(tuple):
      """Handler objects for frontend->backend objects messages"""
      def __new__(cls, id, *args, **kwargs):
          response = {
              'STATUS': kwargs.pop('status', 0),
              'DATAS': kwargs.pop('datas', [])
          }
  
          response['DATAS'] = cls._format_datas(response['DATAS'])
          msg = [id, msgpack.packb(response)]
          return tuple.__new__(cls, msg)
  
      @classmethod
      def _format_datas(cls, datas):
          if datas and not isinstance(datas, (tuple, list)):
              datas = [datas]
-         return [unicode(d) for d in datas]
+         return datas
  
- 
Fix : response datas list should not be unicoded
## Code Before:
import msgpack
import logging


class MessageFormatError(Exception):
    def __init__(self, value):
        self.value = value

    def __str__(self):
        return repr(self.value)


class Request(object):
    """Handler objects for frontend->backend objects messages"""
    def __init__(self, raw_message, compressed=False):
        errors_logger = logging.getLogger("errors_logger")
        message = msgpack.unpackb(raw_message)
        try:
            self.db_uid = message.pop('DB_UID')
            self.command = message.pop('COMMAND')
            self.data = message.pop('ARGS')
        except KeyError:
            errors_logger.exception("Invalid request message : %s" %
                                    message)
            raise MessageFormatError("Invalid request message")


class Response(tuple):
    """Handler objects for frontend->backend objects messages"""
    def __new__(cls, id, *args, **kwargs):
        response = {
            'STATUS': kwargs.pop('status', 0),
            'DATAS': kwargs.pop('datas', [])
        }

        response['DATAS'] = cls._format_datas(response['DATAS'])
        msg = [id, msgpack.packb(response)]
        return tuple.__new__(cls, msg)

    @classmethod
    def _format_datas(cls, datas):
        if datas and not isinstance(datas, (tuple, list)):
            datas = [datas]
        return [unicode(d) for d in datas]


## Instruction:
Fix : response datas list should not be unicoded
## Code After:
import msgpack
import logging


class MessageFormatError(Exception):
    def __init__(self, value):
        self.value = value

    def __str__(self):
        return repr(self.value)


class Request(object):
    """Handler objects for frontend->backend objects messages"""
    def __init__(self, raw_message, compressed=False):
        errors_logger = logging.getLogger("errors_logger")
        message = msgpack.unpackb(raw_message)
        try:
            self.db_uid = message.pop('DB_UID')
            self.command = message.pop('COMMAND')
            self.data = message.pop('ARGS')
        except KeyError:
            errors_logger.exception("Invalid request message : %s" %
                                    message)
            raise MessageFormatError("Invalid request message")


class Response(tuple):
    """Handler objects for frontend->backend objects messages"""
    def __new__(cls, id, *args, **kwargs):
        response = {
            'STATUS': kwargs.pop('status', 0),
            'DATAS': kwargs.pop('datas', [])
        }

        response['DATAS'] = cls._format_datas(response['DATAS'])
        msg = [id, msgpack.packb(response)]
        return tuple.__new__(cls, msg)

    @classmethod
    def _format_datas(cls, datas):
        if datas and not isinstance(datas, (tuple, list)):
            datas = [datas]
        return datas
