]> git.ipfire.org Git - thirdparty/dnspython.git/commitdiff
WireData did not implement the iteration protocol correctly and was thus uniterable.
authorBob Halley <halley@dnspython.org>
Sat, 30 May 2020 13:37:14 +0000 (06:37 -0700)
committerBob Halley <halley@dnspython.org>
Sat, 30 May 2020 13:37:14 +0000 (06:37 -0700)
dns/wiredata.py
tests/test_wiredata.py

index 71edf91943b77deae31a1021114a4150249c02e4..64bc120a79d30d54c37ecadbf0af2aaa7d044abb 100644 (file)
@@ -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)
index 7b59c3cd14e651d318047d6409eb17ad95cf2d76..9274259af7eccbdba20733105c1991378b561e4f 100644 (file)
@@ -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)