Skip to content

Commit c7cf483

Browse files
committed
SSLContext.wrap_socket() is good to use in 3.6
1 parent d82ada0 commit c7cf483

1 file changed

Lines changed: 6 additions & 15 deletions

File tree

lib/createsend/utils.py

Lines changed: 6 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -99,21 +99,12 @@ def connect(self):
9999

100100
cert_path = os.path.join(os.path.dirname(__file__), 'cacert.pem')
101101

102-
# for >= py3.7, mandatory since 3.12
103-
if hasattr(ssl.SSLContext, 'wrap_socket'):
104-
context = ssl.SSLContext()
105-
context.verify_mode = ssl.CERT_REQUIRED
106-
context.load_verify_locations(cert_path)
107-
if hasattr(self, 'cert_file') and hasattr(self, 'key_file') and self.cert_file and self.key_file:
108-
context.load_cert_chain(certfile=self.cert_file, keyfile=self.key_file)
109-
self.sock = context.wrap_socket(sock)
110-
else:
111-
self.sock = ssl.wrap_socket(
112-
sock,
113-
self.key_file,
114-
self.cert_file,
115-
cert_reqs=ssl.CERT_REQUIRED,
116-
ca_certs=cert_path)
102+
context = ssl.SSLContext()
103+
context.verify_mode = ssl.CERT_REQUIRED
104+
context.load_verify_locations(cert_path)
105+
if hasattr(self, 'cert_file') and hasattr(self, 'key_file') and self.cert_file and self.key_file:
106+
context.load_cert_chain(certfile=self.cert_file, keyfile=self.key_file)
107+
self.sock = context.wrap_socket(sock)
117108

118109
try:
119110
match_hostname(self.sock.getpeercert(), self.host)

0 commit comments

Comments
 (0)