mirror of
https://github.com/rsms/inter.git
synced 2024-11-27 09:49:07 +03:00
8234b62ab7
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)
44 lines
1.1 KiB
Python
Executable File
44 lines
1.1 KiB
Python
Executable File
"""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)
|