[Sugar-devel] [PATCH sugar] Register with schoolserver: adopt to changes in xmlrpclib for python 2.7 OLPC #10776

Sascha Silbe sascha-ml-reply-to-2011-2 at silbe.org
Fri May 20 16:15:20 EDT 2011


Excerpts from Simon Schampijer's message of Thu May 19 16:08:36 +0200 2011:


s/adopt/adapt/ (or adjust)

> Python 2.7 switched from using httplib.HTTP to using httplib.HTTPConnection,
>  as the httplib.HTTPConnection includes a timeout by default we can use a
> xmlrpclib.Transport directly and do not need to subclass it.

I guess we don't need to subclass Transport, but we probably need to
call socket.setdefaulttimeout() during Sugar start-up:

>> socket.setdefaulttimeout(timeout)

>>    Set the default timeout in floating seconds for new socket objects.
>>    A value of None indicates that new socket objects have no timeout.
>>    When the socket module is first imported, the default is None.


[src/jarabe/desktop/schoolserver.py]
> -    server = xmlrpclib.ServerProxy(url, _TimeoutTransport())
> +    if sys.version_info[1] < 7:

"if sys.hexversion < 0x02070000:" has a higher chance of continuing to
work after a transition to Py3K. The 2to3 tool already takes care of
renaming xmlrpclib to xmlrpc.client [1].

> +        server = xmlrpclib.ServerProxy(url, _TimeoutTransport())
> +    else:
> +        server = xmlrpclib.ServerProxy(url, xmlrpclib.Transport())

We can skip the transport altogether for 2.7+. That way we support
https, too (SafeTransport instead of Transport).

Sascha

[1] http://docs.python.org/library/xmlrpclib.html
-- 
http://sascha.silbe.org/
http://www.infra-silbe.de/
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 494 bytes
Desc: not available
URL: <http://lists.sugarlabs.org/archive/sugar-devel/attachments/20110520/4bd64e5d/attachment.pgp>


More information about the Sugar-devel mailing list