Rev 3824: fix bug #293054: handlle ssl sockets in a python-2.6 compatible way in http://bazaar.launchpad.net/%7Evila/bzr/bzr.integration

Vincent Ladeuil v.ladeuil+lp at free.fr
Fri Nov 7 14:41:50 GMT 2008


At http://bazaar.launchpad.net/%7Evila/bzr/bzr.integration

------------------------------------------------------------
revno: 3824
revision-id: v.ladeuil+lp at free.fr-20081107144115-ool6x8qc4lp47ipf
parent: pqm at pqm.ubuntu.com-20081104203753-tr3wp885v5p7ccpc
parent: v.ladeuil+lp at free.fr-20081107143634-neosl0l2ltf79cgg
committer: Vincent Ladeuil <v.ladeuil+lp at free.fr>
branch nick: bzr.integration
timestamp: Fri 2008-11-07 15:41:15 +0100
message:
  fix bug #293054: handlle ssl sockets in a python-2.6 compatible way
modified:
  bzrlib/tests/blackbox/test_breakin.py test_breakin.py-20070424043903-qyy6zm4pj3h4sbp3-1
  bzrlib/tests/http_server.py    httpserver.py-20061012142527-m1yxdj1xazsf8d7s-1
  bzrlib/transport/http/_urllib2_wrappers.py _urllib2_wrappers.py-20060913231729-ha9ugi48ktx481ao-1
    ------------------------------------------------------------
    revno: 3823.1.3
    revision-id: v.ladeuil+lp at free.fr-20081107143634-neosl0l2ltf79cgg
    parent: v.ladeuil+lp at free.fr-20081106143400-e7vi78opv0whtr1o
    committer: Vincent Ladeuil <v.ladeuil+lp at free.fr>
    branch nick: 293054-https-python26
    timestamp: Fri 2008-11-07 15:36:34 +0100
    message:
      Fixed as per John's review.
      
      * bzrlib/transport/http/_urllib2_wrappers.py:
      Better explanation for _ssl_wrap_socket.
    modified:
      bzrlib/transport/http/_urllib2_wrappers.py _urllib2_wrappers.py-20060913231729-ha9ugi48ktx481ao-1
    ------------------------------------------------------------
    revno: 3823.1.2
    revision-id: v.ladeuil+lp at free.fr-20081106143400-e7vi78opv0whtr1o
    parent: v.ladeuil+lp at free.fr-20081105181644-xh81k26ieuu7mh8x
    committer: Vincent Ladeuil <v.ladeuil+lp at free.fr>
    branch nick: 293054-https-python26
    timestamp: Thu 2008-11-06 15:34:00 +0100
    message:
      Make the test suite passes again on OSX with python-2.6.
      
      * bzrlib/tests/http_server.py:
      (TestingHTTPServerMixin.tearDown): Catch ENOTCONN since it
      happened on OSX too under python-2.6
      
      * bzrlib/tests/blackbox/test_breakin.py:
      (TestBreakin._dont_SIGQUIT_on_darwin): Popups during test suite
      are distasteful and scary, don't do that on OSX.
      (TestBreakin.test_breakin_harder,
      TestBreakin.test_breakin_disabled): Unless a way to disabl the
      popups is found, disable the tests on OSX.
    modified:
      bzrlib/tests/blackbox/test_breakin.py test_breakin.py-20070424043903-qyy6zm4pj3h4sbp3-1
      bzrlib/tests/http_server.py    httpserver.py-20061012142527-m1yxdj1xazsf8d7s-1
    ------------------------------------------------------------
    revno: 3823.1.1
    revision-id: v.ladeuil+lp at free.fr-20081105181644-xh81k26ieuu7mh8x
    parent: pqm at pqm.ubuntu.com-20081104203753-tr3wp885v5p7ccpc
    committer: Vincent Ladeuil <v.ladeuil+lp at free.fr>
    branch nick: 293054-https-python26
    timestamp: Wed 2008-11-05 19:16:44 +0100
    message:
      Fix bug #293054 by building the ssl socket in a python-2.8
      compatible way.
      
      * bzrlib/transport/http/_urllib2_wrappers.py:
      (_ssl_wrap_socket): python-2.6 needs a different build method for
      ssl sockets.
      (HTTPSConnection.connect_to_origin): Use _ssl_wrap_socket.
    modified:
      bzrlib/transport/http/_urllib2_wrappers.py _urllib2_wrappers.py-20060913231729-ha9ugi48ktx481ao-1
