3434ERROR_CHANNEL = 3
3535RESIZE_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
3845class 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