Ticket #2289: 0001-Register-widget-click-event-reflects-a-timeout-on-un.patch

File 0001-Register-widget-click-event-reflects-a-timeout-on-un.patch, 2.5 KB (added by dipankar, 9 years ago)
  • src/jarabe/desktop/schoolserver.py

    From a2cf4863eca617bcd57008730e13ab8af95e7cfa Mon Sep 17 00:00:00 2001
    From: Dipankar Patro <dipankar@seeta.in>
    Date: Mon, 6 Sep 2010 21:42:51 +0530
    Subject: [PATCH] Register widget click event reflects a timeout on unavailability of servers
    
    [Ticket #2289]
    The register widget when clicked, used to cause sugar to freeze.
    
    Added a timeout facilitated ServerProxy() so that connection to schoolserver
    is dropped in case it is not available.
    ---
     src/jarabe/desktop/schoolserver.py |   28 ++++++++++++++++++++++++++--
     1 files changed, 26 insertions(+), 2 deletions(-)
    
    diff --git a/src/jarabe/desktop/schoolserver.py b/src/jarabe/desktop/schoolserver.py
    index 62519df..e60e26f 100644
    a b  
    1616
    1717import logging
    1818from gettext import gettext as _
    19 from xmlrpclib import ServerProxy, Error
     19import httplib
     20import xmlrpclib
    2021import socket
    2122import os
    2223import string
    def store_identifiers(serial_number, uuid, backup_url): 
    7677class RegisterError(Exception):
    7778    pass
    7879
     80class TimeoutHTTP(httplib.HTTP):
     81   def __init__(self, host='', port=None, strict=None, timeout=socket._GLOBAL_DEFAULT_TIMEOUT):
     82        if port == 0:
     83            port = None
     84        self._setup(self._connection_class(host, port, strict, timeout))
     85
     86class TimeoutTransport(xmlrpclib.Transport):
     87    def __init__(self, timeout=socket._GLOBAL_DEFAULT_TIMEOUT, *args, **kwargs):
     88        xmlrpclib.Transport.__init__(self, *args, **kwargs)
     89        self.timeout = timeout
     90
     91    def make_connection(self, host):
     92        host, extra_headers, x509 = self.get_host_info(host)
     93        return TimeoutHTTP(host, timeout=self.timeout)
     94       
     95class TimeoutServerProxy(xmlrpclib.ServerProxy):
     96        """ Creates a server proxy with Timeout facility.
     97        Timeout sent in argument can be used to drop connection
     98        for unavailable servers  """
     99    def __init__(self, url, timeout, *args, **kwargs):
     100        kwargs['transport'] = TimeoutTransport(timeout=timeout, use_datetime=kwargs.get('use_datetime', 0))
     101        xmlrpclib.ServerProxy.__init__(self, url, *args, **kwargs)
     102       
    79103def register_laptop(url=REGISTER_URL):
    80104
    81105    profile = get_profile()
    def register_laptop(url=REGISTER_URL): 
    95119
    96120    nick = client.get_string('/desktop/sugar/user/nick')
    97121
    98     server = ServerProxy(url)
     122    server = TimeoutServerProxy(url,10)
    99123    try:
    100124        data = server.register(sn, nick, uuid_, profile.pubkey)
    101125    except (Error, socket.error):