summaryrefslogtreecommitdiffstats
path: root/Lib/struct.py
diff options
context:
space:
mode:
authorGuido van Rossum <guido@python.org>2007-05-27 09:19:04 (GMT)
committerGuido van Rossum <guido@python.org>2007-05-27 09:19:04 (GMT)
commite625fd5444bda7a6b619c256eaf86a2ff0d51c6c (patch)
treec281767e808229e87371b493f7b5b5692c3aed48 /Lib/struct.py
parent54ad523f026afd4c06d567cfeeee0fb0e18ba444 (diff)
downloadcpython-e625fd5444bda7a6b619c256eaf86a2ff0d51c6c.zip
cpython-e625fd5444bda7a6b619c256eaf86a2ff0d51c6c.tar.gz
cpython-e625fd5444bda7a6b619c256eaf86a2ff0d51c6c.tar.bz2
Make struct tests pass.
Diffstat (limited to 'Lib/struct.py')
-rw-r--r--Lib/struct.py12
1 files changed, 9 insertions, 3 deletions
diff --git a/Lib/struct.py b/Lib/struct.py
index 1077437..027caa2 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):
"""