getbinpkg.py: use local HTTPSConnection import
authorZac Medico <zmedico@gentoo.org>
Thu, 16 Dec 2010 07:24:16 +0000 (23:24 -0800)
committerZac Medico <zmedico@gentoo.org>
Thu, 16 Dec 2010 09:07:31 +0000 (01:07 -0800)
Use local import since https typically isn't needed, and this way we
can usually avoid triggering the global scope http.client ImportError
handler (like during stage1 -> stage2 builds where USE=ssl is disabled
for python).

pym/portage/getbinpkg.py

index c8a0edc4dbd44b0232df3c6a976f6ed58eda0851..b225eab7f9ff928d3ba6366c47eb1d04709a6e3d 100644 (file)
@@ -43,13 +43,11 @@ else:
 try:
        try:
                from http.client import HTTPConnection as http_client_HTTPConnection
-               from http.client import HTTPSConnection as http_client_HTTPSConnection
                from http.client import BadStatusLine as http_client_BadStatusLine
                from http.client import ResponseNotReady as http_client_ResponseNotReady
                from http.client import error as http_client_error
        except ImportError:
                from httplib import HTTPConnection as http_client_HTTPConnection
-               from httplib import HTTPSConnection as http_client_HTTPSConnection
                from httplib import BadStatusLine as http_client_BadStatusLine
                from httplib import ResponseNotReady as http_client_ResponseNotReady
                from httplib import error as http_client_error
@@ -161,6 +159,18 @@ def create_conn(baseurl,conn=None):
 
        if not conn:
                if protocol == "https":
+                       # Use local import since https typically isn't needed, and
+                       # this way we can usually avoid triggering the global scope
+                       # http.client ImportError handler (like during stage1 -> stage2
+                       # builds where USE=ssl is disabled for python).
+                       try:
+                               try:
+                                       from http.client import HTTPSConnection as http_client_HTTPSConnection
+                               except ImportError:
+                                       from httplib import HTTPSConnection as http_client_HTTPSConnection
+                       except ImportError:
+                               raise NotImplementedError(
+                                       _("python must have ssl enabled for https support"))
                        conn = http_client_HTTPSConnection(host)
                elif protocol == "http":
                        conn = http_client_HTTPConnection(host)