@@ -99,7 +99,7 @@ class Protocol(threading.local):
99
99
COMPRESSION_THRESHOLD = 128
100
100
101
101
def __init__ (self , server , username = None , password = None , compression = None , socket_timeout = None ,
102
- pickle_protocol = None , pickler = None , unpickler = None ):
102
+ pickle_protocol = None , pickler = None , unpickler = None , tls_context = None ):
103
103
super (Protocol , self ).__init__ ()
104
104
self .server = server
105
105
self ._username = username
@@ -112,6 +112,7 @@ def __init__(self, server, username=None, password=None, compression=None, socke
112
112
self .pickle_protocol = pickle_protocol
113
113
self .pickler = pickler
114
114
self .unpickler = unpickler
115
+ self .tls_context = tls_context
115
116
116
117
self .reconnects_deferred_until = None
117
118
@@ -144,6 +145,12 @@ def _open_connection(self):
144
145
self .connection = socket .socket (socket .AF_INET , socket .SOCK_STREAM )
145
146
self .connection .settimeout (self .socket_timeout )
146
147
self .connection .connect ((self .host , self .port ))
148
+
149
+ if self .tls_context :
150
+ self .connection = self .tls_context .wrap_socket (
151
+ self .connection ,
152
+ server_hostname = self .host ,
153
+ )
147
154
else :
148
155
self .connection = socket .socket (socket .AF_UNIX , socket .SOCK_STREAM )
149
156
self .connection .connect (self .server )
0 commit comments