From 670a916183816a3b044f07f09e52f54810c2996a Mon Sep 17 00:00:00 2001 From: Marco Pesenti Gritti Date: Fri, 5 May 2006 15:39:17 -0400 Subject: [PATCH] Merge --- chat/network.py | 38 ++++++++++++++++++++++++++++++++++++++ chat/p2p.py | 8 +++++--- 2 files changed, 43 insertions(+), 3 deletions(-) diff --git a/chat/network.py b/chat/network.py index dc80a943..011c92fc 100644 --- a/chat/network.py +++ b/chat/network.py @@ -75,6 +75,44 @@ class GlibXMLRPCServer(GlibTCPServer, SimpleXMLRPCServer.SimpleXMLRPCDispatcher) SimpleXMLRPCServer.SimpleXMLRPCDispatcher.__init__(self) GlibTCPServer.__init__(self, addr, requestHandler) + def _marshaled_dispatch(self, data, dispatch_method = None): + """Dispatches an XML-RPC method from marshalled (XML) data. + + XML-RPC methods are dispatched from the marshalled (XML) data + using the _dispatch method and the result is returned as + marshalled data. For backwards compatibility, a dispatch + function can be provided as an argument (see comment in + SimpleXMLRPCRequestHandler.do_POST) but overriding the + existing method through subclassing is the prefered means + of changing method dispatch behavior. + """ + + params, method = xmlrpclib.loads(data) + + # generate response + try: + if dispatch_method is not None: + response = dispatch_method(method, params) + else: + response = self._dispatch(method, params) + # wrap response in a singleton tuple + response = (response,) + response = xmlrpclib.dumps(response, methodresponse=1) + except Fault, fault: + response = xmlrpclib.dumps(fault) + except: + set = sys.exc_type + sev = sys.exc_value + ser = sys.exc_traceback + + # report exception back to server + response = xmlrpclib.dumps(xmlrpclib.Fault(1, "%s:%s" % (set, sev))) + + print "Exception while processing request:" + traceback.print_exception(set, sev, ser) + + return response + class GroupChatController(object): diff --git a/chat/p2p.py b/chat/p2p.py index 381180b1..2a91beee 100644 --- a/chat/p2p.py +++ b/chat/p2p.py @@ -2,6 +2,7 @@ import os import pwd import xmlrpclib import socket +import traceback import presence import BuddyList @@ -14,7 +15,6 @@ class GroupRequestHandler(object): def message(self, message): address = network.get_authinfo() self._group.recv(address[0], message) - return True class Owner: instance = None @@ -93,9 +93,11 @@ class Group: peer = xmlrpclib.ServerProxy(addr) success = True try: + print self._serialize_msg(pipe_id, msg) peer.message(self._serialize_msg(pipe_id, msg)) - except (socket.error, xmlrpclib.Fault), e: - print str(e) + except (socket.error, xmlrpclib.Fault, xmlrpclib.ProtocolError), e: + print "Message Send Error:" + traceback.print_exc() success = False return success