Skip to content

Commit 6fc17ed

Browse files
committed
More readable response parsing code in Response.__init__()
1 parent 4bf6921 commit 6fc17ed

File tree

1 file changed

+11
-2
lines changed

1 file changed

+11
-2
lines changed

src/tarantool/response.py

+11-2
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,7 @@ def __init__(self, _socket, field_types=None):
8585
:params _socket: socket connected to the server
8686
:type _socket: instance of socket.socket class (from stdlib)
8787
'''
88-
88+
# This is not necessary, because underlying list data structures are created in the __new__(). But let it be.
8989
super(Response, self).__init__()
9090

9191
self._body_length = None
@@ -100,23 +100,32 @@ def __init__(self, _socket, field_types=None):
100100
# Read response header
101101
buff = ctypes.create_string_buffer(16)
102102
nbytes = _socket.recv_into(buff, 16, )
103+
103104
# Immediately raises an exception if the data cannot be read
104105
if nbytes != 16:
105106
raise socket.error(socket.errno.ECONNABORTED, "Software caused connection abort")
107+
106108
# Unpack header (including <return_code> attribute)
107109
self._request_type, self._body_length, self._request_id, self._return_code = struct_LLLL.unpack(buff)
110+
108111
# Separate return_code and completion_code
109112
self._completion_status = self._return_code & 0x00ff
110113
self._return_code = self._return_code >> 8
114+
111115
# Unpack body if there is one (i.e. not PING)
112116
if self._body_length != 0:
113-
self._body_length -= 4 # In the protocol description <body_length> includes 4 bytes of <return_code>
117+
118+
# In the protocol description <body_length> includes 4 bytes of <return_code>
119+
self._body_length -= 4
120+
114121
# Read response body
115122
buff = ctypes.create_string_buffer(self._body_length)
116123
nbytes = _socket.recv_into(buff)
124+
117125
# Immediately raises an exception if the data cannot be read
118126
if nbytes != self._body_length:
119127
raise socket.error(socket.errno.ECONNABORTED, "Software caused connection abort")
128+
120129
if self._return_code == 0:
121130
# If no errors, unpack response body
122131
self._unpack_body(buff)

0 commit comments

Comments
 (0)