Merge pull request 'improve compatibility with Python 3.10' (#40) from nic/AV-98:master into master

Reviewed-on: #40
This commit is contained in:
Solderpunk 2023-11-12 10:18:29 +00:00
commit a1cb220113
1 changed files with 9 additions and 2 deletions

11
av98.py
View File

@ -548,8 +548,15 @@ you'll be able to transparently follow links to Gopherspace!""")
addresses = self._get_addresses(host, port)
# Prepare TLS context
protocol = ssl.PROTOCOL_TLS if sys.version_info.minor >=6 else ssl.PROTOCOL_TLSv1_2
context = ssl.SSLContext(protocol)
def _newest_supported_protocol():
if sys.version_info >= (3, 10):
return ssl.PROTOCOL_TLS_CLIENT
elif sys.version_info >= (3, 6):
return ssl.PROTOCOL_TLS
else:
return ssl.PROTOCOL_TLSv1_2
context = ssl.SSLContext(_newest_supported_protocol())
# Use CAs or TOFU
if self.options["tls_mode"] == "ca":
context.verify_mode = ssl.CERT_REQUIRED