/brz/remove-bazaar

To get this branch, use:
bzr branch http://gegoxaren.bato24.eu/bzr/brz/remove-bazaar

« back to all changes in this revision

Viewing changes to bzrlib/tests/test_http.py

  • Committer: Vincent Ladeuil
  • Date: 2009-10-08 08:55:17 UTC
  • mto: (5247.1.1 first-try)
  • mto: This revision was merged to the branch mainline in revision 5396.
  • Revision ID: v.ladeuil+lp@free.fr-20091008085517-gbybgf4dszqq31lj
Fix python-2.4/2.5 compatibility.

* bzrlib/tests/test_http.py:
(RecordingServer.connect_socket): Band aid to work around
python-2.4 missing socket.create_connection().

* bzrlib/tests/http_server.py:
(TestingThreadingHTTPServer.process_request_thread): Fix
python2.5/2.4 compatibility.

Show diffs side-by-side

added added

removed removed

Lines of Context:
252
252
            # The client may have already closed the socket.
253
253
            pass
254
254
 
 
255
    def connect_socket(self):
 
256
        msg = "getaddrinfo returns an empty list"
 
257
        for res in socket.getaddrinfo(self.host, self.port):
 
258
            af, socktype, proto, canonname, sa = res
 
259
            sock = None
 
260
            try:
 
261
                sock = socket.socket(af, socktype, proto)
 
262
                sock.connect(sa)
 
263
                return sock
 
264
 
 
265
            except socket.error, msg:
 
266
                if sock is not None:
 
267
                    sock.close()
 
268
        raise socket.error, msg
 
269
 
255
270
    def tearDown(self):
256
271
        try:
257
272
            # Issue a fake connection to wake up the server and allow it to
258
273
            # finish quickly
259
 
            fake_conn = socket.create_connection((self.host, self.port))
 
274
            fake_conn = self.connect_socket()
260
275
            fake_conn.close()
261
276
        except socket.error:
262
277
            # We might have already closed it.  We don't care.