396
396
def __init__(self):
397
397
super(SmartClientMedium, self).__init__()
398
self._protocol_version_error = None
398
399
self._protocol_version = None
400
401
def protocol_version(self):
401
402
"""Find out the best protocol version to use."""
403
if self._protocol_version_error is not None:
404
raise self._protocol_version_error
402
405
if self._protocol_version is None:
403
medium_request = self.get_request()
404
# Send a 'hello' request in protocol version one, for maximum
405
# backwards compatibility.
406
client_protocol = SmartClientRequestProtocolOne(medium_request)
407
self._protocol_version = client_protocol.query_version()
407
medium_request = self.get_request()
408
# Send a 'hello' request in protocol version one, for maximum
409
# backwards compatibility.
410
client_protocol = SmartClientRequestProtocolOne(medium_request)
411
self._protocol_version = client_protocol.query_version()
412
except errors.SmartProtocolError, e:
413
# Cache the error, just like we would cache a successful
415
self._protocol_version_error = e
408
417
return self._protocol_version
410
419
def disconnect(self):