summaryrefslogtreecommitdiffstats
path: root/Lib/shlex.py
diff options
context:
space:
mode:
authorR David Murray <rdmurray@bitdance.com>2014-10-18 00:28:47 (GMT)
committerR David Murray <rdmurray@bitdance.com>2014-10-18 00:28:47 (GMT)
commit838f2c437db5796d316f106b1496d8d29268c5ca (patch)
tree47e87dd48e105e47be86796f3cac0ddf1b8100d1 /Lib/shlex.py
parent7570cbdc6b394cd89990a9252284c7e4a87bd6f1 (diff)
downloadcpython-838f2c437db5796d316f106b1496d8d29268c5ca.zip
cpython-838f2c437db5796d316f106b1496d8d29268c5ca.tar.gz
cpython-838f2c437db5796d316f106b1496d8d29268c5ca.tar.bz2
#18853: Fix resource warning in shlex's __main__ section.
Report and original fix by Vajrasky Kok.
Diffstat (limited to 'Lib/shlex.py')
-rw-r--r--Lib/shlex.py20
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))