Replace special characters in string, for interactive shell quoting, as part of tab-completion.
(have_initial_double_quote, string)
| 76 | |
| 77 | |
| 78 | def escape_string(have_initial_double_quote, string): |
| 79 | """Replace special characters in string, for interactive shell quoting, as part of tab-completion.""" |
| 80 | if have_initial_double_quote: |
| 81 | tuple_ = ( |
| 82 | ('\\', '\\\\'), |
| 83 | ('"', r'\"'), |
| 84 | ('/', '//'), |
| 85 | ) |
| 86 | else: |
| 87 | tuple_ = ( |
| 88 | ('\\', '\\\\'), |
| 89 | ("'", r"\'"), |
| 90 | (' ', r'\ '), |
| 91 | ('"', r'\"'), |
| 92 | ('/', '//'), |
| 93 | ) |
| 94 | for from_str, to_str in tuple_: |
| 95 | string = string.replace(from_str, to_str) |
| 96 | return string |
| 97 | |
| 98 | |
| 99 | class CommandCompleter(Completer): |