From 560c7558c86813b1729d5ab1093251c3ca1c2cd1 Mon Sep 17 00:00:00 2001 From: Cosimo Lupo Date: Thu, 20 Dec 2018 14:28:17 +0000 Subject: [PATCH] SFNTReader: try deepcopy'ing first, if fails do manual copy of file contents --- Lib/fontTools/ttLib/sfnt.py | 21 ++++++++++++--------- 1 file changed, 12 insertions(+), 9 deletions(-) diff --git a/Lib/fontTools/ttLib/sfnt.py b/Lib/fontTools/ttLib/sfnt.py index e41030fbf..7999b7708 100644 --- a/Lib/fontTools/ttLib/sfnt.py +++ b/Lib/fontTools/ttLib/sfnt.py @@ -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