From 5af178ac8eb2da79b965be5c6cee693dad602c65 Mon Sep 17 00:00:00 2001 From: Khaled Hosny Date: Fri, 30 Jul 2021 04:27:02 +0200 Subject: [PATCH] Deprecate and ignore newlinestr --- Lib/fontTools/misc/xmlWriter.py | 11 +++++++---- Lib/fontTools/ttLib/tables/_g_l_y_f.py | 3 +-- Lib/fontTools/ttLib/ttFont.py | 3 +-- Tests/misc/xmlWriter_test.py | 2 +- Tests/ttLib/tables/_n_a_m_e_test.py | 2 +- 5 files changed, 11 insertions(+), 10 deletions(-) diff --git a/Lib/fontTools/misc/xmlWriter.py b/Lib/fontTools/misc/xmlWriter.py index ddc2fdb3e..c846f4141 100644 --- a/Lib/fontTools/misc/xmlWriter.py +++ b/Lib/fontTools/misc/xmlWriter.py @@ -4,6 +4,7 @@ from fontTools.misc.py23 import byteord, strjoin, tobytes, tostr import sys import os import string +import warnings INDENT = " " @@ -37,10 +38,12 @@ class XMLWriter(object): self.file.write('') self.totype = tostr self.indentwhite = self.totype(indentwhite) - if newlinestr is None: - self.newlinestr = self.totype(os.linesep) - else: - self.newlinestr = self.totype(newlinestr) + if newlinestr != "\n": + warnings.warn( + 'Setting "newlinestr" is deprecated and will be ignored.', + DeprecationWarning, + ) + self.newlinestr = self.totype("\n") self.indentlevel = 0 self.stack = [] self.needindent = 1 diff --git a/Lib/fontTools/ttLib/tables/_g_l_y_f.py b/Lib/fontTools/ttLib/tables/_g_l_y_f.py index e3bbddb9c..51ea85105 100644 --- a/Lib/fontTools/ttLib/tables/_g_l_y_f.py +++ b/Lib/fontTools/ttLib/tables/_g_l_y_f.py @@ -159,8 +159,7 @@ class table__g_l_y_f(DefaultTable.DefaultTable): suffix=ext) existingGlyphFiles.add(glyphPath.lower()) glyphWriter = xmlWriter.XMLWriter( - glyphPath, idlefunc=writer.idlefunc, - newlinestr=writer.newlinestr) + glyphPath, idlefunc=writer.idlefunc) glyphWriter.begintag("ttFont", ttLibVersion=version) glyphWriter.newline() glyphWriter.begintag("glyf") diff --git a/Lib/fontTools/ttLib/ttFont.py b/Lib/fontTools/ttLib/ttFont.py index 5ccd182cd..ba58e58d9 100644 --- a/Lib/fontTools/ttLib/ttFont.py +++ b/Lib/fontTools/ttLib/ttFont.py @@ -271,8 +271,7 @@ class TTFont(object): tag = tables[i] if splitTables: tablePath = fileNameTemplate % tagToIdentifier(tag) - tableWriter = xmlWriter.XMLWriter(tablePath, - newlinestr=writer.newlinestr) + tableWriter = xmlWriter.XMLWriter(tablePath) tableWriter.begintag("ttFont", ttLibVersion=version) tableWriter.newline() tableWriter.newline() diff --git a/Tests/misc/xmlWriter_test.py b/Tests/misc/xmlWriter_test.py index 7b9894c66..e1b92894a 100644 --- a/Tests/misc/xmlWriter_test.py +++ b/Tests/misc/xmlWriter_test.py @@ -115,7 +115,7 @@ class TestXMLWriter(unittest.TestCase): writer.write("world") writer.newline() - linesep = tobytes(os.linesep) if nls is None else tobytes(nls) + linesep = tobytes('\n') self.assertEqual( header + linesep + b"hello" + linesep + b"world" + linesep, diff --git a/Tests/ttLib/tables/_n_a_m_e_test.py b/Tests/ttLib/tables/_n_a_m_e_test.py index 8e8297049..196904077 100644 --- a/Tests/ttLib/tables/_n_a_m_e_test.py +++ b/Tests/ttLib/tables/_n_a_m_e_test.py @@ -354,7 +354,7 @@ class NameRecordTest(unittest.TestCase): writer = XMLWriter(BytesIO()) name.toXML(writer, ttFont=None) xml = writer.file.getvalue().decode("utf_8").strip() - return xml.split(writer.newlinestr.decode("utf_8"))[1:] + return xml.split("\n")[1:] def test_toXML_utf16be(self): name = makeName("Foo Bold", 111, 0, 2, 7)