Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Python 3.12 compatibility - closes #1057
There are two Python 3.12 changes that affect the pyVmomi client - Python 3.12 removes ssl.wrap_socket(), deprecated in Python 3.7. ssl.SSLContext.wrap_socket() should be used instead. Ref. https://docs.python.org/3/whatsnew/3.12.html#ssl - key_file, cert_file are removed from http.client.HTTPSConnection. Ref. https://docs.python.org/3/whatsnew/3.12.html#others This change: - The connection logic is refactored to comply with the new Python rules. Python now forces users to generate the SSL context on their own. However, the SoapStubAdapter still has to accept the cert and key pair and SSL context at the same time to keep backwards compatibility for all existing tests and clients. To do that, instead of relying on the http module to generate the SSL context if none is provided, the SoapStubAdapter now handles that generation by mirroring the http module code before the Python 3.12 changes. Because the SSL context generation is pulled to be executed as early as possible there is no need to figure out what parameters are acceptable to pass to the Python http module because the context is already generated. Therefore, the HTTP connection wrappers can be removed - _HTTPConnection and _HTTPSConnection. - ssl.create_default_context() is replaced with SSL._create_default_https_context() to mirror the HTTP module logic. This change is propagated to the sso.py module to keep the behavior consistent. Additional changes: Breaking change: - SSLTunnelConnection is trimmed down to handle only tunnel connections. The code that handles remote proxy doubles the HTTPProxyConnection logic and therefore is removed. This is a breaking change for consumers that wrongly set "sslProxyPath" instead of "httpProxyHost" when they want to go through a remote proxy but I consider this a necessary change because allowing this behavior is a bug and shouldn't have been available at first place. Non-breaking changes: - SSLTunnelConnection now inherits HTTPProxyConnection and overwrites the call method because the constructor is the same. Keep in mind that it's deprecated. Hopefully it will be removed sooner rather than later. - _CheckIPv4(), _CheckIPv6() and _CheckHostname() are removed because it's not necessary to make those verifications when SSLTunnelConnection does not support remote proxies. - Small changes to variable names and imports
- Loading branch information