MCPcopy
hub / github.com/urllib3/urllib3 / resolve_cert_reqs

Function resolve_cert_reqs

src/urllib3/util/ssl_.py:141–161  ·  view source on GitHub ↗

Resolves the argument to a numeric constant, which can be passed to the wrap_socket function/method from the ssl module. Defaults to :data:`ssl.CERT_REQUIRED`. If given a string it is assumed to be the name of the constant in the :mod:`ssl` module or its abbreviation. (So yo

(candidate: None | int | str)

Source from the content-addressed store, hash-verified

139
140
141def resolve_cert_reqs(candidate: None | int | str) -> VerifyMode:
142 """
143 Resolves the argument to a numeric constant, which can be passed to
144 the wrap_socket function/method from the ssl module.
145 Defaults to :data:`ssl.CERT_REQUIRED`.
146 If given a string it is assumed to be the name of the constant in the
147 :mod:`ssl` module or its abbreviation.
148 (So you can specify `REQUIRED` instead of `CERT_REQUIRED`.
149 If it's neither `None` nor a string we assume it is already the numeric
150 constant which can directly be passed to wrap_socket.
151 """
152 if candidate is None:
153 return CERT_REQUIRED
154
155 if isinstance(candidate, str):
156 res = getattr(ssl, candidate, None)
157 if res is None:
158 res = getattr(ssl, "CERT_" + candidate)
159 return res # type: ignore[no-any-return]
160
161 return candidate # type: ignore[return-value]
162
163
164def resolve_ssl_version(candidate: None | int | str) -> int:

Callers 5

ssl_options_to_contextFunction · 0.90
__init__Method · 0.85
set_certMethod · 0.85

Calls

no outgoing calls

Tested by 1