Fix some spacing issues; catch exceptions in XMLRPC client code and return result status (success or failure) to XMLRPC client callback
This commit is contained in:
parent
89f9730641
commit
a7a0c2cda5
@ -19,6 +19,7 @@ from sugar.p2p import Buddy
|
|||||||
from sugar.p2p.Group import LocalGroup
|
from sugar.p2p.Group import LocalGroup
|
||||||
from sugar.p2p.Service import Service
|
from sugar.p2p.Service import Service
|
||||||
from sugar.p2p.Stream import Stream
|
from sugar.p2p.Stream import Stream
|
||||||
|
from sugar.p2p import network
|
||||||
from sugar.session.LogWriter import LogWriter
|
from sugar.session.LogWriter import LogWriter
|
||||||
from sugar.chat.sketchpad.Toolbox import Toolbox
|
from sugar.chat.sketchpad.Toolbox import Toolbox
|
||||||
from sugar.chat.sketchpad.SketchPad import SketchPad
|
from sugar.chat.sketchpad.SketchPad import SketchPad
|
||||||
@ -280,15 +281,15 @@ class Chat(activity.Activity):
|
|||||||
print "act %d: in activity_on_close_from_user" % self.activity_get_id()
|
print "act %d: in activity_on_close_from_user" % self.activity_get_id()
|
||||||
self.activity_shutdown()
|
self.activity_shutdown()
|
||||||
|
|
||||||
def _scroll_chat_view_to_bottom(self):
|
def _scroll_chat_view_to_bottom(self):
|
||||||
# Only scroll to bottom if the view is already close to the bottom
|
# Only scroll to bottom if the view is already close to the bottom
|
||||||
vadj = self._chat_sw.get_vadjustment()
|
vadj = self._chat_sw.get_vadjustment()
|
||||||
if vadj.value + vadj.page_size > vadj.upper * 0.8:
|
if vadj.value + vadj.page_size > vadj.upper * 0.8:
|
||||||
vadj.value = vadj.upper - vadj.page_size
|
vadj.value = vadj.upper - vadj.page_size
|
||||||
self._chat_sw.set_vadjustment(vadj)
|
self._chat_sw.set_vadjustment(vadj)
|
||||||
|
|
||||||
def _message_inserted(self):
|
def _message_inserted(self):
|
||||||
gobject.idle_add(self._scroll_chat_view_to_bottom)
|
gobject.idle_add(self._scroll_chat_view_to_bottom)
|
||||||
self.activity_set_has_changes(True)
|
self.activity_set_has_changes(True)
|
||||||
|
|
||||||
def _insert_buddy(self, buf, nick):
|
def _insert_buddy(self, buf, nick):
|
||||||
@ -399,6 +400,9 @@ class Chat(activity.Activity):
|
|||||||
|
|
||||||
def recv_message(self, buddy, msg):
|
def recv_message(self, buddy, msg):
|
||||||
"""Insert a remote chat message into the chat buffer."""
|
"""Insert a remote chat message into the chat buffer."""
|
||||||
|
if not buddy:
|
||||||
|
return
|
||||||
|
|
||||||
chunk = self._get_first_richtext_chunk(msg)
|
chunk = self._get_first_richtext_chunk(msg)
|
||||||
if chunk:
|
if chunk:
|
||||||
self._insert_rich_message(buddy.get_nick_name(), chunk)
|
self._insert_rich_message(buddy.get_nick_name(), chunk)
|
||||||
@ -597,14 +601,16 @@ class GroupChat(Chat):
|
|||||||
self._chats[buddy] = chat
|
self._chats[buddy] = chat
|
||||||
chat.activity_connect_to_shell()
|
chat.activity_connect_to_shell()
|
||||||
|
|
||||||
def _request_buddy_icon_cb(self, response, user_data):
|
def _request_buddy_icon_cb(self, result_status, response, user_data):
|
||||||
icon = response
|
icon = response
|
||||||
buddy = user_data
|
buddy = user_data
|
||||||
if icon and len(icon):
|
if result_status == network.RESULT_SUCCESS:
|
||||||
icon = base64.b64decode(icon)
|
if icon and len(icon):
|
||||||
print "Buddy icon for '%s' is size %d" % (buddy.get_nick_name(), len(icon))
|
icon = base64.b64decode(icon)
|
||||||
buddy.set_icon(icon)
|
print "Buddy icon for '%s' is size %d" % (buddy.get_nick_name(), len(icon))
|
||||||
else:
|
buddy.set_icon(icon)
|
||||||
|
|
||||||
|
if result_status == network.RESULT_FAILED or not icon:
|
||||||
# What the heck, try again!
|
# What the heck, try again!
|
||||||
gobject.timeout_add(1000, self._request_buddy_icon, buddy)
|
gobject.timeout_add(1000, self._request_buddy_icon, buddy)
|
||||||
|
|
||||||
|
@ -10,6 +10,9 @@ import SimpleXMLRPCServer
|
|||||||
import SocketServer
|
import SocketServer
|
||||||
|
|
||||||
|
|
||||||
|
RESULT_FAILED = 0
|
||||||
|
RESULT_SUCCESS = 1
|
||||||
|
|
||||||
__authinfos = {}
|
__authinfos = {}
|
||||||
|
|
||||||
def _add_authinfo(authinfo):
|
def _add_authinfo(authinfo):
|
||||||
@ -176,7 +179,7 @@ class GlibXMLRPCTransport(xmlrpclib.Transport):
|
|||||||
if request_cb:
|
if request_cb:
|
||||||
if len(response) == 1:
|
if len(response) == 1:
|
||||||
response = response[0]
|
response = response[0]
|
||||||
gobject.idle_add(request_cb, response, user_data)
|
gobject.idle_add(request_cb, RESULT_SUCCESS, response, user_data)
|
||||||
|
|
||||||
class _Method:
|
class _Method:
|
||||||
"""Right, so python people thought it would be funny to make this
|
"""Right, so python people thought it would be funny to make this
|
||||||
@ -209,7 +212,7 @@ class GlibServerProxy(xmlrpclib.ServerProxy):
|
|||||||
Here, 'xmlrpc_test_cb' is the callback function, which has the following
|
Here, 'xmlrpc_test_cb' is the callback function, which has the following
|
||||||
signature:
|
signature:
|
||||||
|
|
||||||
def xmlrpc_test_cb(response, user_data=None):
|
def xmlrpc_test_cb(result_status, response, user_data=None):
|
||||||
...
|
...
|
||||||
"""
|
"""
|
||||||
def __init__(self, uri, encoding=None, verbose=0, allow_none=0):
|
def __init__(self, uri, encoding=None, verbose=0, allow_none=0):
|
||||||
@ -236,14 +239,17 @@ class GlibServerProxy(xmlrpclib.ServerProxy):
|
|||||||
request = xmlrpclib.dumps(params, methodname, encoding=self._encoding,
|
request = xmlrpclib.dumps(params, methodname, encoding=self._encoding,
|
||||||
allow_none=self._allow_none)
|
allow_none=self._allow_none)
|
||||||
|
|
||||||
response = self._transport.start_request(
|
try:
|
||||||
self._host,
|
response = self._transport.start_request(
|
||||||
self._handler,
|
self._host,
|
||||||
request,
|
self._handler,
|
||||||
verbose=self._verbose,
|
request,
|
||||||
request_cb=request_cb,
|
verbose=self._verbose,
|
||||||
user_data=user_data
|
request_cb=request_cb,
|
||||||
)
|
user_data=user_data
|
||||||
|
)
|
||||||
|
except socket.error, exc:
|
||||||
|
gobject.idle_add(request_cb, RESULT_FAILED, None, user_data)
|
||||||
|
|
||||||
def __getattr__(self, name):
|
def __getattr__(self, name):
|
||||||
# magic method dispatcher
|
# magic method dispatcher
|
||||||
|
Loading…
Reference in New Issue
Block a user