Commit 3a5b3417 authored by Nicolas Dumazet's avatar Nicolas Dumazet

Do not let socket.error go through, ProtocolError should be raised instead


git-svn-id: https://svn.erp5.org/repos/public/erp5/trunk@39585 20353a03-c40f-0410-a6d1-a30d3c3de9de
parent c4d95d1b
...@@ -26,9 +26,10 @@ ...@@ -26,9 +26,10 @@
# #
############################################################################## ##############################################################################
from xmlrpclib import Fault from xmlrpclib import Fault, ProtocolError
from xmlrpclib import Transport from xmlrpclib import Transport
from xmlrpclib import SafeTransport from xmlrpclib import SafeTransport
import socket
class TimeoutTransport(SafeTransport): class TimeoutTransport(SafeTransport):
"""A xmlrpc transport with configurable timeout. """A xmlrpc transport with configurable timeout.
...@@ -45,15 +46,22 @@ class TimeoutTransport(SafeTransport): ...@@ -45,15 +46,22 @@ class TimeoutTransport(SafeTransport):
super__init__(self) super__init__(self)
def send_content(self, connection, request_body): def send_content(self, connection, request_body):
connection.putheader("Content-Type", "text/xml") try:
connection.putheader("Content-Length", str(len(request_body))) connection.putheader("Content-Type", "text/xml")
connection.endheaders() connection.putheader("Content-Length", str(len(request_body)))
if self._timeout: connection.endheaders()
connection._conn.sock.settimeout(self._timeout) if self._timeout:
if request_body: connection._conn.sock.settimeout(self._timeout)
connection.send(request_body) if request_body:
connection.send(request_body)
except socket.error, e:
raise ProtocolError(connection._conn.host, -1,
"Could not connect to server", None)
def make_connection(self, h): def make_connection(self, host):
if self._scheme == 'http': try:
return Transport.make_connection(self, h) if self._scheme == 'http':
return SafeTransport.make_connection(self, h) return Transport.make_connection(self, host)
return SafeTransport.make_connection(self, host)
except socket.error, e:
raise ProtocolError(host, -1, "Could not connect to server", None)
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment