@@ -524,16 +524,17 @@ def http_open(self, req):
524524 return MockResponse (200 , "OK" , msg , "" , req .get_full_url ())
525525
526526
527- class MockHTTPSHandler (urllib .request .HTTPSHandler ):
528- # Useful for testing the Proxy-Authorization request by verifying the
529- # properties of httpcon
527+ if hasattr (http .client , 'HTTPSConnection' ):
528+ class MockHTTPSHandler (urllib .request .HTTPSHandler ):
529+ # Useful for testing the Proxy-Authorization request by verifying the
530+ # properties of httpcon
530531
531- def __init__ (self , debuglevel = None , context = None , check_hostname = None ):
532- super (MockHTTPSHandler , self ).__init__ (debuglevel , context , check_hostname )
533- self .httpconn = MockHTTPClass ()
532+ def __init__ (self , debuglevel = None , context = None , check_hostname = None ):
533+ super (MockHTTPSHandler , self ).__init__ (debuglevel , context , check_hostname )
534+ self .httpconn = MockHTTPClass ()
534535
535- def https_open (self , req ):
536- return self .do_open (self .httpconn , req )
536+ def https_open (self , req ):
537+ return self .do_open (self .httpconn , req )
537538
538539
539540class MockHTTPHandlerCheckAuth (urllib .request .BaseHandler ):
@@ -1075,6 +1076,7 @@ def test_http_handler_local_debuglevel(self):
10751076 o .open ("http://www.example.com" )
10761077 self .assertEqual (h ._debuglevel , 5 )
10771078
1079+ @unittest .skipUnless (hasattr (http .client , 'HTTPSConnection' ), 'HTTPSConnection required for HTTPS tests.' )
10781080 def test_https_handler_global_debuglevel (self ):
10791081 with mock .patch .object (http .client .HTTPSConnection , 'debuglevel' , 7 ):
10801082 o = OpenerDirector ()
@@ -1083,6 +1085,7 @@ def test_https_handler_global_debuglevel(self):
10831085 o .open ("https://www.example.com" )
10841086 self .assertEqual (h ._debuglevel , 7 )
10851087
1088+ @unittest .skipUnless (hasattr (http .client , 'HTTPSConnection' ), 'HTTPSConnection required for HTTPS tests.' )
10861089 def test_https_handler_local_debuglevel (self ):
10871090 o = OpenerDirector ()
10881091 h = MockHTTPSHandler (debuglevel = 4 )
@@ -1456,6 +1459,7 @@ def test_proxy_https(self):
14561459 self .assertEqual ([(handlers [0 ], "https_open" )],
14571460 [tup [0 :2 ] for tup in o .calls ])
14581461
1462+ @unittest .skipUnless (hasattr (http .client , 'HTTPSConnection' ), 'HTTPSConnection required for HTTPS tests.' )
14591463 def test_proxy_https_proxy_authorization (self ):
14601464 o = OpenerDirector ()
14611465 ph = urllib .request .ProxyHandler (dict (https = 'proxy.example.com:3128' ))
0 commit comments