~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/transport/__init__.py

Ensure that all transports close their underlying connection.

* bzrlib/transport/sftp.py:
(SFTPTransport.disconnect): Close the sftp connection.

* bzrlib/transport/remote.py:
(RemoteTransport.disconnect): The medium can be None.

* bzrlib/transport/http/_urllib.py:
(HttpTransport_urllib.disconnect): Close the http connection.

* bzrlib/transport/http/_pycurl.py:
(PyCurlTransport.disconnect): Close the Curl object.

* bzrlib/transport/http/__init__.py:
(SmartClientHTTPMedium.disconnect): Disconnect the backing http
transport.

* bzrlib/transport/gio_transport.py:
(GioTransport.disconnect): Hmm, nothing obvious here.

* bzrlib/transport/ftp/__init__.py:
(FtpTransport.disconnect): Close the ftplib connection.

* bzrlib/transport/__init__.py:
(Transport.disconnect): A do-nothing implementation by default.
(ConnectedTransport.disconnect): A new required method.

* bzrlib/tests/test_smart_transport.py:
(TestSmartTCPServer.test_get_error_unexpected)
(SmartTCPTests.start_server): Revert to SmartServer waiting for a
better way to capture the connections.

* bzrlib/tests/per_transport.py:
(TransportTests.test_connection_sharing): 'None' is better than
'object()' for a dummy connection.

* bzrlib/tests/__init__.py:
(TestCase._check_leaked_threads): Don't fail at first leak or all
subsequent tests will fail too. A more elaborate scheme would be
to use threading.enumerate() but that's a big hammer with little
benefits as long as there exist "valid" leaks (like the smart
server).
(TestCaseWithMemoryTransport.setUp): Make sure we call
transport.disconnect() for all created transports.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1286
1286
        # should be asked to ConnectedTransport only.
1287
1287
        return None
1288
1288
 
 
1289
    def disconnect(self):
 
1290
        # This is really needed for ConnectedTransport only, but it's easier to
 
1291
        # have Transport do nothing than testing that the disconnect should be
 
1292
        # asked to ConnectedTransport only.
 
1293
        pass
 
1294
 
1289
1295
    def _redirected_to(self, source, target):
1290
1296
        """Returns a transport suitable to re-issue a redirected request.
1291
1297
 
1550
1556
            transport = self.__class__(other_base, _from_transport=self)
1551
1557
        return transport
1552
1558
 
 
1559
    def disconnect(self):
 
1560
        """Disconnect the transport.
 
1561
 
 
1562
        If and when required the transport willl reconnect automatically.
 
1563
        """
 
1564
        raise NotImplementedError(self.disconnect)
 
1565
 
1553
1566
 
1554
1567
# We try to recognize an url lazily (ignoring user, password, etc)
1555
1568
_urlRE = re.compile(r'^(?P<proto>[^:/\\]+)://(?P<rest>.*)$')