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) obj = cls.__new__(cls)
for k, v in self.__dict__.items(): for k, v in self.__dict__.items():
if k == "file": if k == "file":
f = self.file try:
start = f.tell() obj.file = deepcopy(v, memo)
f.seek(0) except TypeError:
buf = BytesIO(f.read()) f = self.file
f.seek(start) pos = f.tell()
buf.seek(start) f.seek(0)
if hasattr(f, "name"): buf = BytesIO(f.read())
buf.name = f.name f.seek(pos)
obj.file = buf buf.seek(pos)
if hasattr(f, "name"):
buf.name = f.name
obj.file = buf
else: else:
obj.__dict__[k] = deepcopy(v, memo) obj.__dict__[k] = deepcopy(v, memo)
return obj return obj