Skip to content

Commit

Permalink
Fix issues that break Salt in Python 3.12 and 3.13 (#698)
Browse files Browse the repository at this point in the history
  • Loading branch information
meaksh authored Jan 22, 2025
1 parent 7217fcc commit d7a6f92
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 12 deletions.
22 changes: 13 additions & 9 deletions salt/ext/tornado/netutil.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,15 +48,19 @@
if PY3:
xrange = range

if hasattr(ssl, 'match_hostname') and hasattr(ssl, 'CertificateError'): # python 3.2+
ssl_match_hostname = ssl.match_hostname
SSLCertificateError = ssl.CertificateError
elif ssl is None:
ssl_match_hostname = SSLCertificateError = None # type: ignore
else:
import backports.ssl_match_hostname
ssl_match_hostname = backports.ssl_match_hostname.match_hostname
SSLCertificateError = backports.ssl_match_hostname.CertificateError # type: ignore
try:
from salt.ext.ssl_match_hostname import CertificateError as SSLCertificateError
from salt.ext.ssl_match_hostname import match_hostname as ssl_match_hostname
except ImportError:
if hasattr(ssl, 'match_hostname') and hasattr(ssl, 'CertificateError'): # python 3.2+
ssl_match_hostname = ssl.match_hostname
SSLCertificateError = ssl.CertificateError
elif ssl is None:
ssl_match_hostname = SSLCertificateError = None # type: ignore
else:
import backports.ssl_match_hostname
ssl_match_hostname = backports.ssl_match_hostname.match_hostname
SSLCertificateError = backports.ssl_match_hostname.CertificateError # type: ignore

if hasattr(ssl, 'SSLContext'):
if hasattr(ssl, 'create_default_context'):
Expand Down
5 changes: 2 additions & 3 deletions salt/utils/url.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

import re
import sys
from urllib.parse import urlparse, urlunparse
from urllib.parse import urlparse, urlunparse, urlunsplit

import salt.utils.data
import salt.utils.path
Expand Down Expand Up @@ -47,8 +47,7 @@ def create(path, saltenv=None):
path = salt.utils.data.decode(path)

query = "saltenv={}".format(saltenv) if saltenv else ""
url = salt.utils.data.decode(urlunparse(("file", "", path, "", query, "")))
return "salt://{}".format(url[len("file:///") :])
return f'salt://{salt.utils.data.decode(urlunsplit(("", "", path, query, "")))}'


def is_escaped(url):
Expand Down

0 comments on commit d7a6f92

Please sign in to comment.