def __init__(self):
     self.browser = webbrowser.get()
     self.handlers = [get_callable(callable) for callable in settings.AJAXERRORS_ADDITIONAL_HANDLERS]
     self.directory = os.path.join(tempfile.gettempdir(), 'ajax-errors')
     if not os.path.isdir(self.directory):
         with altered_umask(0):
             os.mkdir(self.directory, 01777)
    def process_exception(self, request, exception):
        if not request.is_ajax():
            return None

        if not settings.DEBUG and settings.AJAXERRORS_DO_NOTHING_UNLESS_IN_DEBUG:
            return None

        token = '%032x' % (randint(0, 2**128),)
        with altered_umask(0077):
            with file(os.path.join(self.directory, token), 'w') as handle:
                pickle.dump(technical_500_response(request, *sys.exc_info()), handle)
        self.browser.open(request.build_absolute_uri(location=settings.AJAXERRORS_PATH + '?token=' + token),
                          **settings.AJAXERRORS_WEBBROWSER_OPEN_KWARGS)

        response = None
        for handler in self.handlers:
            handler_response = handler(request, *sys.exc_info())
            if handler_response is not None:
                response = handler_response
        return response