-------------- next part --------------
=== modified file 'bzrlib/tests/blackbox/test_breakin.py'
--- a/bzrlib/tests/blackbox/test_breakin.py	2007-06-20 14:25:06 +0000
+++ b/bzrlib/tests/blackbox/test_breakin.py	2008-11-06 14:34:00 +0000
@@ -22,18 +22,28 @@
 import sys
 import time
 
-from bzrlib.tests import TestCase, TestSkipped
-
-
-class TestBreakin(TestCase):
+from bzrlib import tests
+
+
+class TestBreakin(tests.TestCase):
     # FIXME: If something is broken, these tests may just hang indefinitely in
     # wait() waiting for the child to exit when it's not going to.
 
     def setUp(self):
         if sys.platform == 'win32':
-            raise TestSkipped('breakin signal not tested on win32')
+            raise tests.TestSkipped('breakin signal not tested on win32')
         super(TestBreakin, self).setUp()
 
+    def _dont_SIGQUIT_on_darwin(self):
+        if sys.platform == 'darwin':
+            # At least on Leopard and with python 2.6, this test will raise a
+            # popup window asking if the python failure should be reported to
+            # Apple... That's not the point of the test :) Marking the test as
+            # not applicable Until we find a way to disable that intrusive
+            # behavior... --vila20080611
+            raise tests.TestNotApplicable(
+                '%s raises a popup on OSX' % self.id())
+
     # port 0 means to allocate any port
     _test_process_args = ['serve', '--port', 'localhost:0']
 
@@ -53,6 +63,7 @@
         self.assertContainsRe(err, r'entering debugger')
 
     def test_breakin_harder(self):
+        self._dont_SIGQUIT_on_darwin()
         proc = self.start_bzr_subprocess(self._test_process_args,
                 env_changes=dict(BZR_SIGQUIT_PDB=None))
         # wait for it to get started, and print the 'listening' line
@@ -78,6 +89,7 @@
             self.fail("subprocess wasn't terminated by repeated SIGQUIT")
 
     def test_breakin_disabled(self):
+        self._dont_SIGQUIT_on_darwin()
         proc = self.start_bzr_subprocess(self._test_process_args,
                 env_changes=dict(BZR_SIGQUIT_PDB='0'))
         # wait for it to get started, and print the 'listening' line

=== modified file 'bzrlib/tests/http_server.py'
--- a/bzrlib/tests/http_server.py	2008-09-26 15:28:29 +0000
+++ b/bzrlib/tests/http_server.py	2008-11-06 14:34:00 +0000
@@ -347,7 +347,12 @@
              # WSAENOTCONN (10057) 'Socket is not connected' is harmless on
              # windows (occurs before the first connection attempt
              # vila--20071230)
-             if not len(e.args) or e.args[0] != 10057:
+
+             # 'Socket is not connected' can also occur on OSX, with a
+             # "regular" ENOTCONN (when something went wrong during test case
+             # setup leading to self.setUp() *not* being called but
+             # self.tearDown() still being called -- vila20081106
+             if not len(e.args) or e.args[0] not in (errno.ENOTCONN, 10057):
                  raise
          # Let the server properly close the socket
          self.server_close()

=== modified file 'bzrlib/transport/http/_urllib2_wrappers.py'
--- a/bzrlib/transport/http/_urllib2_wrappers.py	2008-09-26 07:09:50 +0000
+++ b/bzrlib/transport/http/_urllib2_wrappers.py	2008-11-07 14:36:34 +0000
@@ -232,7 +232,19 @@
         httplib.HTTPConnection.connect(self)
 
 
-# FIXME: Should test for ssl availability
+# Build the appropriate socket wrapper for ssl
+try:
+    # python 2.6 introduced a better ssl package
+    import ssl
+    _ssl_wrap_socket = ssl.wrap_socket
+except ImportError:
+    # python versions prior to 2.6 don't have ssl and ssl.wrap_socket instead
+    # they use httplib.FakeSocket
+    def _ssl_wrap_socket(sock, key_file, cert_file):
+        ssl_sock = socket.ssl(sock, key_file, cert_file)
+        return httplib.FakeSocket(sock, ssl_sock)
+
+
 class HTTPSConnection(AbstractHTTPConnection, httplib.HTTPSConnection):
 
     def __init__(self, host, port=None, key_file=None, cert_file=None,
@@ -251,8 +263,7 @@
             self.connect_to_origin()
 
     def connect_to_origin(self):
-        ssl = socket.ssl(self.sock, self.key_file, self.cert_file)
-        self.sock = httplib.FakeSocket(self.sock, ssl)
+        self.sock = _ssl_wrap_socket(self.sock, self.key_file, self.cert_file)
 
 
 class Request(urllib2.Request):



More information about the bazaar-commits mailing list