From 84d6f076a30bdcd8633be7ae7d255fe69102e9f5 Mon Sep 17 00:00:00 2001 From: Cosimo Lupo Date: Tue, 2 Feb 2016 18:25:43 +0000 Subject: [PATCH] [ttLib] call XMLWriter.close() only if 'fileOrPath' is a path, not when it's a file This allows to call `TTFont.saveXML` with an already open file/stream (e.g. sys.stdout or a StringIO) without it being abruptly closed at the end. We do the same elsewhere when we reiceive file handles instead of path names, so we might do it here too. --- Lib/fontTools/ttLib/__init__.py | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/Lib/fontTools/ttLib/__init__.py b/Lib/fontTools/ttLib/__init__.py index 0ef913190..a64893074 100644 --- a/Lib/fontTools/ttLib/__init__.py +++ b/Lib/fontTools/ttLib/__init__.py @@ -308,7 +308,9 @@ class TTFont(object): progress.set((i + 1)) writer.endtag("ttFont") writer.newline() - writer.close() + # close if 'fileOrPath' is a path; leave it open if it's a file + if not hasattr(fileOrPath, "write"): + writer.close() def _tableToXML(self, writer, tag, progress, quiet=None): if quiet is not None: