Here are the examples of the python api xmlrpclib.Transport.request taken from open source projects. By voting up you can indicate which examples are most useful and appropriate.
1 Examples
0
Example 1
Project: pyatom Source File: __init__.py
def request(self, host, handler, request_body, verbose=0):
# issue XML-RPC request
retry_count = 1
while True:
try:
if _python26:
# Noticed this in Hutlab environment (Windows 7 SP1)
# Activestate python 2.5, use the old method
return xmlrpclib.Transport.request(
self, host, handler, request_body, verbose=verbose)
# Follwing implementation not supported in Python <= 2.6
h = self.make_connection(host)
if verbose:
h.set_debuglevel(1)
self.send_request(h, handler, request_body)
self.send_host(h, host)
self.send_user_agent(h)
self.send_content(h, request_body)
response = h.getresponse()
if response.status != 200:
raise xmlrpclib.ProtocolError(host + handler, response.status,
response.reason, response.msg.headers)
payload = response.read()
parser, unmarshaller = self.getparser()
parser.feed(payload)
parser.close()
return unmarshaller.close()
except SocketError as e:
if ((_ldtp_windows_env and e[0] == 10061) or \
(hasattr(e, 'errno') and (e.errno == 111 or \
e.errno == 61 or \
e.errno == 146))) \
and 'localhost' in host:
if hasattr(self, 'close'):
# On Windows XP SP3 / Python 2.5, close doesn't exist
self.close()
if retry_count == 1:
retry_count += 1
if not _ldtp_windows_env:
sigusr1 = signal.signal(signal.SIGUSR1, self._handle_signal)
sigalrm = signal.signal(signal.SIGALRM, self._handle_signal)
sigchld = signal.signal(signal.SIGCHLD, self._handle_signal)
self._spawn_daemon()
if _ldtp_windows_env:
time.sleep(5)
else:
signal.alarm(15) # Wait 15 seconds for ldtpd
signal.pause()
# restore signal handlers
signal.alarm(0)
signal.signal(signal.SIGUSR1, sigusr1)
signal.signal(signal.SIGALRM, sigalrm)
signal.signal(signal.SIGCHLD, sigchld)
continue
else:
raise
# else raise exception
raise
except xmlrpclib.Fault as e:
if hasattr(self, 'close'):
self.close()
if e.faultCode == ERROR_CODE:
raise LdtpExecutionError(e.faultString.encode('utf-8'))
else:
raise e