Bug 2932 - httpclient.py fails to import on Python 2.7: ssl module no longer has a PROTOCOL_SSLv2 constant if OpenSSL compiled without SSLv2 support
Summary: httpclient.py fails to import on Python 2.7: ssl module no longer has a PROTO...
Status: RESOLVED FIXED
Alias: None
Product: Mercurial
Classification: Unclassified
Component: Mercurial (show other bugs)
Version: unspecified
Hardware: All All
: normal bug
Assignee: Bugzilla
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2011-07-28 10:51 UTC by Robin Munn
Modified: 2012-05-13 05:10 UTC (History)
4 users (show)

See Also:
Python Version: ---


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Robin Munn 2011-07-28 10:51 UTC
Importing the mercurial.httpclient package (or any part of Mercurial that
depends on it) fails as follows:

Traceback (most recent call last):
  File "/usr/bin/hgview", line 31, in <module>
    from hgviewlib.qt4.hgrepoviewer import main 
  File "/usr/lib/pymodules/python2.7/hgviewlib/qt4/__init__.py", line 76, in
<module>
    import hgrepoview, hgfileview
  File "/usr/lib/pymodules/python2.7/hgviewlib/qt4/hgrepoview.py", line 37,
in <module>
    from hgviewlib.qt4.hgmanifestdialog import ManifestViewer
  File "/usr/lib/pymodules/python2.7/hgviewlib/qt4/hgmanifestdialog.py",
line 24, in <module>
    from mercurial import ui, hg, util
  File "/usr/lib/pymodules/python2.7/mercurial/hg.py", line 12, in <module>
    import localrepo, bundlerepo, httprepo, sshrepo, statichttprepo, bookmarks
  File "/usr/lib/pymodules/python2.7/mercurial/httprepo.py", line 11, in
<module>
    import changegroup, statichttprepo, error, httpconnection, url, util,
wireproto
  File "/usr/lib/pymodules/python2.7/mercurial/statichttprepo.py", line 11,
in <module>
    import changelog, byterange, url, error
  File "/usr/lib/pymodules/python2.7/mercurial/url.py", line 13, in <module>
    import httpconnection as httpconnectionmod
  File "/usr/lib/pymodules/python2.7/mercurial/httpconnection.py", line 16,
in <module>
    from mercurial import httpclient
  File "/usr/lib/pymodules/python2.7/mercurial/httpclient/__init__.py", line
48, in <module>
    import socketutil
  File "/usr/lib/pymodules/python2.7/mercurial/httpclient/socketutil.py",
line 81, in <module>
    PROTOCOL_SSLv2 = ssl.PROTOCOL_SSLv2
AttributeError: 'module' object has no attribute 'PROTOCOL_SSLv2'

(Ubuntu 11.11, Oneiric Ocelot, trying and failing to run hgview)

 The cause of this AttributeError is that Python 2.7 removes the
PROTOCOL_SSLv2 constant if OpenSSL was compiled with the OPENSSL_NO_SSL2
flag (see http://docs.python.org/library/ssl.html#ssl.PROTOCOL_SSLv2).

This has been filed as Debian http://www.serpentine.com/bugzilla/show_bug.cgi?id=635496
(http://bugs.debian.org/cgi-bin/bugreport.cgi?bug=635496).
Comment 1 Augie Fackler 2011-07-28 15:11 UTC
This is mine. Do not fix it in hg - I have to fix it in the upstream library
and then merge that down into hg. I'll try and get a Python 2.7 build
installed so I can test and fix.
Comment 2 Augie Fackler 2011-07-28 15:27 UTC
Please test this patch:

# HG changeset patch
# User Augie Fackler <durin42@gmail.com>
# Date 1311888399 18000
# Node ID e032f8d2f4e441e393f5900a9db0b80edccd55f6
# Parent  b4c06b97dfe0cae28497bc3ab85c075a173de8e6
httpclient: import revision 3ba1fd023910 of py-nonblocking-http

diff --git a/mercurial/httpclient/socketutil.py
b/mercurial/httpclient/socketutil.py
--- a/mercurial/httpclient/socketutil.py
+++ b/mercurial/httpclient/socketutil.py
@@ -78,7 +78,8 @@
     CERT_NONE = ssl.CERT_NONE
     CERT_OPTIONAL = ssl.CERT_OPTIONAL
     CERT_REQUIRED = ssl.CERT_REQUIRED
-    PROTOCOL_SSLv2 = ssl.PROTOCOL_SSLv2
+    if getattr(ssl, 'PROTOCOL_SSLv2', None) is not None:
+        PROTOCOL_SSLv2 = ssl.PROTOCOL_SSLv2
     PROTOCOL_SSLv3 = ssl.PROTOCOL_SSLv3
     PROTOCOL_SSLv23 = ssl.PROTOCOL_SSLv23
     PROTOCOL_TLSv1 = ssl.PROTOCOL_TLSv1
Comment 3 Javi 2011-07-29 08:54 UTC
That patch fixes the issue but I get some failures when running make tests:

$ make tests
cd tests && python run-tests.py
.....................................s....s...
--- /root/hg/tests/test-clone-failure.t
+++ /root/hg/tests/test-clone-failure.t.err
@@ -24,8 +24,8 @@
   $ hg init b
   $ cd b
   $ hg clone . ../a
-  abort: Permission denied: ../a
-  [255]
+  updating to branch default
+  0 files updated, 0 files merged, 0 files removed, 0 files unresolved
   $ cd ..
   $ chmod 700 a
   $ rm -r a b
@@ -68,10 +68,10 @@
   $ cd ..
   $ mkdir d
   $ hg clone c d 2> err
-  [255]
+  updating to branch default
+  1 files updated, 0 files merged, 0 files removed, 0 files unresolved
   $ test -d d
   $ test -d d/.hg
-  [1]
 
 reenable perm to allow deletion


ERROR: /root/hg/tests/test-clone-failure.t output changed
!....
--- /root/hg/tests/test-command-template.t
+++ /root/hg/tests/test-command-template.t.err
@@ -436,7 +436,7 @@
   $ touch q
   $ chmod 0 q
   $ hg log --style ./q
-  abort: Permission denied: ./q
+  abort: "changeset" not in template map
   [255]

 Error if no style:
@@ -456,8 +456,6 @@

   $ echo 'changeset = q' >> t
   $ hg log --style ./t
-  abort: template file ./q: Permission denied
-  [255]
+  updating to branch default
+  0 files updated, 0 files merged, 0 files removed, 0 files unresolved
   $ cd ..
   $ chmod 700 a
   $ rm -r a b
@@ -68,10 +68,10 @@
   $ cd ..
   $ mkdir d
   $ hg clone c d 2> err
-  [255]
+  updating to branch default
+  1 files updated, 0 files merged, 0 files removed, 0 files unresolved
   $ test -d d
   $ test -d d/.hg
-  [1]
 
 reenable perm to allow deletion


ERROR: /root/hg/tests/test-clone-failure.t output changed
[...]

I don't get how this failures may be related though.
Comment 4 Javi 2011-07-30 09:30 UTC
Never mind the test failures, they also happen without the patch.

Your patch fixes this.
Comment 5 Augie Fackler 2011-08-01 13:55 UTC
The bug bot seems not to have noticed, but this will be fixed in 1.9.1,
which will be released later today.
Comment 6 Bugzilla 2012-05-12 09:22 UTC

--- Bug imported by bugzilla@serpentine.com 2012-05-12 09:22 EDT  ---

This bug was previously known as _bug_ 2932 at http://mercurial.selenic.com/bts/issue2932