@@ -524,16 +524,17 @@ def http_open(self, req):
524
524
return MockResponse (200 , "OK" , msg , "" , req .get_full_url ())
525
525
526
526
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
530
531
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 ()
534
535
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 )
537
538
538
539
539
540
class MockHTTPHandlerCheckAuth (urllib .request .BaseHandler ):
@@ -1075,6 +1076,7 @@ def test_http_handler_local_debuglevel(self):
1075
1076
o .open ("http://www.example.com" )
1076
1077
self .assertEqual (h ._debuglevel , 5 )
1077
1078
1079
+ @unittest .skipUnless (hasattr (http .client , 'HTTPSConnection' ), 'HTTPSConnection required for HTTPS tests.' )
1078
1080
def test_https_handler_global_debuglevel (self ):
1079
1081
with mock .patch .object (http .client .HTTPSConnection , 'debuglevel' , 7 ):
1080
1082
o = OpenerDirector ()
@@ -1083,6 +1085,7 @@ def test_https_handler_global_debuglevel(self):
1083
1085
o .open ("https://www.example.com" )
1084
1086
self .assertEqual (h ._debuglevel , 7 )
1085
1087
1088
+ @unittest .skipUnless (hasattr (http .client , 'HTTPSConnection' ), 'HTTPSConnection required for HTTPS tests.' )
1086
1089
def test_https_handler_local_debuglevel (self ):
1087
1090
o = OpenerDirector ()
1088
1091
h = MockHTTPSHandler (debuglevel = 4 )
@@ -1456,6 +1459,7 @@ def test_proxy_https(self):
1456
1459
self .assertEqual ([(handlers [0 ], "https_open" )],
1457
1460
[tup [0 :2 ] for tup in o .calls ])
1458
1461
1462
+ @unittest .skipUnless (hasattr (http .client , 'HTTPSConnection' ), 'HTTPSConnection required for HTTPS tests.' )
1459
1463
def test_proxy_https_proxy_authorization (self ):
1460
1464
o = OpenerDirector ()
1461
1465
ph = urllib .request .ProxyHandler (dict (https = 'proxy.example.com:3128' ))
0 commit comments