From e625fd5444bda7a6b619c256eaf86a2ff0d51c6c Mon Sep 17 00:00:00 2001 From: Guido van Rossum Date: Sun, 27 May 2007 09:19:04 +0000 Subject: Make struct tests pass. --- Lib/struct.py | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) (limited to 'Lib/struct.py') diff --git a/Lib/struct.py b/Lib/struct.py index 1077437a4a..027caa258b 100644 --- a/Lib/struct.py +++ b/Lib/struct.py @@ -31,7 +31,13 @@ The variable struct.error is an exception raised on errors. __version__ = '3.0' -from _struct import Struct, error +from _struct import Struct as _Struct, error + +class Struct(_Struct): + def __init__(self, fmt): + if isinstance(fmt, str): + fmt = str8(fmt) + _Struct.__init__(self, fmt) _MAXCACHE = 100 _cache = {} @@ -40,7 +46,7 @@ def _compile(fmt): # Internal: compile struct pattern if len(_cache) >= _MAXCACHE: _cache.clear() - s = Struct(str8(fmt)) + s = Struct(fmt) _cache[fmt] = s return s @@ -76,7 +82,7 @@ def pack_into(fmt, buf, offset, *args): o = _cache[fmt] except KeyError: o = _compile(fmt) - return bytes(o.pack_into(buf, offset, *args)) + o.pack_into(buf, offset, *args) def unpack(fmt, s): """ -- cgit v1.2.1