Issue1964

Title [PATCH] demandimport does not play well with conditional imports used in Python standard ,library (such as seeing if "import _ssl" fails)
Priority bug Status resolved
Superseder Nosy List alejolp, brendan, djc, edbrannin, mg, pmezard, srid
Assigned To Topics

Created on 2009-12-21.23:57:07 by srid, last changed 2010-07-23.18:15:47 by mpm.

Files
File name Uploaded Type Edit Remove
demandimport-ignore-ssl.patch edbrannin, 2010-03-09.14:42:34 application/octet-stream
Messages
msg11971 (view) Author: brendan Date: 2010-03-09.16:00:06
See http://hg.intevation.org/mercurial/crew/rev/30553ac3e355
(demandimport: blacklist _ssl (issue1964))
msg11968 (view) Author: djc Date: 2010-03-09.15:04:23
Fixed in 30553ac3e355.
msg11967 (view) Author: edbrannin Date: 2010-03-09.14:42:34
Just to nudge this along a bit, here's a patch against mercurial-1.5-py2.6-
linux-i686.egg.

In the meantime, people can use this extension to get around it

    #/path/to/sslhack.py
    from mercurial import demandimport
    demandimport.ignore.append('_ssl')

...and put this in .hgrc or mercurial.ini:

    [extensions]
    00sslhack = /path/to/sslhack.py

Credit goes to Steve Borho / sborho: 
http://bitbucket.org/tortoisehg/stable/issue/1006/could-not-import-module-
_ssl-on-push-but-not-on
msg11849 (view) Author: edbrannin Date: 2010-02-23.13:55:24
Adding <<'_ssl',>> to the end of the "ignore = [" block fixed this issue for 
me.
msg11299 (view) Author: djc Date: 2009-12-22.09:56:26
Yeah, this is slightly problematic. We should likely put _ssl in the
demandimport blacklist.
msg11297 (view) Author: srid Date: 2009-12-21.23:57:07
The traceback below is for reference:

Since the traceback points to "socket.py" doing a "from _ssl import SSLError as 
sslerror" at around line 106 which was sandwitched in the try:.. else:.. block I was 
confused as to how that else block got executed at all as _ssl is not available. 

  try:
      import _ssl
  except ImportError:
      # no SSL support
      pass
  else:
      [...]
      from _ssl import SSLError as sslerror
      from _ssl import \

It seems mercurial is doing some magic with the imports. Ideally it should not be 
executing the (conditional) imports in the `else` block.

Further investigation shows that "import _ssl" succeeded (!) even though it normally 
wouldn't .. and _ssl is now an instance of mercurial.demandimport._demandmod!

Original traceback:

  File "/home/apy/ActivePython-2.6/lib/python2.6/site-
packages/mercurial/demandimport.py", line 47, in _load
    mod = _origimport(head, globals, locals)
  File "/home/apy/ActivePython-2.6/lib/python2.6/site-packages/mercurial/url.py", line 
98, in <module>
    class passwordmgr(urllib2.HTTPPasswordMgrWithDefaultRealm):
  File "/home/apy/ActivePython-2.6/lib/python2.6/site-
packages/mercurial/demandimport.py", line 75, in __getattribute__
    self._load()
  File "/home/apy/ActivePython-2.6/lib/python2.6/site-
packages/mercurial/demandimport.py", line 47, in _load
    mod = _origimport(head, globals, locals)
  File "/home/apy/ActivePython-2.6/lib/python2.6/urllib2.py", line 109, in <module>
    from urllib import (unwrap, unquote, splittype, splithost, quote,
  File "/home/apy/ActivePython-2.6/lib/python2.6/site-
packages/mercurial/demandimport.py", line 106, in _demandimport
    mod = _origimport(name, globals, locals)
  File "/home/apy/ActivePython-2.6/lib/python2.6/urllib.py", line 837, in <module>
    class ftpwrapper:
  File "/home/apy/ActivePython-2.6/lib/python2.6/urllib.py", line 841, in ftpwrapper
    timeout=socket._GLOBAL_DEFAULT_TIMEOUT):
  File "/home/apy/ActivePython-2.6/lib/python2.6/site-
packages/mercurial/demandimport.py", line 75, in __getattribute__
    self._load()
  File "/home/apy/ActivePython-2.6/lib/python2.6/site-
packages/mercurial/demandimport.py", line 47, in _load
    mod = _origimport(head, globals, locals)
  File "/home/apy/ActivePython-2.6/lib/python2.6/socket.py", line 64, in <module>
    from _ssl import SSLError as sslerror
  File "/home/apy/ActivePython-2.6/lib/python2.6/site-
packages/mercurial/demandimport.py", line 106, in _demandimport
    mod = _origimport(name, globals, locals)
ImportError: No module named _ssl
abort: could not import module _ssl!
Exception AttributeError: "'httprepository' object has no attribute 'urlopener'" in 
<bound method httprepository.__del__ of <mercurial.httprepo.httprepository object at 
0x204bbe90>> ignored
bash-2.04$
History
Date User Action Args
2010-07-23 18:15:47mpmsetstatus: testing -> resolved
nosy: brendan, pmezard, mg, djc, srid, alejolp, edbrannin
2010-03-09 16:00:07brendansetnosy: + brendan
messages: + msg11971
2010-03-09 15:04:23djcsetstatus: chatting -> testing
nosy: pmezard, mg, djc, srid, alejolp, edbrannin
messages: + msg11968
2010-03-09 14:42:34edbranninsetfiles: + demandimport-ignore-ssl.patch
nosy: pmezard, mg, djc, srid, alejolp, edbrannin
messages: + msg11967
title: demandimport does not play well with conditional imports used in Python standard ,library (such as seeing if "import _ssl" fails) -> [PATCH] demandimport does not play well with conditional imports used in Python standard ,library (such as seeing if "import _ssl" fails)
2010-02-23 13:55:24edbranninsetnosy: + edbrannin
messages: + msg11849
2009-12-22 20:09:01pmezardsetnosy: + pmezard
2009-12-22 09:56:27djcsetstatus: unread -> chatting
nosy: + djc
messages: + msg11299
2009-12-22 03:52:05alejolpsetnosy: + alejolp
2009-12-22 00:00:43mgsetnosy: + mg
2009-12-21 23:57:07sridcreate