def cd_completer(self, event):
ip = get_ipython()<EOL>relpath = event.symbol<EOL>if event.line.endswith('<STR_LIT>') or '<STR_LIT>' in event.line:<EOL><INDENT>bkms = self.db.get('<STR_LIT>', None)<EOL>if bkms:<EOL><INDENT>return bkms.keys()<EOL><DEDENT>else:<EOL><INDENT>return []<EOL><DEDENT><DEDENT>if event.symbol == '<STR_LIT:->':<EOL><INDENT>width_dh = str(len(str(len(ip.user_ns['<STR_LIT>']) + <NUM_LIT:1>)))<EOL>fmt = '<STR_LIT>' + width_dh +'<STR_LIT>'<EOL>ents = [ fmt % (i,s) for i,s in enumerate(ip.user_ns['<STR_LIT>'])]<EOL>if len(ents) > <NUM_LIT:1>:<EOL><INDENT>return ents<EOL><DEDENT>return []<EOL><DEDENT>if event.symbol.startswith('<STR_LIT>'):<EOL><INDENT>return ["<STR_LIT>" + os.path.basename(d) for d in ip.user_ns['<STR_LIT>']]<EOL><DEDENT>relpath, tilde_expand, tilde_val = expand_user(relpath)<EOL>relpath = relpath.replace('<STR_LIT:\\>','<STR_LIT:/>')<EOL>found = []<EOL>for d in [f.replace('<STR_LIT:\\>','<STR_LIT:/>') + '<STR_LIT:/>' for f in glob.glob(relpath+'<STR_LIT:*>')<EOL>if os.path.isdir(f)]:<EOL><INDENT>if '<STR_LIT:U+0020>' in d:<EOL><INDENT>raise TryNext<EOL><DEDENT>found.append(d)<EOL><DEDENT>if not found:<EOL><INDENT>if os.path.isdir(relpath):<EOL><INDENT>return [compress_user(relpath, tilde_expand, tilde_val)]<EOL><DEDENT>bks = self.db.get('<STR_LIT>',{}).iterkeys()<EOL>bkmatches = [s for s in bks if s.startswith(event.symbol)]<EOL>if bkmatches:<EOL><INDENT>return bkmatches<EOL><DEDENT>raise TryNext<EOL><DEDENT>return [compress_user(p, tilde_expand, tilde_val) for p in found]<EOL>
Completer function for cd, which only returns directories.