[PATCH 06 of 13] Added a new function to util to detect HTTPS support on urllib/urllib2. The 2to3 tool won't detect this

Alejandro Santos alejolp at alejolp.com
Wed Aug 5 15:55:40 CDT 2009


# HG changeset patch
# User Alejandro Santos <alejolp at alejolp.com>
# Date 1249505636 10800
# Node ID d0b6c743b767fef7516206872765e4c8136c515f
# Parent  34cf98e3a0202becb3a8b986a714650f988b961a
Added a new function to util to detect HTTPS support on urllib/urllib2. The 2to3 tool won't detect this.

diff -r 34cf98e3a020 -r d0b6c743b767 mercurial/py2compat.py
--- a/mercurial/py2compat.py	Wed Aug 05 17:53:07 2009 -0300
+++ b/mercurial/py2compat.py	Wed Aug 05 17:53:56 2009 -0300
@@ -13,3 +13,7 @@
 
 buffer = __builtin__.buffer
 posixfiletype = file
+
+def httpssupport():
+    import urllib2
+    return hasattr(urllib2, 'HTTPSHandler')
diff -r 34cf98e3a020 -r d0b6c743b767 mercurial/py3compat.py
--- a/mercurial/py3compat.py	Wed Aug 05 17:53:07 2009 -0300
+++ b/mercurial/py3compat.py	Wed Aug 05 17:53:56 2009 -0300
@@ -33,3 +33,11 @@
 
 def buffer(data, offset=None, size=None):
     return memoryview(data)[offset:size and offset + size]
+
+def httpssupport():
+    """
+    Returns True if urllib has HTTPS support. 
+    It seems this is an edge case of the 2to3 tool on the urllib2 usage.
+    """
+    import urllib.request
+    return hasattr(urllib.request, 'HTTPSHandler')
diff -r 34cf98e3a020 -r d0b6c743b767 mercurial/url.py
--- a/mercurial/url.py	Wed Aug 05 17:53:07 2009 -0300
+++ b/mercurial/url.py	Wed Aug 05 17:53:56 2009 -0300
@@ -247,7 +247,7 @@
             connection.send(self, data)
     return _sendfile
 
-has_https = hasattr(urllib2, 'HTTPSHandler')
+has_https = util.httpssupport()
 if has_https:
     try:
         # avoid using deprecated/broken FakeSocket in python 2.6


More information about the Mercurial-devel mailing list