# HG changeset patch # User Andrej A Antonov # Date 1330470719 -14400 # Branch 3.2 # Node ID 8276da8918d0f945969525c46c51ce5546536c5b # Parent 137e45f15c0bd262c9ad4c032d97425bc0589456 added timeout to xmlrpc.client.ServerProxy() diff -r 137e45f15c0b -r 8276da8918d0 Doc/library/xmlrpc.client.rst --- a/Doc/library/xmlrpc.client.rst Thu Aug 25 18:32:02 2011 +0200 +++ b/Doc/library/xmlrpc.client.rst Wed Feb 29 03:11:59 2012 +0400 @@ -21,7 +21,7 @@ between conformable Python objects and XML on the wire. -.. class:: ServerProxy(uri, transport=None, encoding=None, verbose=False, allow_none=False, use_datetime=False) +.. class:: ServerProxy(uri, transport=None, encoding=None, verbose=False, allow_none=False, use_datetime=False, timeout=None) A :class:`ServerProxy` instance is an object that manages communication with a remote XML-RPC server. The required first argument is a URI (Uniform Resource @@ -36,7 +36,10 @@ all clients and servers; see http://ontosys.com/xml-rpc/extensions.php for a description. The *use_datetime* flag can be used to cause date/time values to be presented as :class:`datetime.datetime` objects; this is false by default. - :class:`datetime.datetime` objects may be passed to calls. + :class:`datetime.datetime` objects may be passed to calls. If the optional + *timeout* parameter is given, blocking operations (like connection attempts) + will timeout after that many seconds (if it is not given, the global default + timeout setting is used). Both the HTTP and HTTPS transports support the URL syntax extension for HTTP Basic Authentication: ``http://user:pass@host:port/path``. The ``user:pass`` @@ -104,6 +107,8 @@ :class:`Server` is retained as an alias for :class:`ServerProxy` for backwards compatibility. New code should use :class:`ServerProxy`. + .. versionchanged:: 3.3 + *timeout* was added. .. seealso:: diff -r 137e45f15c0b -r 8276da8918d0 Lib/xmlrpc/client.py --- a/Lib/xmlrpc/client.py Thu Aug 25 18:32:02 2011 +0200 +++ b/Lib/xmlrpc/client.py Wed Feb 29 03:11:59 2012 +0400 @@ -1114,8 +1114,9 @@ # that they can decode such a request encode_threshold = None #None = don't encode - def __init__(self, use_datetime=False): + def __init__(self, use_datetime=False, timeout=None): self._use_datetime = use_datetime + self._timeout = timeout self._connection = (None, None) self._extra_headers = [] @@ -1223,7 +1224,8 @@ return self._connection[1] # create a HTTP connection object from a host descriptor chost, self._extra_headers, x509 = self.get_host_info(host) - self._connection = host, http.client.HTTPConnection(chost) + self._connection = host, http.client.HTTPConnection(chost, + timeout=self._timeout) return self._connection[1] ## @@ -1341,7 +1343,7 @@ # host may be a string, or a (host, x509-dict) tuple chost, self._extra_headers, x509 = self.get_host_info(host) self._connection = host, http.client.HTTPSConnection(chost, - None, **(x509 or {})) + None, timeout=self._timeout, **(x509 or {})) return self._connection[1] ## @@ -1384,7 +1386,7 @@ """ def __init__(self, uri, transport=None, encoding=None, verbose=False, - allow_none=False, use_datetime=False): + allow_none=False, use_datetime=False, timeout=None): # establish a "logical" server connection # get the url @@ -1398,9 +1400,9 @@ if transport is None: if type == "https": - transport = SafeTransport(use_datetime=use_datetime) + transport = SafeTransport(use_datetime=use_datetime, timeout=timeout) else: - transport = Transport(use_datetime=use_datetime) + transport = Transport(use_datetime=use_datetime, timeout=timeout) self.__transport = transport self.__encoding = encoding or 'utf-8'