Revision 8d5b316c lib/luxi.py
b/lib/luxi.py | ||
---|---|---|
21 | 21 |
|
22 | 22 |
"""Module for the unix socket protocol |
23 | 23 |
|
24 |
This module implements the local unix socket protocl. You only need |
|
24 |
This module implements the local unix socket protocol. You only need
|
|
25 | 25 |
this module and the opcodes module in the client program in order to |
26 | 26 |
communicate with the master. |
27 | 27 |
|
... | ... | |
252 | 252 |
""" |
253 | 253 |
if address is None: |
254 | 254 |
address = constants.MASTER_SOCKET |
255 |
self.transport = transport(address, timeouts=timeouts) |
|
255 |
self.address = address |
|
256 |
self.timeouts = timeouts |
|
257 |
self.transport_class = transport |
|
258 |
self.transport = None |
|
259 |
self._InitTransport() |
|
260 |
|
|
261 |
def _InitTransport(self): |
|
262 |
"""(Re)initialize the transport if needed. |
|
263 |
|
|
264 |
""" |
|
265 |
if self.transport is None: |
|
266 |
self.transport = self.transport_class(self.address, |
|
267 |
timeouts=self.timeouts) |
|
268 |
|
|
269 |
def _CloseTransport(self): |
|
270 |
"""Close the transport, ignoring errors. |
|
271 |
|
|
272 |
""" |
|
273 |
if self.transport is None: |
|
274 |
return |
|
275 |
try: |
|
276 |
old_transp = self.transport |
|
277 |
self.transport = None |
|
278 |
old_transp.Close() |
|
279 |
except Exception, err: |
|
280 |
pass |
|
256 | 281 |
|
257 | 282 |
def CallMethod(self, method, args): |
258 | 283 |
"""Send a generic request and return the response. |
... | ... | |
264 | 289 |
KEY_ARGS: args, |
265 | 290 |
} |
266 | 291 |
|
292 |
# Serialize the request |
|
293 |
send_data = serializer.DumpJson(request, indent=False) |
|
294 |
|
|
267 | 295 |
# Send request and wait for response |
268 |
result = self.transport.Call(serializer.DumpJson(request, indent=False)) |
|
296 |
try: |
|
297 |
self._InitTransport() |
|
298 |
result = self.transport.Call(send_data) |
|
299 |
except Exception: |
|
300 |
self._CloseTransport() |
|
301 |
raise |
|
302 |
|
|
303 |
# Parse the result |
|
269 | 304 |
try: |
270 | 305 |
data = serializer.LoadJson(result) |
271 | 306 |
except Exception, err: |
Also available in: Unified diff