Skip to content

Commit

Permalink
core.completer: Clean up excessive and unused code.
Browse files Browse the repository at this point in the history
- `mark_dirs` is only called from one location and it is more simply
  expressed as a one-liner using the ternary operator.
- `single_dir_expand` is not called from anywhere in IPython.
  • Loading branch information
bfroehle committed Dec 18, 2011
1 parent c8874d7 commit bf4a4f4
Showing 1 changed file with 4 additions and 36 deletions.
40 changes: 4 additions & 36 deletions IPython/core/completer.py
Expand Up @@ -130,19 +130,6 @@ def protect_filename(s):
return "".join([(ch in PROTECTABLES and '\\' + ch or ch)
for ch in s])


def mark_dirs(matches):
"""Mark directories in input list by appending '/' to their names."""
out = []
isdir = os.path.isdir
for x in matches:
if isdir(x):
out.append(x+'/')
else:
out.append(x)
return out


def expand_user(path):
"""Expand '~'-style usernames in strings.
Expand Down Expand Up @@ -191,28 +178,6 @@ def compress_user(path, tilde_expand, tilde_val):
else:
return path


def single_dir_expand(matches):
"Recursively expand match lists containing a single dir."

if len(matches) == 1 and os.path.isdir(matches[0]):
# Takes care of links to directories also. Use '/'
# explicitly, even under Windows, so that name completions
# don't end up escaped.
d = matches[0]
if d[-1] in ['/','\\']:
d = d[:-1]

subdirs = os.listdir(d)
if subdirs:
matches = [ (d + '/' + p) for p in subdirs]
return single_dir_expand(matches)
else:
return matches
else:
return matches


class Bunch(object): pass

DELIMS = ' \t\n`!@#$^&*()=+[{]}\\|;:\'",<>?'
Expand Down Expand Up @@ -604,7 +569,10 @@ def file_matches(self, text):
protect_filename(f) for f in m0]

#io.rprint('mm', matches) # dbg
return mark_dirs(matches)

# Mark directories in input list by appending '/' to their names.
matches = [x+'/' if os.path.isdir(x) else x for x in matches]
return matches

def magic_matches(self, text):
"""Match magics"""
Expand Down

0 comments on commit bf4a4f4

Please sign in to comment.