# Path: motorway/utils.py
# class DateTimeAwareJsonEncoder(JSONEncoder):
#     def default(self, o):
#         if type(o) == datetime.timedelta:
#             return duration_isoformat(o)
#         elif type(o) == datetime.datetime:
#             return datetime_isoformat(o)
#         elif isinstance(o, decimal.Decimal):
#             return float(o)
#         return super(DateTimeAwareJsonEncoder, self).default(o)


import json
import traceback
import uuid
import datetime
import logging
from isodate import duration_isoformat
from motorway.utils import DateTimeAwareJsonEncoder
        """
        return cls(ramp_unique_id=message.ramp_unique_id, content=content, grouping_value=grouping_value,
                   error_message=error_message, producer_uuid=message.producer_uuid)

    @classmethod
    def from_message(cls, message, controller_queue, process_name=None):
        """

        :param message: Message dict (converted from JSON)
        :param controller_queue:
        :param process_name: UUID of the process processing this message (as string)
        :return:
        """
        # assert type(message) is dict, "message (%s) should be dict" % message
        if type(message) is not dict:
            logging.error("Expected type dict, got type %s - message: %s", type(message), message)
        message['process_name'] = process_name
        # assert 'producer_uuid' in message, "missing uuid %s" % message
        return cls(controller_queue=controller_queue, **message)

    def _message(self):
        return {
            'content': self.content,
            'ramp_unique_id': self.ramp_unique_id,
            'ack_value': self.ack_value,
            'grouping_value': self.grouping_value,
            'producer_uuid': self.producer_uuid
        }

    def as_json(self):

# Path: motorway/utils.py
# class DateTimeAwareJsonEncoder(JSONEncoder):
#     def default(self, o):
#         if type(o) == datetime.timedelta:
#             return duration_isoformat(o)
#         elif type(o) == datetime.datetime:
#             return datetime_isoformat(o)
#         elif isinstance(o, decimal.Decimal):
#             return float(o)
#         return super(DateTimeAwareJsonEncoder, self).default(o)


# Path: motorway/messages.py
import json
import traceback
import uuid
import datetime
import logging
from isodate import duration_isoformat
from motorway.utils import DateTimeAwareJsonEncoder

        """
        return cls(ramp_unique_id=message.ramp_unique_id, content=content, grouping_value=grouping_value,
                   error_message=error_message, producer_uuid=message.producer_uuid)

    @classmethod
    def from_message(cls, message, controller_queue, process_name=None):
        """

        :param message: Message dict (converted from JSON)
        :param controller_queue:
        :param process_name: UUID of the process processing this message (as string)
        :return:
        """
        # assert type(message) is dict, "message (%s) should be dict" % message
        if type(message) is not dict:
            logging.error("Expected type dict, got type %s - message: %s", type(message), message)
        message['process_name'] = process_name
        # assert 'producer_uuid' in message, "missing uuid %s" % message
        return cls(controller_queue=controller_queue, **message)

    def _message(self):
        return {
            'content': self.content,
            'ramp_unique_id': self.ramp_unique_id,
            'ack_value': self.ack_value,
            'grouping_value': self.grouping_value,
            'producer_uuid': self.producer_uuid
        }

    def as_json(self):

        return json.dumps(self._message(), cls=DateTimeAwareJsonEncoder)