diff options
author | Bob Ippolito <bob@redivi.com> | 2006-05-24 15:32:06 (GMT) |
---|---|---|
committer | Bob Ippolito <bob@redivi.com> | 2006-05-24 15:32:06 (GMT) |
commit | eb62127842a04817a6fc3bedba4e7478e561279d (patch) | |
tree | 71befa7f281b21738bebab2bff2c354c277e2379 /Lib/struct.py | |
parent | d5e0dc51cf1e570e8ad06ddc78e9f9b15f0f3c3c (diff) | |
download | cpython-eb62127842a04817a6fc3bedba4e7478e561279d.zip cpython-eb62127842a04817a6fc3bedba4e7478e561279d.tar.gz cpython-eb62127842a04817a6fc3bedba4e7478e561279d.tar.bz2 |
refactor unpack, add unpack_from
Diffstat (limited to 'Lib/struct.py')
-rw-r--r-- | Lib/struct.py | 12 |
1 files changed, 12 insertions, 0 deletions
diff --git a/Lib/struct.py b/Lib/struct.py index ee5ddc2..648e39c 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 |