# Path: transmute_core/exceptions.py
# class APIException(TransmuteCoreException):
#     """
#     this exception signifies an exception
#     with API
#     """
# 
#     def __init__(self, message, code=400):
#         """code can be overriden, to allow the proper status code."""
#         super(APIException, self).__init__(message)
#         self.code = code
# 
# class NoSerializerFound(TransmuteCoreException):
#     """
#     raised when a serializer does not exist to handle the
#     desired content type.
#     """
# 
# Path: transmute_core/function/response.py
# class Response(object):
#     result = attr.ib()
#     code = attr.ib(default=200)
#     headers = attr.ib(
#         validator=[attr.validators.instance_of(Mapping)], default=attr.Factory(dict)
#     )
#     success = attr.ib(validator=[attr.validators.instance_of(bool)], default=True)


import attr
from .exceptions import APIException, NoSerializerFound
from .function import Response
from six import reraise
"""
utilities to help with generating handlers.
"""


def process_result(transmute_func, context, result, exc, content_type):
    """
    process a result:

    transmute_func: the transmute_func function that returned the response.

    context: the transmute_context to use.

    result: the return value of the function, which will be serialized and
            returned back in the API.

    exc: the exception object. For Python 2, the traceback should
         be attached via the __traceback__ attribute. This is done automatically
         in Python 3.

    content_type: the content type that request is requesting for a return type.
                  (e.g. application/json)
    """
    if isinstance(result, Response):
        response = result
    else:

# Path: transmute_core/exceptions.py
# class APIException(TransmuteCoreException):
#     """
#     this exception signifies an exception
#     with API
#     """
# 
#     def __init__(self, message, code=400):
#         """code can be overriden, to allow the proper status code."""
#         super(APIException, self).__init__(message)
#         self.code = code
# 
# class NoSerializerFound(TransmuteCoreException):
#     """
#     raised when a serializer does not exist to handle the
#     desired content type.
#     """
# 
# Path: transmute_core/function/response.py
# class Response(object):
#     result = attr.ib()
#     code = attr.ib(default=200)
#     headers = attr.ib(
#         validator=[attr.validators.instance_of(Mapping)], default=attr.Factory(dict)
#     )
#     success = attr.ib(validator=[attr.validators.instance_of(bool)], default=True)


# Path: transmute_core/handler.py
import attr
from .exceptions import APIException, NoSerializerFound
from .function import Response
from six import reraise

"""
utilities to help with generating handlers.
"""


def process_result(transmute_func, context, result, exc, content_type):
    """
    process a result:

    transmute_func: the transmute_func function that returned the response.

    context: the transmute_context to use.

    result: the return value of the function, which will be serialized and
            returned back in the API.

    exc: the exception object. For Python 2, the traceback should
         be attached via the __traceback__ attribute. This is done automatically
         in Python 3.

    content_type: the content type that request is requesting for a return type.
                  (e.g. application/json)
    """
    if isinstance(result, Response):
        response = result
    else:

        response = Response(