1212from datetime import datetime , timedelta
1313from json .decoder import JSONDecodeError
1414
15- import decorator
1615import urllib3
1716from urllib3 .connection import match_hostname as urllib3_match_hostname
1817from urllib3 .util .ssl_ import ssl_wrap_socket as urllib3_ssl_wrap_socket
1918from urllib3 .util .ssl_ import wrap_socket as urllib3_wrap_socket
2019
2120from .compat import basestring , byte_type , decode_from_bytes , encode_to_bytes , text_type
22- from .utils import SSL_PROTOCOL , MocketSocketCore , hexdump , hexload
21+ from .utils import SSL_PROTOCOL , MocketSocketCore , get_mocketize , hexdump , hexload
2322
2423xxh32 = None
2524try :
@@ -65,6 +64,11 @@ def __set__(self, *args):
6564
6665
6766class FakeSSLContext (SuperFakeSSLContext ):
67+ DUMMY_METHODS = (
68+ "load_default_certs" ,
69+ "load_verify_locations" ,
70+ "set_alpn_protocols" ,
71+ )
6872 sock = None
6973 post_handshake_auth = None
7074 _check_hostname = False
@@ -78,6 +82,8 @@ def check_hostname(self, *args):
7882 self ._check_hostname = False
7983
8084 def __init__ (self , sock = None , server_hostname = None , _context = None , * args , ** kwargs ):
85+ self ._set_dummy_methods ()
86+
8187 if isinstance (sock , MocketSocket ):
8288 self .sock = sock
8389 self .sock ._host = server_hostname
@@ -89,13 +95,12 @@ def __init__(self, sock=None, server_hostname=None, _context=None, *args, **kwar
8995 elif isinstance (sock , int ) and true_ssl_context :
9096 self .context = true_ssl_context (sock )
9197
92- @ staticmethod
93- def load_default_certs (* args , ** kwargs ):
94- pass
98+ def _set_dummy_methods ( self ):
99+ def dummy_method (* args , ** kwargs ):
100+ pass
95101
96- @staticmethod
97- def load_verify_locations (* args , ** kwargs ):
98- pass
102+ for m in self .DUMMY_METHODS :
103+ setattr (self , m , dummy_method )
99104
100105 @staticmethod
101106 def wrap_socket (sock = sock , * args , ** kwargs ):
@@ -640,7 +645,4 @@ def wrapper(test, cls=Mocketizer, truesocket_recording_dir=None, *args, **kwargs
640645 return test (* args , ** kwargs )
641646
642647
643- if decorator .__version__ < "5" :
644- mocketize = decorator .decorator (wrapper )
645- else :
646- mocketize = decorator .decorator (wrapper , kwsyntax = True )
648+ mocketize = get_mocketize (wrapper_ = wrapper )
0 commit comments