Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Refactor Code Expression #2894

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
4 changes: 1 addition & 3 deletions docker/context/context.py
Original file line number Diff line number Diff line change
Expand Up @@ -205,9 +205,7 @@ def Orchestrator(self):

@property
def Metadata(self):
meta = {}
if self.orchestrator:
meta = {"StackOrchestrator": self.orchestrator}
meta = {"StackOrchestrator": self.orchestrator} if self.orchestrator else {}
return {
"Name": self.name,
"Metadata": meta,
Expand Down
2 changes: 1 addition & 1 deletion docker/models/plugins.py
Original file line number Diff line number Diff line change
Expand Up @@ -180,7 +180,7 @@ def install(self, remote_name, local_name=None):
"""
privileges = self.client.api.plugin_privileges(remote_name)
it = self.client.api.pull_plugin(remote_name, privileges, local_name)
for data in it:
for _ in it:
pass
return self.get(local_name or remote_name)

Expand Down
3 changes: 2 additions & 1 deletion docker/models/swarm.py
Original file line number Diff line number Diff line change
Expand Up @@ -121,8 +121,9 @@ def init(self, advertise_addr=None, listen_addr='0.0.0.0:2377',
'default_addr_pool': default_addr_pool,
'subnet_size': subnet_size,
'data_path_addr': data_path_addr,
'swarm_spec': self.client.api.create_swarm_spec(**kwargs),
}
init_kwargs['swarm_spec'] = self.client.api.create_swarm_spec(**kwargs)

node_id = self.client.api.init_swarm(**init_kwargs)
self.reload()
return node_id
Expand Down
48 changes: 25 additions & 23 deletions docker/types/daemon.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,33 +42,35 @@ def close(self):
Closes the event streaming.
"""

if not self._response.raw.closed:
# find the underlying socket object
# based on api.client._get_raw_response_socket
if self._response.raw.closed:
return

sock_fp = self._response.raw._fp.fp
# find the underlying socket object
# based on api.client._get_raw_response_socket

if hasattr(sock_fp, 'raw'):
sock_raw = sock_fp.raw
sock_fp = self._response.raw._fp.fp

if hasattr(sock_raw, 'sock'):
sock = sock_raw.sock
if hasattr(sock_fp, 'raw'):
sock_raw = sock_fp.raw

elif hasattr(sock_raw, '_sock'):
sock = sock_raw._sock
if hasattr(sock_raw, 'sock'):
sock = sock_raw.sock

elif hasattr(sock_fp, 'channel'):
# We're working with a paramiko (SSH) channel, which doesn't
# support cancelable streams with the current implementation
raise DockerException(
'Cancellable streams not supported for the SSH protocol'
)
else:
sock = sock_fp._sock
elif hasattr(sock_raw, '_sock'):
sock = sock_raw._sock

if hasattr(urllib3.contrib, 'pyopenssl') and isinstance(
sock, urllib3.contrib.pyopenssl.WrappedSocket):
sock = sock.socket
elif hasattr(sock_fp, 'channel'):
# We're working with a paramiko (SSH) channel, which doesn't
# support cancelable streams with the current implementation
raise DockerException(
'Cancellable streams not supported for the SSH protocol'
)
else:
sock = sock_fp._sock

sock.shutdown(socket.SHUT_RDWR)
sock.close()
if hasattr(urllib3.contrib, 'pyopenssl') and isinstance(
sock, urllib3.contrib.pyopenssl.WrappedSocket):
sock = sock.socket

sock.shutdown(socket.SHUT_RDWR)
sock.close()
7 changes: 3 additions & 4 deletions docker/utils/socket.py
Original file line number Diff line number Diff line change
Expand Up @@ -146,11 +146,10 @@ def consume_socket_output(frames, demux=False):
out[0] = frame[0]
else:
out[0] += frame[0]
elif out[1] is None:
out[1] = frame[1]
else:
if out[1] is None:
out[1] = frame[1]
else:
out[1] += frame[1]
out[1] += frame[1]
return tuple(out)


Expand Down