|
24 | 24 | """ |
25 | 25 | # many imports are lazy-loaded when they are needed |
26 | 26 | import argparse |
27 | | -import atexit |
28 | 27 | import cmd |
29 | | -import codecs |
30 | 28 | import collections |
31 | | -import copy |
32 | 29 | import datetime |
33 | 30 | import functools |
34 | 31 | import glob |
|
38 | 35 | import platform |
39 | 36 | import re |
40 | 37 | import shlex |
41 | | -import signal |
42 | 38 | import subprocess |
43 | 39 | import sys |
44 | | -import tempfile |
45 | 40 | import traceback |
46 | 41 | from typing import Callable, List, Optional, Union, Tuple |
47 | 42 |
|
@@ -524,6 +519,7 @@ def complete_submenu(_self, text, line, begidx, endidx): |
524 | 519 | self._copy_out_shared_attrs(_self, original_attributes) |
525 | 520 |
|
526 | 521 | # Pass the submenu's tab completion parameters back up to the menu that called complete() |
| 522 | + import copy |
527 | 523 | _self.allow_appended_space = submenu.allow_appended_space |
528 | 524 | _self.allow_closing_quote = submenu.allow_closing_quote |
529 | 525 | _self.display_matches = copy.copy(submenu.display_matches) |
@@ -661,6 +657,7 @@ def __init__(self, completekey='tab', stdin=None, stdout=None, persistent_histor |
661 | 657 | readline.set_history_length(persistent_history_length) |
662 | 658 | except FileNotFoundError: |
663 | 659 | pass |
| 660 | + import atexit |
664 | 661 | atexit.register(readline.write_history_file, persistent_history_file) |
665 | 662 |
|
666 | 663 | # Call super class constructor |
@@ -935,6 +932,7 @@ def tokens_for_completion(self, line, begidx, endidx): |
935 | 932 | On Failure |
936 | 933 | Both items are None |
937 | 934 | """ |
| 935 | + import copy |
938 | 936 | unclosed_quote = '' |
939 | 937 | quotes_to_try = copy.copy(constants.QUOTES) |
940 | 938 |
|
@@ -1677,6 +1675,7 @@ def complete(self, text, state): |
1677 | 1675 | # Since self.display_matches is empty, set it to self.completion_matches |
1678 | 1676 | # before we alter them. That way the suggestions will reflect how we parsed |
1679 | 1677 | # the token being completed and not how readline did. |
| 1678 | + import copy |
1680 | 1679 | self.display_matches = copy.copy(self.completion_matches) |
1681 | 1680 |
|
1682 | 1681 | # Check if we need to add an opening quote |
@@ -1848,7 +1847,7 @@ def sigint_handler(self, signum, frame): |
1848 | 1847 |
|
1849 | 1848 | def preloop(self): |
1850 | 1849 | """"Hook method executed once when the cmdloop() method is called.""" |
1851 | | - |
| 1850 | + import signal |
1852 | 1851 | # Register a default SIGINT signal handler for Ctrl+C |
1853 | 1852 | signal.signal(signal.SIGINT, self.sigint_handler) |
1854 | 1853 |
|
@@ -2083,6 +2082,7 @@ def _redirect_output(self, statement): |
2083 | 2082 | # Re-raise the exception |
2084 | 2083 | raise ex |
2085 | 2084 | elif statement.output: |
| 2085 | + import tempfile |
2086 | 2086 | if (not statement.output_to) and (not can_clip): |
2087 | 2087 | raise EnvironmentError('Cannot redirect to paste buffer; install ``xclip`` and re-run to enable') |
2088 | 2088 | self.kept_state = Statekeeper(self, ('stdout',)) |
@@ -2927,6 +2927,7 @@ def do_history(self, args): |
2927 | 2927 | if runme: |
2928 | 2928 | self.onecmd_plus_hooks(runme) |
2929 | 2929 | elif args.edit: |
| 2930 | + import tempfile |
2930 | 2931 | fd, fname = tempfile.mkstemp(suffix='.txt', text=True) |
2931 | 2932 | with os.fdopen(fd, 'w') as fobj: |
2932 | 2933 | for command in history: |
@@ -3138,6 +3139,8 @@ def is_text_file(file_path): |
3138 | 3139 | Returns if a file contains only ASCII or UTF-8 encoded text |
3139 | 3140 | :param file_path: path to the file being checked |
3140 | 3141 | """ |
| 3142 | + import codecs |
| 3143 | + |
3141 | 3144 | expanded_path = os.path.abspath(os.path.expanduser(file_path.strip())) |
3142 | 3145 | valid_text_file = False |
3143 | 3146 |
|
|
0 commit comments