changeset: 93123:4c2b77d0680b branch: 3.4 parent: 93120:e9cb45ccf42b user: R David Murray date: Fri Oct 17 20:28:47 2014 -0400 files: Lib/shlex.py Misc/NEWS description: #18853: Fix resource warning in shlex's __main__ section. Report and original fix by Vajrasky Kok. diff -r e9cb45ccf42b -r 4c2b77d0680b Lib/shlex.py --- a/Lib/shlex.py Fri Oct 17 19:55:11 2014 -0400 +++ b/Lib/shlex.py Fri Oct 17 20:28:47 2014 -0400 @@ -290,15 +290,17 @@ return "'" + s.replace("'", "'\"'\"'") + "'" +def _print_tokens(lexer): + while 1: + tt = lexer.get_token() + if not tt: + break + print("Token: " + repr(tt)) + if __name__ == '__main__': if len(sys.argv) == 1: - lexer = shlex() + _print_tokens(shlex()) else: - file = sys.argv[1] - lexer = shlex(open(file), file) - while 1: - tt = lexer.get_token() - if tt: - print("Token: " + repr(tt)) - else: - break + fn = sys.argv[1] + with open(fn) as f: + _print_tokens(shlex(f, fn)) diff -r e9cb45ccf42b -r 4c2b77d0680b Misc/NEWS --- a/Misc/NEWS Fri Oct 17 19:55:11 2014 -0400 +++ b/Misc/NEWS Fri Oct 17 20:28:47 2014 -0400 @@ -33,6 +33,8 @@ Library ------- +- Issue #18853: Fixed ResourceWarning in shlex.__nain__. + - Issue #9351: Defaults set with set_defaults on an argparse subparser are no longer ignored when also set on the parent parser.