# Path: nudge/publisher.py
# def lazyprop(fn):
#     def _lazyprop(self):
# def Args(*args, **kwargs):
#     def __init__(self, name=None, method=None, uri=None, uris=None,
#                  function=None, args=None, renderer=None):
#     def match(self, reqline):
#     def __call__(self, *args, **kwargs):
# def _write(req, content):
#     def __init__(self, *args, **kwargs):
#     def __getitem__(self, key):
#     def __setitem__(self, key, value):
#     def get(self, key, default=None):
#     def set(self, key, value):
#     def normalize_name(n):
#     def __init__(self, req_dict):
#     def path(self):
#     def uri(self):
#     def headers(self):
#     def cookies(self):
#     def arguments(self):
#     def write(self, content):
#     def request_time(self):
# def redirect(uri, headers=None):
#     def __init__(self, fallbackapp=None, endpoints=None,
#                  debug=False, options=None, default_error_handler=None):
#     def verify_options(self):
#     def add_endpoint(self, endpoint):
#     def _add_args(self, req):
#     def __call__(self, environ, start_response):
# def _finish_request(req, start_response, code, content_type, content, headers):
# def _gen_trace_str(f, args, kwargs, res):
# def _generate_headers(version, status_code, content_length, headers={}):
# def serve(service_description, args=None):
# class Endpoint(object):
# class WSGIHeaders(dict):
# class WSGIRequest(object):
# class ServicePublisher(object):
# 
# Path: nudge/renderer.py
# class Result(object):
#     def __init__(self, content, content_type, http_status=200, headers=None):
#         self.content = content
#         self.content_type = content_type
#         self.http_status = http_status
#         if not headers:
#             headers = {}
#         self.headers = headers


import datetime
import time
import unittest
import urlparse
import StringIO
import nudge.validator 
import nudge.arg as args
import nudge.json as json
import httplib
from nudge.publisher import ServicePublisher, Endpoint, Args, WSGIRequest,\
    HTTPException, responses
from nudge.renderer import Result
from nose.tools import raises
from test_publisher import create_req, MockResponse, response_buf
            method='GET', 
            uri='/location', 
            function=handler,
        ))
        req = create_req('GET', '/location')
        resp = MockResponse(req, 500)
        result = sp(req, resp.start_response)
        resp.write(result)
        self.assertEqual(req._buffer, response_buf(
            http_status=500,
            content="An error occured",
            content_type="text/plain",
        ))

    def test_default_exp_handler_with_call(self):
        """ Test default exception handler with a callable that will change
            message. """
        class TestExpHandler(object):
            code = 500
            content_type = "text/plain"
            content = "An error occured"
            headers = {}
            def __call__(self, exp):
                return (self.code, self.content_type, exp.message, self.headers)

        def handler():
            raise Exception("New Message")
        
        sp = ServicePublisher(
                options={"default_error_handler": TestExpHandler})

# Path: nudge/publisher.py
# def lazyprop(fn):
#     def _lazyprop(self):
# def Args(*args, **kwargs):
#     def __init__(self, name=None, method=None, uri=None, uris=None,
#                  function=None, args=None, renderer=None):
#     def match(self, reqline):
#     def __call__(self, *args, **kwargs):
# def _write(req, content):
#     def __init__(self, *args, **kwargs):
#     def __getitem__(self, key):
#     def __setitem__(self, key, value):
#     def get(self, key, default=None):
#     def set(self, key, value):
#     def normalize_name(n):
#     def __init__(self, req_dict):
#     def path(self):
#     def uri(self):
#     def headers(self):
#     def cookies(self):
#     def arguments(self):
#     def write(self, content):
#     def request_time(self):
# def redirect(uri, headers=None):
#     def __init__(self, fallbackapp=None, endpoints=None,
#                  debug=False, options=None, default_error_handler=None):
#     def verify_options(self):
#     def add_endpoint(self, endpoint):
#     def _add_args(self, req):
#     def __call__(self, environ, start_response):
# def _finish_request(req, start_response, code, content_type, content, headers):
# def _gen_trace_str(f, args, kwargs, res):
# def _generate_headers(version, status_code, content_length, headers={}):
# def serve(service_description, args=None):
# class Endpoint(object):
# class WSGIHeaders(dict):
# class WSGIRequest(object):
# class ServicePublisher(object):
# 
# Path: nudge/renderer.py
# class Result(object):
#     def __init__(self, content, content_type, http_status=200, headers=None):
#         self.content = content
#         self.content_type = content_type
#         self.http_status = http_status
#         if not headers:
#             headers = {}
#         self.headers = headers


# Path: tests/test_exceptions.py
import datetime
import time
import unittest
import urlparse
import StringIO
import nudge.validator 
import nudge.arg as args
import nudge.json as json
import httplib
from nudge.publisher import ServicePublisher, Endpoint, Args, WSGIRequest,\
    HTTPException, responses
from nudge.renderer import Result
from nose.tools import raises
from test_publisher import create_req, MockResponse, response_buf

            method='GET', 
            uri='/location', 
            function=handler,
        ))
        req = create_req('GET', '/location')
        resp = MockResponse(req, 500)
        result = sp(req, resp.start_response)
        resp.write(result)
        self.assertEqual(req._buffer, response_buf(
            http_status=500,
            content="An error occured",
            content_type="text/plain",
        ))

    def test_default_exp_handler_with_call(self):
        """ Test default exception handler with a callable that will change
            message. """
        class TestExpHandler(object):
            code = 500
            content_type = "text/plain"
            content = "An error occured"
            headers = {}
            def __call__(self, exp):
                return (self.code, self.content_type, exp.message, self.headers)

        def handler():
            raise Exception("New Message")
        
        sp = ServicePublisher(
                options={"default_error_handler": TestExpHandler})

        sp.add_endpoint(Endpoint(