Ticket #2289: 0001-Register-Bug-Solution-LP-bug-617813.patch

File 0001-Register-Bug-Solution-LP-bug-617813.patch, 3.1 KB (added by lfaraone, 9 years ago)
  • src/jarabe/desktop/schoolserver.py

    From e636b25da0973e9986b6fcd2a7f0f5a48d3e0265 Mon Sep 17 00:00:00 2001
    From: Dipankar Patro <dipankar@seeta.in>
    Date: Sat, 4 Sep 2010 19:53:54 +0530
    Subject: [PATCH] Register Bug Solution: LP bug #617813
    
    ---
     src/jarabe/desktop/schoolserver.py |   40 ++++++++++++++++++++++++++++++-----
     1 files changed, 34 insertions(+), 6 deletions(-)
    
    diff --git a/src/jarabe/desktop/schoolserver.py b/src/jarabe/desktop/schoolserver.py
    index 62519df..58ffb88 100644
    a b  
    1616
    1717import logging
    1818from gettext import gettext as _
    19 from xmlrpclib import ServerProxy, Error
     19
     20import httplib
     21import xmlrpclib
    2022import socket
    2123import os
    22 import string
     24from string import ascii_uppercase
    2325import random
    2426import time
    2527import uuid
    def generate_serial_number(): 
    3739
    3840    serial_part1 = []
    3941
    40     for y in range(3) :
    41         serial_part1.append(random.choice(string.ascii_uppercase))
     42    for y_ in range(3) :
     43        serial_part1.append(random.choice(ascii_uppercase))
    4244
    4345    serial_part1 = ''.join(serial_part1)
    4446    serial_part2 = str(int(time.time()))[-8:]
    def store_identifiers(serial_number, uuid, backup_url): 
    7678class RegisterError(Exception):
    7779    pass
    7880
     81# New class TimeoutServerProxy to implement timeout controlled connection, derived from xmlrpclib.ServerProxy()
     82# LP Bug #617813
     83class TimeoutHTTP(httplib.HTTP):
     84   def __init__(self, host='', port=None, strict=None,
     85                timeout=socket._GLOBAL_DEFAULT_TIMEOUT):
     86        if port == 0:
     87            port = None
     88        self._setup(self._connection_class(host, port, strict, timeout))
     89
     90class TimeoutTransport(xmlrpclib.Transport):
     91    def __init__(self, timeout=socket._GLOBAL_DEFAULT_TIMEOUT, *args, **kwargs):
     92        xmlrpclib.Transport.__init__(self, *args, **kwargs)
     93        self.timeout = timeout
     94
     95    def make_connection(self, host):
     96        host, extra_headers, x509 = self.get_host_info(host)
     97        conn = TimeoutHTTP(host, timeout=self.timeout)
     98        return conn
     99       
     100class TimeoutServerProxy(xmlrpclib.ServerProxy):
     101    def __init__(self, url, timeout, *args, **kwargs):
     102        kwargs['transport'] = TimeoutTransport(timeout=timeout, use_datetime=kwargs.get('use_datetime', 0))
     103        xmlrpclib.ServerProxy.__init__(self, url, *args, **kwargs)
     104
    79105def register_laptop(url=REGISTER_URL):
    80106
    81107    profile = get_profile()
    def register_laptop(url=REGISTER_URL): 
    89115    else:
    90116        sn = generate_serial_number()
    91117        uuid_ = str(uuid.uuid1())
    92         jabber_server = client.get_string('/desktop/sugar/collaboration/jabber_server')
     118        setting_name = '/desktop/sugar/collaboration/jabber_server'
     119        jabber_server = client.get_string(setting_name)
    93120        store_identifiers(sn, uuid_, jabber_server)
    94121        url = 'http://' + jabber_server + ':8080/'
    95122
    96123    nick = client.get_string('/desktop/sugar/user/nick')
    97124
    98     server = ServerProxy(url)
     125    server = TimeoutServerProxy(url)
     126   
    99127    try:
    100128        data = server.register(sn, nick, uuid_, profile.pubkey)
    101129    except (Error, socket.error):