# Path: pyroutes/http/response.py
# class Response(object):
#     """
#     A wrapper class for a response to a route. Takes
#     a content, headers and status_code parameter.
#     headers should be passed in as a list of tuples.
#     status_code can be a string including status name, or an integer.
#     If default_content_header is set and no Content-Type header is set,
#     settings.DEFAULT_CONTENT_TYPE is added as Content-Type.
#     """
#     def __init__(self, content=None, headers=None, status_code='200 OK',
#             default_content_header=True):
#         if content is None:
#             self.content = []
#         else:
#             self.content = content
# 
#         header_names = []
#         if headers:
#             header_names = [header[0] for header in headers]
# 
#         self.headers = []
#         if default_content_header and 'Content-Type' not in header_names:
#             self.headers.append(('Content-Type', settings.DEFAULT_CONTENT_TYPE))
#         if not headers is None:
#             self.headers += headers
# 
#         if status_code in _RESPONSES:
#             self.status_code = "%s %s" % (status_code, _RESPONSES[status_code])
#         else:
#             self.status_code = status_code
# 
#         self.cookies = ResponseCookieHandler()


from pyroutes.http.response import Response
"""
Middleware for making non-response objects into Responses
"""


class Responsify(object):
    """
    If a non-response object s (e.g a string) is passed, returns Response(s)

    This allows e.g

        >>> @route('/')
        >>> def foo(request):
        >>>     return 'Hello, world!'

    or

        >>> bar = lambda x: 'Hello, lambda world!'
        >>> route('/')(bar)

    """
    def __init__(self, passthrough, route):
        self.passthrough = passthrough

    def __call__(self, request):
        response = self.passthrough(request)
        if not isinstance(response, Response):

# Path: pyroutes/http/response.py
# class Response(object):
#     """
#     A wrapper class for a response to a route. Takes
#     a content, headers and status_code parameter.
#     headers should be passed in as a list of tuples.
#     status_code can be a string including status name, or an integer.
#     If default_content_header is set and no Content-Type header is set,
#     settings.DEFAULT_CONTENT_TYPE is added as Content-Type.
#     """
#     def __init__(self, content=None, headers=None, status_code='200 OK',
#             default_content_header=True):
#         if content is None:
#             self.content = []
#         else:
#             self.content = content
# 
#         header_names = []
#         if headers:
#             header_names = [header[0] for header in headers]
# 
#         self.headers = []
#         if default_content_header and 'Content-Type' not in header_names:
#             self.headers.append(('Content-Type', settings.DEFAULT_CONTENT_TYPE))
#         if not headers is None:
#             self.headers += headers
# 
#         if status_code in _RESPONSES:
#             self.status_code = "%s %s" % (status_code, _RESPONSES[status_code])
#         else:
#             self.status_code = status_code
# 
#         self.cookies = ResponseCookieHandler()


# Path: pyroutes/middleware/responsify.py
from pyroutes.http.response import Response

"""
Middleware for making non-response objects into Responses
"""


class Responsify(object):
    """
    If a non-response object s (e.g a string) is passed, returns Response(s)

    This allows e.g

        >>> @route('/')
        >>> def foo(request):
        >>>     return 'Hello, world!'

    or

        >>> bar = lambda x: 'Hello, lambda world!'
        >>> route('/')(bar)

    """
    def __init__(self, passthrough, route):
        self.passthrough = passthrough

    def __call__(self, request):
        response = self.passthrough(request)
        if not isinstance(response, Response):

            response = Response(response)