summaryrefslogtreecommitdiff
path: root/Lib/struct.py
diff options
context:
space:
mode:
authorBob Ippolito <bob@redivi.com>2006-05-24 15:32:06 +0000
committerBob Ippolito <bob@redivi.com>2006-05-24 15:32:06 +0000
commit609a3ce1c076e87c943786235ef3bc29677a3ee9 (patch)
tree23a845ec384ad139fff364b08ef239b7473c4194 /Lib/struct.py
parentce3da6731a842b51a3ca847b37f64f5498bacc62 (diff)
downloadcpython-609a3ce1c076e87c943786235ef3bc29677a3ee9.tar.gz
refactor unpack, add unpack_from
Diffstat (limited to 'Lib/struct.py')
-rw-r--r--Lib/struct.py12
1 files changed, 12 insertions, 0 deletions
diff --git a/Lib/struct.py b/Lib/struct.py
index ee5ddc265c..648e39c2d7 100644
--- a/Lib/struct.py
+++ b/Lib/struct.py
@@ -73,3 +73,15 @@ def unpack(fmt, s):
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