ttCollection: fix 'ResourceWarning: unclosed file'
Thanks Mike L.
This commit is contained in:
parent
ebe313d70e
commit
c08bfc1e1a
@ -26,8 +26,10 @@ class TTCollection(object):
|
|||||||
|
|
||||||
assert 'fontNumber' not in kwargs, kwargs
|
assert 'fontNumber' not in kwargs, kwargs
|
||||||
|
|
||||||
|
closeStream = False
|
||||||
if not hasattr(file, "read"):
|
if not hasattr(file, "read"):
|
||||||
file = open(file, "rb")
|
file = open(file, "rb")
|
||||||
|
closeStream = True
|
||||||
|
|
||||||
tableCache = {} if shareTables else None
|
tableCache = {} if shareTables else None
|
||||||
|
|
||||||
@ -36,6 +38,9 @@ class TTCollection(object):
|
|||||||
font = TTFont(file, fontNumber=i, _tableCache=tableCache, **kwargs)
|
font = TTFont(file, fontNumber=i, _tableCache=tableCache, **kwargs)
|
||||||
fonts.append(font)
|
fonts.append(font)
|
||||||
|
|
||||||
|
if closeStream:
|
||||||
|
file.close()
|
||||||
|
|
||||||
def __enter__(self):
|
def __enter__(self):
|
||||||
return self
|
return self
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user