Skip to content

Commit 9da5493

Browse files
committed
Use backports.ssl_match_hostname
The py2-ipaddress module unfortunately conflicts with the pypi:ipaddress module, which is in the dependency tree of widely used pyOpenSSL. I think it would be a good idea to use a well maintained backport of the Python 3.5 implementation of match_hostname() instead of duplicating the effort and maintain another. All tests are passing here. Signed-off-by: Felix Yan <[email protected]>
1 parent fdd1187 commit 9da5493

File tree

5 files changed

+12
-136
lines changed

5 files changed

+12
-136
lines changed

docker/ssladapter/ssl_match_hostname.py

Lines changed: 0 additions & 130 deletions
This file was deleted.

docker/ssladapter/ssladapter.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818
# Monkey-patching match_hostname with a version that supports
1919
# IP-address checking. Not necessary for Python 3.5 and above
2020
if sys.version_info[0] < 3 or sys.version_info[1] < 5:
21-
from .ssl_match_hostname import match_hostname
21+
from backports.ssl_match_hostname import match_hostname
2222
urllib3.connection.match_hostname = match_hostname
2323

2424

requirements.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
requests==2.5.3
22
six>=1.4.0
33
websocket-client==0.32.0
4-
py2-ipaddress==3.4.1 ; python_version < '3.2'
4+
backports.ssl_match_hostname>=3.5 ; python_version < '3.5'

setup.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
]
1414

1515
extras_require = {
16-
':python_version < "3"': 'py2-ipaddress >= 3.4.1',
16+
':python_version < "3.5"': 'backports.ssl_match_hostname >= 3.5',
1717
}
1818

1919
exec(open('docker/version.py').read())

tests/unit/ssladapter_test.py

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,13 @@
11
from docker.ssladapter import ssladapter
2-
from docker.ssladapter.ssl_match_hostname import (
3-
match_hostname, CertificateError
4-
)
2+
3+
try:
4+
from backports.ssl_match_hostname import (
5+
match_hostname, CertificateError
6+
)
7+
except ImportError:
8+
from ssl import (
9+
match_hostname, CertificateError
10+
)
511

612
try:
713
from ssl import OP_NO_SSLv3, OP_NO_SSLv2, OP_NO_TLSv1

0 commit comments

Comments
 (0)