etree/plistlib/glifLib: using (default) single quotes in XML_DECLARATION

https://github.com/fonttools/fonttools/pull/1335#issuecomment-431118568
This commit is contained in:
Cosimo Lupo 2018-10-18 19:49:52 +01:00
parent 6db88d7cb7
commit 8081bf57fa
No known key found for this signature in database
GPG Key ID: 59D54DB0C9976482
4 changed files with 7 additions and 15 deletions

View File

@ -14,10 +14,8 @@ iterwalk.
from __future__ import absolute_import, unicode_literals from __future__ import absolute_import, unicode_literals
from fontTools.misc.py23 import basestring, unicode, tounicode, open from fontTools.misc.py23 import basestring, unicode, tounicode, open
# we use a custom XML declaration for backward compatibility with older
# ufoLib versions which would write it using double quotes. XML_DECLARATION = """<?xml version='1.0' encoding='%s'?>"""
# https://github.com/unified-font-object/ufoLib/issues/158
XML_DECLARATION = """<?xml version="1.0" encoding="%s"?>"""
__all__ = [ __all__ = [
# public symbols # public symbols

View File

@ -41,10 +41,7 @@ if PY3:
else: else:
USE_BUILTIN_TYPES = False USE_BUILTIN_TYPES = False
# we use a custom XML declaration for backward compatibility with older XML_DECLARATION = b"""<?xml version='1.0' encoding='UTF-8'?>"""
# ufoLib versions which would write it using double quotes.
# https://github.com/unified-font-object/ufoLib/issues/158
XML_DECLARATION = b"""<?xml version="1.0" encoding="UTF-8"?>"""
PLIST_DOCTYPE = ( PLIST_DOCTYPE = (
b'<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" ' b'<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" '

View File

@ -575,9 +575,6 @@ def readGlyphFromString(aString, glyphObject=None, pointPen=None, formatVersions
_readGlyphFromTree(tree, glyphObject, pointPen, formatVersions=formatVersions, validate=validate) _readGlyphFromTree(tree, glyphObject, pointPen, formatVersions=formatVersions, validate=validate)
_XML_DECLARATION = plistlib.XML_DECLARATION + b"\n"
def _writeGlyphToBytes( def _writeGlyphToBytes(
glyphName, glyphObject=None, drawPointsFunc=None, writer=None, glyphName, glyphObject=None, drawPointsFunc=None, writer=None,
formatVersion=2, validate=True): formatVersion=2, validate=True):
@ -621,8 +618,8 @@ def _writeGlyphToBytes(
if getattr(glyphObject, "lib", None): if getattr(glyphObject, "lib", None):
_writeLib(glyphObject, root, validate) _writeLib(glyphObject, root, validate)
# return the text # return the text
data = _XML_DECLARATION + etree.tostring( data = etree.tostring(
root, encoding="utf-8", xml_declaration=False, pretty_print=True root, encoding="UTF-8", xml_declaration=True, pretty_print=True
) )
return data return data

View File

@ -7,8 +7,8 @@ from io import open
from .testSupport import getDemoFontGlyphSetPath from .testSupport import getDemoFontGlyphSetPath
from fontTools.ufoLib.glifLib import ( from fontTools.ufoLib.glifLib import (
GlyphSet, glyphNameToFileName, readGlyphFromString, writeGlyphToString, GlyphSet, glyphNameToFileName, readGlyphFromString, writeGlyphToString,
_XML_DECLARATION,
) )
from fontTools.misc.etree import XML_DECLARATION
GLYPHSETDIR = getDemoFontGlyphSetPath() GLYPHSETDIR = getDemoFontGlyphSetPath()
@ -161,4 +161,4 @@ class ReadWriteFuncTest(unittest.TestCase):
def testXmlDeclaration(self): def testXmlDeclaration(self):
s = writeGlyphToString("a", _Glyph()) s = writeGlyphToString("a", _Glyph())
self.assertTrue(s.startswith(_XML_DECLARATION.decode("utf-8"))) self.assertTrue(s.startswith(XML_DECLARATION % "UTF-8"))