From: Bob Halley Date: Sat, 30 May 2020 13:37:14 +0000 (-0700) Subject: WireData did not implement the iteration protocol correctly and was thus uniterable. X-Git-Tag: v2.0.0rc1~140 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=fb47f0eb986fd9d203279377440548a84c45a29f;p=thirdparty%2Fdnspython.git WireData did not implement the iteration protocol correctly and was thus uniterable. --- diff --git a/dns/wiredata.py b/dns/wiredata.py index 71edf919..64bc120a 100644 --- a/dns/wiredata.py +++ b/dns/wiredata.py @@ -42,13 +42,8 @@ class WireData(bytes): raise dns.exception.FormError def __iter__(self): - i = 0 - while 1: - try: - yield self[i] - i += 1 - except dns.exception.FormError: - raise StopIteration + for i in range(len(self)): + yield self[i] def unwrap(self): return bytes(self) diff --git a/tests/test_wiredata.py b/tests/test_wiredata.py index 7b59c3cd..9274259a 100644 --- a/tests/test_wiredata.py +++ b/tests/test_wiredata.py @@ -9,7 +9,7 @@ import unittest from dns.exception import FormError -from dns.wiredata import WireData +from dns.wiredata import WireData, maybe_wrap class WireDataSlicingTestCase(unittest.TestCase): @@ -121,3 +121,14 @@ class WireDataSlicingTestCase(unittest.TestCase): inst = WireData(b'0123456789') with self.assertRaises(FormError): inst[10] # pylint: disable=pointless-statement + + def testIteration(self): + bval = b'0123' + inst = WireData(bval) + l = list(inst) + self.assertEqual(l, [x for x in bval]) + + def testBadWrap(self): + def bad(): + w = maybe_wrap(123) + self.assertRaises(ValueError, bad)