def get_longer(old, new):
"""Get the longer of two command sequences when one is a superset of
the other. Otherwise, return a list containing both.
"""
try:
pngs = ('\\begin', '\\end')
old_parts = {x for x in sep_RE.split(old) if x if x not in pngs}
new_parts = {y for y in sep_RE.split(new) if y if y not in pngs}
if new_parts == old_parts and new != old and any('\\begin' in c for c
in (old, new)):
return old if old.startswith('\\begin') else new
elif new_parts.issubset(old_parts):
return old
elif old_parts.issubset(new_parts):
return new
else:
return [old, new]
except TypeError:
# XXX Verify this test is necessary; smells like spam.
if not isinstance(old, abc.MutableSequence):
raise TypeError
# ``new`` must be returned from all combinations to get promoted.
leaders = set()
for sig in old:
res = get_longer(sig, new)
# Ensure 'foo' doesn't get split into ['f', 'o', 'o']
winners = (set(res) if isinstance(res, abc.MutableSequence)
else set((res,)))
sigs = (set(sig) if isinstance(sig, abc.MutableSequence) else
set((sig,)))
# ``new`` is always just a string.
losers = (sigs | set((new,))) - winners
leaders |= winners
leaders -= losers
return sorted(leaders)
return None
评论列表
文章目录