diff options
author | Andrey Zelenkov <zelenkov@nginx.com> | 2019-08-30 15:37:44 +0300 |
---|---|---|
committer | Andrey Zelenkov <zelenkov@nginx.com> | 2019-08-30 15:37:44 +0300 |
commit | ccd6c0dc057e32ae50aec6d692a624119b1aa925 (patch) | |
tree | fdb95ffb0d7386c6b7404312d94dfa1f71a0e022 /test/unit | |
parent | 7053a35a60bdacdfcf1277dd8f08f6c46c8028c7 (diff) | |
download | unit-ccd6c0dc057e32ae50aec6d692a624119b1aa925.tar.gz unit-ccd6c0dc057e32ae50aec6d692a624119b1aa925.tar.bz2 |
Tests: websockets style fixes.
Diffstat (limited to '')
-rw-r--r-- | test/unit/applications/websockets.py | 18 |
1 files changed, 9 insertions, 9 deletions
diff --git a/test/unit/applications/websockets.py b/test/unit/applications/websockets.py index 417e9504..0a343875 100644 --- a/test/unit/applications/websockets.py +++ b/test/unit/applications/websockets.py @@ -54,7 +54,7 @@ class TestApplicationWebsocket(TestApplicationProto): def apply_mask(self, data, mask): return bytes(b ^ m for b, m in zip(data, itertools.cycle(mask))) - def serialize_close(self, code = 1000, reason = ''): + def serialize_close(self, code=1000, reason=''): return struct.pack('!H', code) + reason.encode('utf-8') def frame_read(self, sock, read_timeout=10): @@ -66,9 +66,7 @@ class TestApplicationWebsocket(TestApplicationProto): data = sock.recv(bytes) else: data = self.recvall( - sock, - read_timeout=read_timeout, - buff_size=bytes, + sock, read_timeout=read_timeout, buff_size=bytes ) break except: @@ -180,7 +178,7 @@ class TestApplicationWebsocket(TestApplicationProto): else: pos = 0 frame_len = len(frame) - while (pos < frame_len): + while pos < frame_len: end = min(pos + chopsize, frame_len) sock.sendall(frame[pos:end]) pos = end @@ -197,17 +195,19 @@ class TestApplicationWebsocket(TestApplicationProto): pos = 0 op_code = type - while(pos < message_len): + while pos < message_len: end = min(pos + fragmention_size, message_len) - fin = (end == message_len) - self.frame_write(sock, op_code, message[pos:end], fin=fin, **kwargs) + fin = end == message_len + self.frame_write( + sock, op_code, message[pos:end], fin=fin, **kwargs + ) op_code = self.OP_CONT pos = end def message_read(self, sock, read_timeout=10): frame = self.frame_read(sock, read_timeout=read_timeout) - while(not frame['fin']): + while not frame['fin']: temp = self.frame_read(sock, read_timeout=read_timeout) frame['data'] += temp['data'] frame['fin'] = temp['fin'] |