37
37
38
38
39
39
class HTTPSConnection (urllib3 .connection .HTTPSConnection ):
40
+ def __init__ (self , * args : Any , ** kwargs : Any ) -> None :
41
+ self ._elastic_assert_fingerprint : Optional [str ] = None
42
+ super ().__init__ (* args , ** kwargs )
43
+
40
44
def connect (self ) -> None :
41
45
super ().connect ()
42
46
# Hack to prevent a warning within HTTPSConnectionPool._validate_conn()
@@ -80,16 +84,16 @@ def _new_conn(self) -> HTTPSConnection:
80
84
"""
81
85
Return a fresh :class:`urllib3.connection.HTTPSConnection`.
82
86
"""
83
- conn = super ()._new_conn ()
87
+ conn : HTTPSConnection = super ()._new_conn () # type: ignore[assignment]
84
88
# Tell our custom connection if we'll assert fingerprint ourselves
85
89
conn ._elastic_assert_fingerprint = self ._elastic_assert_fingerprint
86
90
return conn
87
91
88
- def _validate_conn (self , conn : urllib3 . connection . HTTPSConnection ) -> None :
92
+ def _validate_conn (self , conn : HTTPSConnection ) -> None : # type: ignore[override]
89
93
"""
90
94
Called right before a request is made, after the socket is created.
91
95
"""
92
- super (HTTPSConnectionPool , self )._validate_conn (conn ) # type: ignore[misc]
96
+ super (HTTPSConnectionPool , self )._validate_conn (conn )
93
97
94
98
if self ._elastic_assert_fingerprint :
95
99
hash_func = _HASHES_BY_LENGTH [len (self ._elastic_assert_fingerprint )]
@@ -107,7 +111,7 @@ def _validate_conn(self, conn: urllib3.connection.HTTPSConnection) -> None:
107
111
# See: https://github.com/python/cpython/pull/25467
108
112
fingerprints = [
109
113
hash_func (cert .public_bytes (_ENCODING_DER )).digest ()
110
- for cert in conn .sock ._sslobj .get_verified_chain ()
114
+ for cert in conn .sock ._sslobj .get_verified_chain () # type: ignore[union-attr]
111
115
]
112
116
except RERAISE_EXCEPTIONS : # pragma: nocover
113
117
raise
@@ -118,7 +122,7 @@ def _validate_conn(self, conn: urllib3.connection.HTTPSConnection) -> None:
118
122
119
123
# Only add the peercert in front of the chain if it's not there for some reason.
120
124
# This is to make sure old behavior of 'ssl_assert_fingerprint' still works.
121
- peercert_fingerprint = hash_func (conn .sock .getpeercert (True )).digest ()
125
+ peercert_fingerprint = hash_func (conn .sock .getpeercert (True )).digest () # type: ignore[union-attr]
122
126
if peercert_fingerprint not in fingerprints : # pragma: nocover
123
127
fingerprints .insert (0 , peercert_fingerprint )
124
128
0 commit comments