summaryrefslogtreecommitdiff
path: root/misc/pylib/robofab/plistFromTree.py
diff options
context:
space:
mode:
authorRasmus Andersson <rasmus@notion.se>2017-09-04 06:03:17 +0300
committerRasmus Andersson <rasmus@notion.se>2017-09-04 18:12:34 +0300
commit8234b62ab762637ef24c3398b4204a8ce8db31a7 (patch)
tree1c8df547021cdb58951630a015e4101ede46dbf1 /misc/pylib/robofab/plistFromTree.py
parent31ae014e0c827dd76696fdab7e4ca3fed9f6402b (diff)
downloadinter-8234b62ab762637ef24c3398b4204a8ce8db31a7.tar.xz
Speeds up font compilation by around 200%
Cython is used to compile some hot paths into native Python extensions. These hot paths were identified through running ufocompile with the hotshot profiler and then converting file by file to Cython, starting with the "hottest" paths and continuing until returns were deminishing. This means that only a few Python files were converted to Cython. Closes #23 Closes #20 (really this time)
Diffstat (limited to 'misc/pylib/robofab/plistFromTree.py')
-rwxr-xr-xmisc/pylib/robofab/plistFromTree.py43
1 files changed, 43 insertions, 0 deletions
diff --git a/misc/pylib/robofab/plistFromTree.py b/misc/pylib/robofab/plistFromTree.py
new file mode 100755
index 000000000..5bf608467
--- /dev/null
+++ b/misc/pylib/robofab/plistFromTree.py
@@ -0,0 +1,43 @@
+"""Small helper module to parse Plist-formatted data from trees as created
+by xmlTreeBuilder.
+"""
+
+
+__all__ = "readPlistFromTree"
+
+
+from plistlib import PlistParser
+
+
+def readPlistFromTree(tree):
+ """Given a (sub)tree created by xmlTreeBuilder, interpret it
+ as Plist-formatted data, and return the root object.
+ """
+ parser = PlistTreeParser()
+ return parser.parseTree(tree)
+
+
+class PlistTreeParser(PlistParser):
+
+ def parseTree(self, tree):
+ element, attributes, children = tree
+ self.parseElement(element, attributes, children)
+ return self.root
+
+ def parseElement(self, element, attributes, children):
+ self.handleBeginElement(element, attributes)
+ for child in children:
+ if isinstance(child, tuple):
+ self.parseElement(child[0], child[1], child[2])
+ else:
+ if not isinstance(child, unicode):
+ # ugh, xmlTreeBuilder returns utf-8 :-(
+ child = unicode(child, "utf-8")
+ self.handleData(child)
+ self.handleEndElement(element)
+
+
+if __name__ == "__main__":
+ from xmlTreeBuilder import buildTree
+ tree = buildTree("xxx.plist", stripData=0)
+ print readPlistFromTree(tree)