[pypy-svn] r59397 - pypy/trunk/pypy/module/struct
fijal at codespeak.net
fijal at codespeak.net
Sat Oct 25 13:45:19 CEST 2008
Author: fijal
Date: Sat Oct 25 13:45:19 2008
New Revision: 59397
Modified:
pypy/trunk/pypy/module/struct/__init__.py
pypy/trunk/pypy/module/struct/app_struct.py
Log:
supply dummy Struct type
Modified: pypy/trunk/pypy/module/struct/__init__.py
==============================================================================
--- pypy/trunk/pypy/module/struct/__init__.py (original)
+++ pypy/trunk/pypy/module/struct/__init__.py Sat Oct 25 13:45:19 2008
@@ -55,4 +55,5 @@
'error': 'app_struct.error',
'pack_into': 'app_struct.pack_into',
'unpack_from': 'app_struct.unpack_from',
+ 'Struct': 'app_struct.Struct',
}
Modified: pypy/trunk/pypy/module/struct/app_struct.py
==============================================================================
--- pypy/trunk/pypy/module/struct/app_struct.py (original)
+++ pypy/trunk/pypy/module/struct/app_struct.py Sat Oct 25 13:45:19 2008
@@ -21,3 +21,21 @@
raise error("unpack_from requires a buffer of at least %d bytes"
% (size,))
return struct.unpack(fmt, data)
+
+# XXX inefficient
+class Struct(object):
+ def __init__(self, format):
+ self.format = format
+ self.size = struct.calcsize(format)
+
+ def pack(self, *args):
+ return struct.pack(self.format, *args)
+
+ def unpack(self, s):
+ return struct.unpack(self.format, s)
+
+ def pack_into(self, buffer, offset, *args):
+ return pack_info(self.format, buffer, offset, *args)
+
+ def unpack_from(self, buffer, offset=0):
+ return unpack_from(self.format, buffer, offset)
More information about the Pypy-commit
mailing list