Skip to content

Commit 5ac64a1

Browse files
committed
Refactor LocalSocketHandler to simplify do_open method and improve error handling
Signed-off-by: Nicolas Bettembourg <[email protected]>
1 parent 7b9ac00 commit 5ac64a1

File tree

1 file changed

+1
-24
lines changed

1 file changed

+1
-24
lines changed

plugins/modules/sap_control_exec.py

Lines changed: 1 addition & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -289,35 +289,12 @@ def connect(self):
289289
class LocalSocketHandler(HTTPHandler):
290290
"""HTTP handler for Unix domain sockets."""
291291
def __init__(self, debuglevel=0, socketpath=None):
292-
HTTPHandler.__init__(self, debuglevel)
292+
self._debuglevel = debuglevel
293293
self._socketpath = socketpath
294294

295295
def http_open(self, req):
296296
return self.do_open(LocalSocketHttpConnection, req, socketpath=self._socketpath)
297297

298-
def do_open(self, http_class, req, **http_conn_args):
299-
"""Override to handle Unix socket connections."""
300-
host = req.host
301-
if not host:
302-
raise ValueError('no host given')
303-
304-
http_conn = http_class(host, **http_conn_args)
305-
http_conn.set_debuglevel(self._debuglevel)
306-
307-
try:
308-
http_conn.connect()
309-
http_conn.request(req.get_method(), req.selector, req.data, req.headers)
310-
r = http_conn.getresponse()
311-
312-
# Create a proper response object that SUDS expects
313-
r.msg = r.reason
314-
return r
315-
except Exception as err:
316-
http_conn.close()
317-
raise err
318-
finally:
319-
if hasattr(http_conn, 'close'):
320-
http_conn.close()
321298

322299
def choices():
323300
retlist = ["Start", "Stop", "Shutdown", "InstanceStart", "InstanceStop", "Bootstrap", "ParameterValue", "GetProcessList",

0 commit comments

Comments
 (0)