34
34
ERROR_CHANNEL = 3
35
35
RESIZE_CHANNEL = 4
36
36
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
+
37
44
38
45
class WSClient :
39
- def __init__ (self , configuration , url , headers ):
46
+ def __init__ (self , configuration , url , headers , capture_all ):
40
47
"""A websocket client with support for channels.
41
48
42
49
Exec command uses different channels for different streams. for
@@ -48,7 +55,10 @@ def __init__(self, configuration, url, headers):
48
55
header = []
49
56
self ._connected = False
50
57
self ._channels = {}
51
- self ._all = StringIO ()
58
+ if capture_all :
59
+ self ._all = StringIO ()
60
+ else :
61
+ self ._all = _IgnoredIO ()
52
62
53
63
# We just need to pass the Authorization, ignore all the other
54
64
# http headers we get from the generated code
@@ -258,6 +268,7 @@ def websocket_call(configuration, *args, **kwargs):
258
268
url = args [1 ]
259
269
_request_timeout = kwargs .get ("_request_timeout" , 60 )
260
270
_preload_content = kwargs .get ("_preload_content" , True )
271
+ capture_all = kwargs .get ("capture_all" , True )
261
272
headers = kwargs .get ("headers" )
262
273
263
274
# Expand command parameter list to indivitual command params
@@ -273,7 +284,7 @@ def websocket_call(configuration, *args, **kwargs):
273
284
url += '?' + urlencode (query_params )
274
285
275
286
try :
276
- client = WSClient (configuration , get_websocket_url (url ), headers )
287
+ client = WSClient (configuration , get_websocket_url (url ), headers , capture_all )
277
288
if not _preload_content :
278
289
return client
279
290
client .run_forever (timeout = _request_timeout )
0 commit comments