Beispiel #1
0
	def respondToPost(self, transaction):
		"""
		This is similar to the xmlrpcserver.py example from the xmlrpc
		library distribution, only it's been adapted to work within a
		WebKit servlet.
		"""
		try:
			# get arguments
			data = transaction.request().rawInput(rewind=1).read()
			encoding = _getXmlDeclAttr(data, "encoding")
			params, method = xmlrpclib.loads(data)

			# generate response
			try:
				# This first test helps us to support PythonWin, which uses
				# repeated calls to __methods__.__getitem__ to determine the
				# allowed methods of an object.
				if method == '__methods__.__getitem__':
					response = self.exposedMethods()[params[0]]
				else:
					response = self.call(method, *params)
				if type(response) != type(()):
					response = (response,)
			except xmlrpclib.Fault, fault:
				response = xmlrpclib.dumps(fault, encoding=encoding,
					allow_none=self.allow_none)
				self.sendOK('text/xml', response, transaction)
				self.handleException(transaction)
			except Exception, e:
				fault = self.resultForException(e, transaction)
				response = xmlrpclib.dumps(xmlrpclib.Fault(1, fault),
					encoding=encoding, allow_none=self.allow_none)
				self.sendOK('text/xml', response, transaction)
				self.handleException(transaction)
    def respondToPost(self, transaction):
        """
		This is similar to the xmlrpcserver.py example from the xmlrpc
		library distribution, only it's been adapted to work within a
		WebKit servlet.
		"""
        try:
            # get arguments
            data = transaction.request().rawInput(rewind=1).read()
            encoding = _getXmlDeclAttr(data, "encoding")
            params, method = xmlrpclib.loads(data)

            # generate response
            try:
                # This first test helps us to support PythonWin, which uses
                # repeated calls to __methods__.__getitem__ to determine the
                # allowed methods of an object.
                if method == '__methods__.__getitem__':
                    response = self.exposedMethods()[params[0]]
                else:
                    response = self.call(method, *params)
                if type(response) != type(()):
                    response = (response, )
            except Exception, e:
                fault = self.resultForException(e, transaction)
                response = xmlrpclib.dumps(xmlrpclib.Fault(1, fault),
                                           encoding=encoding)
                self.sendOK('text/xml', response, transaction)
                self.handleException(transaction)
            except:  # if it's a string exception, this gets triggered
                fault = self.resultForException(sys.exc_info()[0], transaction)
                response = xmlrpclib.dumps(xmlrpclib.Fault(1, fault),
                                           encoding=encoding)
                self.sendOK('text/xml', response, transaction)
                self.handleException(transaction)
            else:
                response = xmlrpclib.dumps(response,
                                           methodresponse=1,
                                           encoding=encoding)
                self.sendOK('text/xml', response, transaction)
Beispiel #3
0
				if type(response) != type(()):
					response = (response,)
			except xmlrpclib.Fault, fault:
				response = xmlrpclib.dumps(fault, encoding=encoding,
					allow_none=self.allow_none)
				self.sendOK('text/xml', response, transaction)
				self.handleException(transaction)
			except Exception, e:
				fault = self.resultForException(e, transaction)
				response = xmlrpclib.dumps(xmlrpclib.Fault(1, fault),
					encoding=encoding, allow_none=self.allow_none)
				self.sendOK('text/xml', response, transaction)
				self.handleException(transaction)
			except:  # if it's a string exception, this gets triggered
				fault = self.resultForException(sys.exc_info()[0], transaction)
				response = xmlrpclib.dumps(xmlrpclib.Fault(1, fault),
					encoding=encoding, allow_none=self.allow_none)
				self.sendOK('text/xml', response, transaction)
				self.handleException(transaction)
			else:
				response = xmlrpclib.dumps(response, methodresponse=1,
					encoding=encoding, allow_none=self.allow_none)
				self.sendOK('text/xml', response, transaction)
		except Exception:
			# internal error, report as HTTP server error
			print 'XMLRPCServlet internal error'
			print ''.join(traceback.format_exception(
				sys.exc_info()[0], sys.exc_info()[1], sys.exc_info()[2]))
			transaction.response().setStatus(500, 'Server Error')
			self.handleException(transaction)