예제 #1
0
def make_setup_error(exc_info=None):
    """Create a new SetupError for the last exception and log it."""
    if exc_info is None:
        exc_info = sys.exc_info()

    # log the exception
    log.exception(_(u'Plugin setup error'), 'pluginsystem', exc_info)
    exc_type, exc_value, tb = exc_info

    # if the exception is already a SetupError we only
    # have to return it unchanged.
    if isinstance(exc_value, SetupError):
        return exc_value

    # otherwise create an error message for it and return a new
    # exception.
    error, (filename, line) = summarize_exception(exc_info)
    return SetupError(_(u'Exception happend on setup: '
                        u'%(error)s (%(file)s, line %(line)d)') % {
        'error':    escape(error),
        'file':     filename,
        'line':     line
    })
예제 #2
0
파일: xml.py 프로젝트: jokey2k/pyClanSphere
        XML-RPC methods are dispatched from the marshalled (XML) data
        using the _dispatch method and the result is returned as
        marshalled data.
        """
        try:
            params, method = xmlrpclib.loads(data)
            response = xmlrpclib.dumps((self._wrap_obj(self._dispatch(method, params)),),
                                       methodresponse=True, allow_none=True,
                                       encoding=self.charset)
        except xmlrpclib.Fault, fault:
            response = xmlrpclib.dumps(fault, allow_none=self.allow_none,
                                       encoding=self.charset)
        except:
            exc_type, exc_value, tb = exc_info = sys.exc_info()
            log.exception('Exception in XMLRPC request:', 'xmlrpc', exc_info)
            response = xmlrpclib.dumps(
                xmlrpclib.Fault(1, '%s:%s' % (exc_type, exc_value)),
                encoding=self.charset, allow_none=self.allow_none
            )

        return response

    def handle_request(self, request):
        if request.method == 'POST':
            response = self._marshaled_dispatch(request.data)
            return BaseResponse(response, mimetype='application/xml')
        return BaseResponse('\n'.join((
            '<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 3.2 Final//EN">',
            '<title>XMLRPC Interface</title>',
            '<h1>XMLRPC Interface</h1>',