Packer.pack() reset buffer on exception (#274)

fixes #210
This commit is contained in:
INADA Naoki 2018-01-11 23:50:41 +09:00 committed by GitHub
parent 60ef3879d7
commit d9ec8fc905
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 12 additions and 6 deletions

View file

@ -848,7 +848,11 @@ class Packer(object):
raise TypeError("Cannot serialize %r" % (obj, ))
def pack(self, obj):
self._pack(obj)
try:
self._pack(obj)
except:
self._buffer = StringIO() # force reset
raise
ret = self._buffer.getvalue()
if self._autoreset:
self._buffer = StringIO()