431
431
super(SmartClientMedium, self).__init__()
432
432
self._protocol_version_error = None
433
433
self._protocol_version = None
434
self._done_hello = False
435
436
def protocol_version(self):
436
"""Find out the best protocol version to use."""
437
"""Find out if 'hello' smart request works."""
437
438
if self._protocol_version_error is not None:
438
439
raise self._protocol_version_error
439
if self._protocol_version is None:
440
if not self._done_hello:
441
442
medium_request = self.get_request()
442
443
# Send a 'hello' request in protocol version one, for maximum
443
444
# backwards compatibility.
444
445
client_protocol = SmartClientRequestProtocolOne(medium_request)
445
self._protocol_version = client_protocol.query_version()
446
client_protocol.query_version()
447
self._done_hello = True
446
448
except errors.SmartProtocolError, e:
447
449
# Cache the error, just like we would cache a successful
449
451
self._protocol_version_error = e
451
return self._protocol_version
455
def should_probe(self):
456
"""Should RemoteBzrDirFormat.probe_transport send a smart request on
459
Some transports are unambiguously smart-only; there's no need to check
460
if the transport is able to carry smart requests, because that's all
461
it is for. In those cases, this method should return False.
463
But some HTTP transports can sometimes fail to carry smart requests,
464
but still be usuable for accessing remote bzrdirs via plain file
465
accesses. So for those transports, their media should return True here
466
so that RemoteBzrDirFormat can determine if it is appropriate for that
453
471
def disconnect(self):
454
472
"""If this medium maintains a persistent connection, close it.