diff Lib/struct.py @ 38277:b825e6227366 legacy-trunk

refactor unpack, add unpack_from
author Bob Ippolito <bob@redivi.com>
date Wed, 24 May 2006 15:32:06 +0000
parents de9f1a140611
children b2491fd0a4dc
line wrap: on
line diff
--- a/Lib/struct.py	Wed May 24 15:11:01 2006 +0000
+++ b/Lib/struct.py	Wed May 24 15:32:06 2006 +0000
@@ -73,3 +73,15 @@
     except KeyError:
         o = _compile(fmt)
     return o.unpack(s)
+    
+def unpack_from(fmt, buf, offset=0):
+    """
+    Unpack the buffer, containing packed C structure data, according to
+    fmt starting at offset. Requires len(buffer[offset:]) >= calcsize(fmt).
+    See struct.__doc__ for more on format strings.
+    """
+    try:
+        o = _cache[fmt]
+    except KeyError:
+        o = _compile(fmt)
+    return o.unpack_from(buf, offset)
\ No newline at end of file