Rietveld Code Review Tool
Help | Bug tracker | Discussion group | Source code | Sign in
(19)

Side by Side Diff: Lib/shlex.py

Issue 18853: Got ResourceWarning unclosed file when running Lib/shlex.py demo
Patch Set: Created 6 years, 6 months ago
Left:
Right:
Use n/p to move between diff chunks; N/P to move between comments. Please Sign in to add in-line comments.
Jump to:
View unified diff | Download patch
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 """A lexical analyzer class for simple shell-like syntaxes.""" 1 """A lexical analyzer class for simple shell-like syntaxes."""
2 2
3 # Module and documentation by Eric S. Raymond, 21 Dec 1998 3 # Module and documentation by Eric S. Raymond, 21 Dec 1998
4 # Input stacking and error message cleanup added by ESR, March 2000 4 # Input stacking and error message cleanup added by ESR, March 2000
5 # push_source() and pop_source() made explicit by ESR, January 2001. 5 # push_source() and pop_source() made explicit by ESR, January 2001.
6 # Posix compliance, split(), string arguments, and 6 # Posix compliance, split(), string arguments, and
7 # iterator interface by Gustavo Niemeyer, April 2003. 7 # iterator interface by Gustavo Niemeyer, April 2003.
8 8
9 import os 9 import os
10 import re 10 import re
(...skipping 274 matching lines...) Expand 10 before | Expand all | Expand 10 after
285 if _find_unsafe(s) is None: 285 if _find_unsafe(s) is None:
286 return s 286 return s
287 287
288 # use single quotes, and put single quotes into double quotes 288 # use single quotes, and put single quotes into double quotes
289 # the string $'b is then quoted as '$'"'"'b' 289 # the string $'b is then quoted as '$'"'"'b'
290 return "'" + s.replace("'", "'\"'\"'") + "'" 290 return "'" + s.replace("'", "'\"'\"'") + "'"
291 291
292 292
293 if __name__ == '__main__': 293 if __name__ == '__main__':
294 if len(sys.argv) == 1: 294 if len(sys.argv) == 1:
295 f = None
295 lexer = shlex() 296 lexer = shlex()
296 else: 297 else:
297 file = sys.argv[1] 298 file = sys.argv[1]
298 lexer = shlex(open(file), file) 299 f = open(file)
299 while 1: 300 lexer = shlex(f, file)
300 tt = lexer.get_token() 301 try:
301 if tt: 302 while 1:
302 print("Token: " + repr(tt)) 303 tt = lexer.get_token()
303 else: 304 if tt:
304 break 305 print("Token: " + repr(tt))
306 else:
307 break
308 finally:
309 if f:
310 f.close()
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

RSS Feeds Recent Issues | This issue
This is Rietveld 894c83f36cb7+