Author: Ronan Lamy <ronan.l...@gmail.com>
Branch: py3.5
Changeset: r88035:bbc8635cc762
Date: 2016-11-01 15:50 +0000
http://bitbucket.org/pypy/pypy/changeset/bbc8635cc762/

Log:    Implement struct.iter_unpack() function

diff --git a/pypy/module/struct/__init__.py b/pypy/module/struct/__init__.py
--- a/pypy/module/struct/__init__.py
+++ b/pypy/module/struct/__init__.py
@@ -55,6 +55,7 @@
         'pack_into': 'interp_struct.pack_into',
         'unpack': 'interp_struct.unpack',
         'unpack_from': 'interp_struct.unpack_from',
+        'iter_unpack': 'interp_struct.iter_unpack',
 
         'Struct': 'interp_struct.W_Struct',
         '_clearcache': 'interp_struct.clearcache',
diff --git a/pypy/module/struct/interp_struct.py 
b/pypy/module/struct/interp_struct.py
--- a/pypy/module/struct/interp_struct.py
+++ b/pypy/module/struct/interp_struct.py
@@ -186,5 +186,11 @@
     #__length_hint__=
 )
 
+@unwrap_spec(format=str)
+def iter_unpack(space, format, w_buffer):
+    w_struct = W_Struct(space, format)
+    buf = space.buffer_w(w_buffer, space.BUF_SIMPLE)
+    return W_UnpackIter(w_struct, buf)
+
 def clearcache(space):
     """No-op on PyPy"""
diff --git a/pypy/module/struct/test/test_struct.py 
b/pypy/module/struct/test/test_struct.py
--- a/pypy/module/struct/test/test_struct.py
+++ b/pypy/module/struct/test/test_struct.py
@@ -400,6 +400,8 @@
         s = self.struct.Struct('ii')
         it = s.iter_unpack(b)
         assert list(it) == [(0, 0), (0, 0)]
+        it = self.struct.iter_unpack('ii', b)
+        assert list(it) == [(0, 0), (0, 0)]
 
     def test___float__(self):
         class MyFloat(object):
_______________________________________________
pypy-commit mailing list
pypy-commit@python.org
https://mail.python.org/mailman/listinfo/pypy-commit

Reply via email to