Skip to content

Commit ecc6f5c

Browse files
committed
add mixin for both connection
1 parent e602516 commit ecc6f5c

1 file changed

Lines changed: 20 additions & 9 deletions

File tree

shotgun_api3/shotgun.py

Lines changed: 20 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -190,30 +190,41 @@ def _set_socket_keepalive(sock) -> None:
190190
LOG.debug("Unable to set %s on socket." % option_name, exc_info=True)
191191

192192

193-
class KeepaliveHTTPConnection(HTTPConnectionWithTimeout):
193+
class _KeepaliveConnectionMixin(http.client.HTTPConnection):
194194
"""
195-
httplib2 HTTP connection that enables TCP keepalive once connected.
195+
Mixin that enables TCP keepalive once the connection is established.
196196
197-
Passed to ``httplib2.Http.request()`` as its ``connection_type`` so that the
198-
bundled httplib2 does not need to be modified.
197+
Must be listed before the httplib2 connection class so that this
198+
``connect()`` runs and delegates to the real one. ``self.sock`` is the
199+
SSL-wrapped socket for HTTPS, which delegates ``setsockopt`` to the socket
200+
underneath.
201+
202+
Derives from ``http.client.HTTPConnection``, the common base of both
203+
httplib2 connection classes, so that ``super().connect()`` resolves for type
204+
checkers. It is never instantiated on its own.
199205
"""
200206

201207
def connect(self) -> None:
202208
super().connect()
203209
_set_socket_keepalive(self.sock)
204210

205211

206-
class KeepaliveHTTPSConnection(HTTPSConnectionWithTimeout):
212+
class KeepaliveHTTPConnection(_KeepaliveConnectionMixin, HTTPConnectionWithTimeout):
207213
"""
208-
httplib2 HTTPS connection that enables TCP keepalive once connected.
214+
httplib2 HTTP connection that enables TCP keepalive once connected.
209215
210216
Passed to ``httplib2.Http.request()`` as its ``connection_type`` so that the
211217
bundled httplib2 does not need to be modified.
212218
"""
213219

214-
def connect(self) -> None:
215-
super().connect()
216-
_set_socket_keepalive(self.sock)
220+
221+
class KeepaliveHTTPSConnection(_KeepaliveConnectionMixin, HTTPSConnectionWithTimeout):
222+
"""
223+
httplib2 HTTPS connection that enables TCP keepalive once connected.
224+
225+
Passed to ``httplib2.Http.request()`` as its ``connection_type`` so that the
226+
bundled httplib2 does not need to be modified.
227+
"""
217228

218229

219230
# ----------------------------------------------------------------------------

0 commit comments

Comments
 (0)