Skip to content

Commit 368d0d7

Browse files
committed
ws_client: Add option to disable capture-all
1 parent ced17c6 commit 368d0d7

File tree

2 files changed

+16
-4
lines changed

2 files changed

+16
-4
lines changed

stream/stream.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,8 @@
1616

1717

1818
def stream(func, *args, **kwargs):
19-
"""Stream given API call using websocket"""
19+
"""Stream given API call using websocket.
20+
Extra kwarg: capture-all=True - captures all stdout+stderr for use with WSClient.read_all()"""
2021

2122
def _intercept_request_call(*args, **kwargs):
2223
# old generated code's api client has config. new ones has

stream/ws_client.py

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -34,9 +34,16 @@
3434
ERROR_CHANNEL = 3
3535
RESIZE_CHANNEL = 4
3636

37+
class _IgnoredIO:
38+
def write(self, _x):
39+
pass
40+
41+
def getvalue(self):
42+
raise TypeError("Tried to read_all() from a WSClient configured to not capture. Did you mean `capture_all=True`?")
43+
3744

3845
class WSClient:
39-
def __init__(self, configuration, url, headers):
46+
def __init__(self, configuration, url, headers, capture_all):
4047
"""A websocket client with support for channels.
4148
4249
Exec command uses different channels for different streams. for
@@ -48,7 +55,10 @@ def __init__(self, configuration, url, headers):
4855
header = []
4956
self._connected = False
5057
self._channels = {}
51-
self._all = StringIO()
58+
if capture_all:
59+
self._all = StringIO()
60+
else:
61+
self._all = _IgnoredIO()
5262

5363
# We just need to pass the Authorization, ignore all the other
5464
# http headers we get from the generated code
@@ -258,6 +268,7 @@ def websocket_call(configuration, *args, **kwargs):
258268
url = args[1]
259269
_request_timeout = kwargs.get("_request_timeout", 60)
260270
_preload_content = kwargs.get("_preload_content", True)
271+
capture_all = kwargs.get("capture_all", True)
261272
headers = kwargs.get("headers")
262273

263274
# Expand command parameter list to indivitual command params
@@ -273,7 +284,7 @@ def websocket_call(configuration, *args, **kwargs):
273284
url += '?' + urlencode(query_params)
274285

275286
try:
276-
client = WSClient(configuration, get_websocket_url(url), headers)
287+
client = WSClient(configuration, get_websocket_url(url), headers, capture_all)
277288
if not _preload_content:
278289
return client
279290
client.run_forever(timeout=_request_timeout)

0 commit comments

Comments
 (0)