diff options
author | R David Murray <rdmurray@bitdance.com> | 2014-10-18 00:30:16 (GMT) |
---|---|---|
committer | R David Murray <rdmurray@bitdance.com> | 2014-10-18 00:30:16 (GMT) |
commit | d20ec1b92196a01acf9bfb990329d06b4dee5c78 (patch) | |
tree | c89fc9f16b6760a0d5f93bba3c983545305f424b /Lib | |
parent | afce02ed38bd846c75593319e1df62de9bf3c627 (diff) | |
parent | 838f2c437db5796d316f106b1496d8d29268c5ca (diff) | |
download | cpython-d20ec1b92196a01acf9bfb990329d06b4dee5c78.zip cpython-d20ec1b92196a01acf9bfb990329d06b4dee5c78.tar.gz cpython-d20ec1b92196a01acf9bfb990329d06b4dee5c78.tar.bz2 |
Merge: #18853: Fix resource warning in shlex's __main__ section.
Diffstat (limited to 'Lib')
-rw-r--r-- | Lib/shlex.py | 20 |
1 files changed, 11 insertions, 9 deletions
diff --git a/Lib/shlex.py b/Lib/shlex.py index 69f3b45..4672553 100644 --- a/Lib/shlex.py +++ b/Lib/shlex.py @@ -290,15 +290,17 @@ def quote(s): return "'" + s.replace("'", "'\"'\"'") + "'" -if __name__ == '__main__': - if len(sys.argv) == 1: - lexer = shlex() - else: - file = sys.argv[1] - lexer = shlex(open(file), file) +def _print_tokens(lexer): while 1: tt = lexer.get_token() - if tt: - print("Token: " + repr(tt)) - else: + if not tt: break + print("Token: " + repr(tt)) + +if __name__ == '__main__': + if len(sys.argv) == 1: + _print_tokens(shlex()) + else: + fn = sys.argv[1] + with open(fn) as f: + _print_tokens(shlex(f, fn)) |