MCPcopy Index your code
hub / github.com/python/cpython / make_test_context

Function make_test_context

Lib/test/test_ssl.py:281–319  ·  view source on GitHub ↗
(
    *,
    server_side=False,
    check_hostname=None,
    cert_reqs=ssl.CERT_NONE,
    ca_certs=None, certfile=None, keyfile=None,
    ciphers=None, ciphersuites=None,
    min_version=None, max_version=None,
)

Source from the content-addressed store, hash-verified

279
280
281def make_test_context(
282 *,
283 server_side=False,
284 check_hostname=None,
285 cert_reqs=ssl.CERT_NONE,
286 ca_certs=None, certfile=None, keyfile=None,
287 ciphers=None, ciphersuites=None,
288 min_version=None, max_version=None,
289):
290 if server_side:
291 context = ssl.SSLContext(ssl.PROTOCOL_TLS_SERVER)
292 else:
293 context = ssl.SSLContext(ssl.PROTOCOL_TLS_CLIENT)
294
295 if check_hostname is None:
296 if cert_reqs == ssl.CERT_NONE:
297 context.check_hostname = False
298 else:
299 context.check_hostname = check_hostname
300
301 if cert_reqs is not None:
302 context.verify_mode = cert_reqs
303
304 if ca_certs is not None:
305 context.load_verify_locations(ca_certs)
306 if certfile is not None or keyfile is not None:
307 context.load_cert_chain(certfile, keyfile)
308
309 if ciphers is not None:
310 context.set_ciphers(ciphers)
311 if ciphersuites is not None:
312 context.set_ciphersuites(ciphersuites)
313
314 if min_version is not None:
315 context.minimum_version = min_version
316 if max_version is not None:
317 context.maximum_version = max_version
318
319 return context
320
321
322def test_wrap_socket(

Calls

no outgoing calls

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…