Files
python-uncompyle6/test/simple_source/bug30/04_and_del.py
2019-04-23 19:12:12 -04:00

21 lines
637 B
Python

# From 2.5.6 osxemxpath.py
# Bug is in getting "and" and "del" correct
def normpath(comps):
i = 0
while i < len(comps):
if comps[i] == '.':
del comps[i]
elif comps[i] == '..' and i > 0 and comps[i-1] not in ('', '..'):
del comps[i-1:i+1]
i = i - 1
elif comps[i] == '' and i > 0 and comps[i-1] != '':
del comps[i]
else:
i = i + 1
return comps
assert normpath(['.']) == []
assert normpath(['a', 'b', '..']) == ['a']
assert normpath(['a', 'b', '', 'c']) == ['a', 'b', 'c']
assert normpath(['a', 'b', '.', '', 'c', '..']) == ['a', 'b']