plistlib: use double-quotes in xml declaration
for consistency with glifLib
This commit is contained in:
parent
61c19acace
commit
a8124a0eef
@ -548,10 +548,7 @@ def readGlyphFromString(aString, glyphObject=None, pointPen=None, formatVersions
|
|||||||
_readGlyphFromTree(tree, glyphObject, pointPen, formatVersions=formatVersions, validate=validate)
|
_readGlyphFromTree(tree, glyphObject, pointPen, formatVersions=formatVersions, validate=validate)
|
||||||
|
|
||||||
|
|
||||||
# we use a custom XML declaration for backward compatibility with older
|
_XML_DECLARATION = plistlib.XML_DECLARATION + b"\n"
|
||||||
# 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"?>\n"""
|
|
||||||
|
|
||||||
|
|
||||||
def _writeGlyphToBytes(
|
def _writeGlyphToBytes(
|
||||||
@ -597,7 +594,7 @@ 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 = _XML_DECLARATION + etree.tostring(
|
||||||
root, encoding="utf-8", xml_declaration=False, pretty_print=True
|
root, encoding="utf-8", xml_declaration=False, pretty_print=True
|
||||||
)
|
)
|
||||||
return data
|
return data
|
||||||
|
@ -13,6 +13,11 @@ from lxml import etree
|
|||||||
from fontTools.misc.py23 import unicode, basestring, tounicode
|
from fontTools.misc.py23 import unicode, basestring, tounicode
|
||||||
|
|
||||||
|
|
||||||
|
# we use a custom XML declaration for backward compatibility with older
|
||||||
|
# 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 = (
|
||||||
'<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" '
|
'<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" '
|
||||||
'"http://www.apple.com/DTDs/PropertyList-1.0.dtd">'
|
'"http://www.apple.com/DTDs/PropertyList-1.0.dtd">'
|
||||||
@ -328,11 +333,14 @@ def dump(value, fp, sort_keys=True, skipkeys=False, _pretty_print=True):
|
|||||||
root = etree.Element("plist", version="1.0")
|
root = etree.Element("plist", version="1.0")
|
||||||
root.append(totree(value, sort_keys=sort_keys, skipkeys=skipkeys))
|
root.append(totree(value, sort_keys=sort_keys, skipkeys=skipkeys))
|
||||||
tree = etree.ElementTree(root)
|
tree = etree.ElementTree(root)
|
||||||
|
fp.write(XML_DECLARATION)
|
||||||
|
if _pretty_print:
|
||||||
|
fp.write(b"\n")
|
||||||
tree.write(
|
tree.write(
|
||||||
fp,
|
fp,
|
||||||
encoding="utf-8",
|
encoding="utf-8",
|
||||||
pretty_print=_pretty_print,
|
pretty_print=_pretty_print,
|
||||||
xml_declaration=True,
|
xml_declaration=False,
|
||||||
doctype=PLIST_DOCTYPE,
|
doctype=PLIST_DOCTYPE,
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@ -6,7 +6,7 @@ from io import open
|
|||||||
from ufoLib.test.testSupport import getDemoFontGlyphSetPath
|
from ufoLib.test.testSupport import getDemoFontGlyphSetPath
|
||||||
from ufoLib.glifLib import (
|
from ufoLib.glifLib import (
|
||||||
GlyphSet, glyphNameToFileName, readGlyphFromString, writeGlyphToString,
|
GlyphSet, glyphNameToFileName, readGlyphFromString, writeGlyphToString,
|
||||||
XML_DECLARATION,
|
_XML_DECLARATION,
|
||||||
)
|
)
|
||||||
|
|
||||||
GLYPHSETDIR = getDemoFontGlyphSetPath()
|
GLYPHSETDIR = getDemoFontGlyphSetPath()
|
||||||
@ -160,7 +160,7 @@ 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.decode("utf-8")))
|
||||||
|
|
||||||
|
|
||||||
if __name__ == "__main__":
|
if __name__ == "__main__":
|
||||||
|
Loading…
x
Reference in New Issue
Block a user