def gen_outdict(symbols_it):
"""Without the change of ``ntup.mode`` from str to list, output
would be roughly equivalent to:
>>> dict((gname, {ntup.name: ntup._asdict() for ntup in grp})
for gname, grp in gr_symtups)
...
"""
#
# TODO change all ``mode`` and ``atom`` vals to lists
from collections.abc import MutableSequence
outdict = {}
for groupname, group in symbols_it:
newgroup = {}
for ntup in group:
# ntup = ntup._replace(mode=[ntup.mode])
if ntup.name not in newgroup:
newgroup.update({ntup.name: ntup._asdict()})
else:
existing = newgroup[ntup.name]
for field in 'font symbol'.split():
assert existing[field] == ntup._asdict()[field]
for field in 'atom mode'.split():
if isinstance(existing[field], MutableSequence):
# For now, this can't exist without implementing above.
assert False
if ntup._asdict()[field] not in existing[field]:
existing[field].append(ntup._asdict()[field])
existing[field].sort()
else:
if existing[field] != ntup._asdict()[field]:
existing.update({field: sorted(
[existing[field], ntup._asdict()[field]])})
outdict.update({groupname: newgroup})
return outdict
# Among the first few lines of the source file are js var initializations for
# creating `module.exports` objects. These take the form: `var foo = "foo";`.
# Snag these and store them as a dict alongside original comment heading.
评论列表
文章目录