[sfnt] allways copy file data to BytesIO, not just if deepcopy failed
on py27, calling deepcopy on a file object doesn't raise TypeError, but leaves the duplicated file object in an inconsistent state: https://travis-ci.org/fonttools/fonttools/jobs/474811063#L714 any operations on it will fail with 'ValueError: I/O operation on uninitialized object'. Thus, for semplicity for now we always do a manual copy the file contents into an in-memory BytesIO stream, rather than attempting to call deepcopy first.
This commit is contained in:
parent
7d688ff18a
commit
ce86397f8f
@ -135,18 +135,14 @@ class SFNTReader(object):
|
||||
obj = cls.__new__(cls)
|
||||
for k, v in self.__dict__.items():
|
||||
if k == "file":
|
||||
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
|
||||
pos = v.tell()
|
||||
v.seek(0)
|
||||
buf = BytesIO(v.read())
|
||||
v.seek(pos)
|
||||
buf.seek(pos)
|
||||
if hasattr(v, "name"):
|
||||
buf.name = v.name
|
||||
obj.file = buf
|
||||
else:
|
||||
obj.__dict__[k] = deepcopy(v, memo)
|
||||
return obj
|
||||
|
Loading…
x
Reference in New Issue
Block a user