One function

NetstringSocket in mahmoud/boltons

The author described this change as Fix NetstringSocket to correctly use arguments to .read_ns() method.. It counts as a record because the check below fails on the code as it stood at 81e44a231 and passes on 0a20b37cc, with nothing else changed between the two runs.

Fix saved2020-03-28
Sharing licenceBSD-2-Clause · LICENSE
Change size+14 5

What the code was meant to do, written into the code itself as a docstring

Reads and writes using the netstring protocol. More info: https://en.wikipedia.org/wiki/Netstring Even more info: http://cr.yp.to/proto/netstrings.txt

The change

1919
2020 def setmaxsize(self, maxsize):
2121 self.maxsize = maxsize
22- self._msgsize_maxsize = len(str(maxsize)) + 1 # len(str()) == log10
22+ self._msgsize_maxsize = self._calc_msgsize_maxsize(maxsize)
2323
24+ def _calc_msgsize_maxsize(self, maxsize):
25+ return len(str(maxsize)) + 1 # len(str()) == log10
26+
2427 def read_ns(self, timeout=_UNSET, maxsize=_UNSET):
2528 if timeout is _UNSET:
2629 timeout = self.timeout
2730
31+ if maxsize is _UNSET:
32+ maxsize = self.maxsize
33+ msgsize_maxsize = self._msgsize_maxsize
34+ else:
35+ msgsize_maxsize = self._calc_msgsize_maxsize(maxsize)
36+
2837 size_prefix = self.bsock.recv_until(b':',
29- timeout=self.timeout,
30- maxsize=self._msgsize_maxsize)
38+ timeout=timeout,
39+ maxsize=msgsize_maxsize)
3140 try:
3241 size = int(size_prefix)
3342 except ValueError:
3443 raise NetstringInvalidSize('netstring message size must be valid'
3544 ' integer, not %r' % size_prefix)
3645
37- if size > self.maxsize:
38- raise NetstringMessageTooLong(size, self.maxsize)
46+ if size > maxsize:
47+ raise NetstringMessageTooLong(size, maxsize)
3948 payload = self.bsock.recv_size(size)
4049 if self.bsock.recv(1) != b',':
4150 raise NetstringProtocolError("expected trailing ',' after message")

The check that tells the two apart

failpass·tests/test_socketutils.py::test_socketutils_netstring_timeout

Check file tests/test_socketutils.py, taken without changes from the fix and copied onto the older code, so the exact same check runs against both versions.

Origin and history

The code before it81e44a2319ce0bef0de44f1059762b97879cb35d
Broken version dated2020-03-23
Moduleboltons.socketutils
Units changedNetstringSocket
Fingerprint5eeb36aac33ef446
Checked2026-08-18 by goldset/0.1

Every field above is generated by our program. None of it is written by hand.

Other bugs found in mahmoud/boltons