def _fetchGlyphName(glyphPath):
# Given a path to an existing .glif file, get the glyph name
# from the XML data.
from xml.parsers.expat import ParserCreate
p = ParserCreate()
p.StartElementHandler = _startElementHandler
p.returns_unicode = True
f = open(glyphPath)
try:
p.ParseFile(f)
except _DoneParsing, why:
glyphName = why.args[0]
if glyphName is None:
raise ValueError, (".glif file doen't have a <glyph> top-level "
"element: %r" % glyphPath)
else:
assert 0, "it's not expected that parsing the file ends normally"
return glyphName
评论列表
文章目录