def enter_completion(text, iteration): global repo global _attempt_end global _last_line global _last_res try: line = _helpers.get_line_buffer()[:_attempt_end] if _last_line != line: _last_res = _completer_get_subs(repo, line) _last_line = line qtype, lastword, subs = _last_res if iteration < len(subs): path = subs[iteration] leaf_name, leaf_item = path[-1] res = vfs.try_resolve(repo, leaf_name, parent=path[:-1]) leaf_name, leaf_item = res[-1] fullname = os.path.join(*(name for name, item in res)) if stat.S_ISDIR(vfs.item_mode(leaf_item)): ret = shquote.what_to_add(qtype, lastword, fullname + b'/', terminate=False) else: ret = shquote.what_to_add( qtype, lastword, fullname, terminate=True) + b' ' return text + ret except Exception as e: log('\n') try: import traceback traceback.print_tb(sys.exc_traceback) except Exception as e2: log('Error printing traceback: %s\n' % e2) log('\nError in completion: %s\n' % e)
def completer(text, iteration): global repo global _last_line global _last_res global rl_completion_suppress_append if rl_completion_suppress_append is not None: rl_completion_suppress_append.value = 1 try: line = readline.get_line_buffer()[:readline.get_endidx()] if _last_line != line: _last_res = _completer_get_subs(repo, line) _last_line = line (dir, name, qtype, lastword, subs) = _last_res if iteration < len(subs): path = subs[iteration] leaf_name, leaf_item = path[-1] res = vfs.try_resolve(repo, leaf_name, parent=path[:-1]) leaf_name, leaf_item = res[-1] fullname = os.path.join(*(name for name, item in res)) if stat.S_ISDIR(vfs.item_mode(leaf_item)): ret = shquote.what_to_add(qtype, lastword, fullname+'/', terminate=False) else: ret = shquote.what_to_add(qtype, lastword, fullname, terminate=True) + ' ' return text + ret except Exception as e: log('\n') try: import traceback traceback.print_tb(sys.exc_traceback) except Exception as e2: log('Error printing traceback: %s\n' % e2) log('\nError in completion: %s\n' % e)
def completer(text, state): global _last_line global _last_res global rl_completion_suppress_append if rl_completion_suppress_append is not None: rl_completion_suppress_append.value = 1 try: line = readline.get_line_buffer()[:readline.get_endidx()] if _last_line != line: _last_res = _completer_get_subs(line) _last_line = line (dir, name, qtype, lastword, subs) = _last_res if state < len(subs): sn = subs[state] sn1 = sn.try_resolve() # find the type of any symlink target fullname = os.path.join(dir, sn.name) if stat.S_ISDIR(sn1.mode): ret = shquote.what_to_add(qtype, lastword, fullname+'/', terminate=False) else: ret = shquote.what_to_add(qtype, lastword, fullname, terminate=True) + ' ' return text + ret except Exception, e: log('\n') try: import traceback traceback.print_tb(sys.exc_traceback) except Exception, e2: log('Error printing traceback: %s\n' % e2)
def completer(text, state): global _last_line global _last_res global rl_completion_suppress_append if rl_completion_suppress_append is not None: rl_completion_suppress_append.value = 1 try: line = readline.get_line_buffer()[:readline.get_endidx()] if _last_line != line: _last_res = _completer_get_subs(line) _last_line = line (dir, name, qtype, lastword, subs) = _last_res if state < len(subs): sn = subs[state] sn1 = sn.try_resolve() # find the type of any symlink target fullname = os.path.join(dir, sn.name) if stat.S_ISDIR(sn1.mode): ret = shquote.what_to_add(qtype, lastword, fullname + '/', terminate=False) else: ret = shquote.what_to_add( qtype, lastword, fullname, terminate=True) + ' ' return text + ret except Exception, e: log('\n') try: import traceback traceback.print_tb(sys.exc_traceback) except Exception, e2: log('Error printing traceback: %s\n' % e2)
def test_shquote(): WVPASSEQ(qst(""" this is basic \t\n\r text """), ['this', 'is', 'basic', 'text']) WVPASSEQ(qst(r""" \"x\" "help" 'yelp' """), ['"x"', 'help', 'yelp']) WVPASSEQ(qst(r""" "'\"\"'" '\"\'' """), ["'\"\"'", '\\"\'']) WVPASSEQ(shquote.quotesplit(' this is "unfinished'), [(2, 'this'), (7, 'is'), (10, 'unfinished')]) WVPASSEQ(shquote.quotesplit('"silly"\'will'), [(0, 'silly'), (7, 'will')]) WVPASSEQ(shquote.unfinished_word('this is a "billy" "goat'), ('"', 'goat')) WVPASSEQ(shquote.unfinished_word("'x"), ("'", 'x')) WVPASSEQ(shquote.unfinished_word("abra cadabra "), (None, '')) WVPASSEQ(shquote.unfinished_word("abra cadabra"), (None, 'cadabra')) (qtype, word) = shquote.unfinished_word("this is /usr/loc") WVPASSEQ(shquote.what_to_add(qtype, word, "/usr/local", True), "al") (qtype, word) = shquote.unfinished_word("this is '/usr/loc") WVPASSEQ(shquote.what_to_add(qtype, word, "/usr/local", True), "al'") (qtype, word) = shquote.unfinished_word("this is \"/usr/loc") WVPASSEQ(shquote.what_to_add(qtype, word, "/usr/local", True), "al\"") (qtype, word) = shquote.unfinished_word("this is \"/usr/loc") WVPASSEQ(shquote.what_to_add(qtype, word, "/usr/local", False), "al") (qtype, word) = shquote.unfinished_word("this is \\ hammer\\ \"") WVPASSEQ(word, ' hammer "') WVPASSEQ(shquote.what_to_add(qtype, word, " hammer \"time\"", True), "time\\\"") WVPASSEQ(shquote.quotify_list(['a', '', '"word"', "'third'", "'", "x y"]), "a '' '\"word\"' \"'third'\" \"'\" 'x y'")
def completer(text, state): global _last_line global _last_res global rl_completion_suppress_append if rl_completion_suppress_append is not None: rl_completion_suppress_append.value = 1 try: line = readline.get_line_buffer()[:readline.get_endidx()] if _last_line != line: _last_res = _completer_get_subs(line) _last_line = line (dir, name, qtype, lastword, subs) = _last_res if state < len(subs): sn = subs[state] sn1 = sn.resolve('') # deref symlinks fullname = os.path.join(dir, sn.name) if stat.S_ISDIR(sn1.mode): ret = shquote.what_to_add(qtype, lastword, fullname+'/', terminate=False) else: ret = shquote.what_to_add(qtype, lastword, fullname, terminate=True) + ' ' return text + ret except Exception, e: log('\nerror in completion: %s\n' % e)
def test_shquote(): with no_lingering_errors(): WVPASSEQ(qst(""" this is basic \t\n\r text """), ["this", "is", "basic", "text"]) WVPASSEQ(qst(r""" \"x\" "help" 'yelp' """), ['"x"', "help", "yelp"]) WVPASSEQ(qst(r""" "'\"\"'" '\"\'' """), ["'\"\"'", "\\\"'"]) WVPASSEQ(shquote.quotesplit(' this is "unfinished'), [(2, "this"), (7, "is"), (10, "unfinished")]) WVPASSEQ(shquote.quotesplit('"silly"\'will'), [(0, "silly"), (7, "will")]) WVPASSEQ(shquote.unfinished_word('this is a "billy" "goat'), ('"', "goat")) WVPASSEQ(shquote.unfinished_word("'x"), ("'", "x")) WVPASSEQ(shquote.unfinished_word("abra cadabra "), (None, "")) WVPASSEQ(shquote.unfinished_word("abra cadabra"), (None, "cadabra")) (qtype, word) = shquote.unfinished_word("this is /usr/loc") WVPASSEQ(shquote.what_to_add(qtype, word, "/usr/local", True), "al") (qtype, word) = shquote.unfinished_word("this is '/usr/loc") WVPASSEQ(shquote.what_to_add(qtype, word, "/usr/local", True), "al'") (qtype, word) = shquote.unfinished_word('this is "/usr/loc') WVPASSEQ(shquote.what_to_add(qtype, word, "/usr/local", True), 'al"') (qtype, word) = shquote.unfinished_word('this is "/usr/loc') WVPASSEQ(shquote.what_to_add(qtype, word, "/usr/local", False), "al") (qtype, word) = shquote.unfinished_word('this is \\ hammer\\ "') WVPASSEQ(word, ' hammer "') WVPASSEQ(shquote.what_to_add(qtype, word, ' hammer "time"', True), 'time\\"') WVPASSEQ( shquote.quotify_list(["a", "", '"word"', "'third'", "'", "x y"]), "a '' '\"word\"' \"'third'\" \"'\" 'x y'" )
def test_shquote(): with no_lingering_errors(): WVPASSEQ(qst(""" this is basic \t\n\r text """), ['this', 'is', 'basic', 'text']) WVPASSEQ(qst(r""" \"x\" "help" 'yelp' """), ['"x"', 'help', 'yelp']) WVPASSEQ(qst(r""" "'\"\"'" '\"\'' """), ["'\"\"'", '\\"\'']) WVPASSEQ(shquote.quotesplit(' this is "unfinished'), [(2,'this'), (7,'is'), (10,'unfinished')]) WVPASSEQ(shquote.quotesplit('"silly"\'will'), [(0,'silly'), (7,'will')]) WVPASSEQ(shquote.unfinished_word('this is a "billy" "goat'), ('"', 'goat')) WVPASSEQ(shquote.unfinished_word("'x"), ("'", 'x')) WVPASSEQ(shquote.unfinished_word("abra cadabra "), (None, '')) WVPASSEQ(shquote.unfinished_word("abra cadabra"), (None, 'cadabra')) (qtype, word) = shquote.unfinished_word("this is /usr/loc") WVPASSEQ(shquote.what_to_add(qtype, word, "/usr/local", True), "al") (qtype, word) = shquote.unfinished_word("this is '/usr/loc") WVPASSEQ(shquote.what_to_add(qtype, word, "/usr/local", True), "al'") (qtype, word) = shquote.unfinished_word("this is \"/usr/loc") WVPASSEQ(shquote.what_to_add(qtype, word, "/usr/local", True), "al\"") (qtype, word) = shquote.unfinished_word("this is \"/usr/loc") WVPASSEQ(shquote.what_to_add(qtype, word, "/usr/local", False), "al") (qtype, word) = shquote.unfinished_word("this is \\ hammer\\ \"") WVPASSEQ(word, ' hammer "') WVPASSEQ(shquote.what_to_add(qtype, word, " hammer \"time\"", True), "time\\\"") WVPASSEQ(shquote.quotify_list(['a', '', '"word"', "'third'", "'", "x y"]), "a '' '\"word\"' \"'third'\" \"'\" 'x y'")
def test_shquote(): WVPASSEQ(qst(b""" this is basic \t\n\r text """), [b'this', b'is', b'basic', b'text']) WVPASSEQ(qst(br""" \"x\" "help" 'yelp' """), [b'"x"', b'help', b'yelp']) WVPASSEQ(qst(br""" "'\"\"'" '\"\'' """), [b"'\"\"'", b'\\"\'']) WVPASSEQ(shquote.quotesplit(b' this is "unfinished'), [(2, b'this'), (7, b'is'), (10, b'unfinished')]) WVPASSEQ(shquote.quotesplit(b'"silly"\'will'), [(0, b'silly'), (7, b'will')]) WVPASSEQ(shquote.unfinished_word(b'this is a "billy" "goat'), (b'"', b'goat')) WVPASSEQ(shquote.unfinished_word(b"'x"), (b"'", b'x')) WVPASSEQ(shquote.unfinished_word(b"abra cadabra "), (None, b'')) WVPASSEQ(shquote.unfinished_word(b"abra cadabra"), (None, b'cadabra')) qtype, word = shquote.unfinished_word(b"this is /usr/loc") WVPASSEQ(shquote.what_to_add(qtype, word, b"/usr/local", True), b"al") qtype, word = shquote.unfinished_word(b"this is '/usr/loc") WVPASSEQ(shquote.what_to_add(qtype, word, b"/usr/local", True), b"al'") qtype, word = shquote.unfinished_word(b"this is \"/usr/loc") WVPASSEQ(shquote.what_to_add(qtype, word, b"/usr/local", True), b"al\"") qtype, word = shquote.unfinished_word(b"this is \"/usr/loc") WVPASSEQ(shquote.what_to_add(qtype, word, b"/usr/local", False), b"al") qtype, word = shquote.unfinished_word(b"this is \\ hammer\\ \"") WVPASSEQ(word, b' hammer "') WVPASSEQ(shquote.what_to_add(qtype, word, b" hammer \"time\"", True), b"time\\\"") WVPASSEQ(shquote.quotify_list([b'a', b'', b'"word"', b"'third'", b"'", b"x y"]), b"a '' '\"word\"' \"'third'\" \"'\" 'x y'")