SFNTReader: try deepcopy'ing first, if fails do manual copy of file contents

This commit is contained in:
Cosimo Lupo 2018-12-20 14:28:17 +00:00
parent 4001ded199
commit 560c7558c8
No known key found for this signature in database
GPG Key ID: 59D54DB0C9976482

View File

@ -135,15 +135,18 @@ class SFNTReader(object):
obj = cls.__new__(cls)
for k, v in self.__dict__.items():
if k == "file":
f = self.file
start = f.tell()
f.seek(0)
buf = BytesIO(f.read())
f.seek(start)
buf.seek(start)
if hasattr(f, "name"):
buf.name = f.name
obj.file = buf
try:
obj.file = deepcopy(v, memo)
except TypeError:
f = self.file
pos = f.tell()
f.seek(0)
buf = BytesIO(f.read())
f.seek(pos)
buf.seek(pos)
if hasattr(f, "name"):
buf.name = f.name
obj.file = buf
else:
obj.__dict__[k] = deepcopy(v, memo)
return obj