def __call__(self, environ, start_response):
        request = HttpRequest(environ)
        response = None
        
        view, args = self.routes.get_view(environ['PATH_INFO'])
        if view:
            if hasattr(view, '__call__'):
                to_call = view
            else:
                # TODO: do this better
                to_call = eval(view)
            try:
                response = to_call(request, **args)
            except Exception, error:
                # either the function failed, or it doesn't exist
                # TODO: log missing functions
                try:
                    # see if there's a user-defined error route
                    response = error500(request, error)
                except NameError:
                    # custom 500 function missing, return generic
                    msg = '<h1>500 Error</h1><pre>%s</pre>' % error
                    response = HttpResponse(msg, status_code=500)
                except Exception, e:
                    # custom 500 function there, but broken
                    msg = '<h1>500 Error</h1><pre>%s</pre>' % e
                    response = HttpResponse(msg, status_code=500)
        
        if not isinstance(response, HttpResponse):
            try:
                response = error404(request)
            except Exception, e:
                response = HttpResponse('<h1>Page Not Found</h1>', status_code=404)
        start_response(response.status, response.get_headers())
        return response.content
dataset/ETHPy150Open bradwright/mnml/mnml.py/WebApplication.__call__/original