mirror of
https://github.com/python/cpython.git
synced 2025-07-07 19:35:27 +00:00
(Merge 3.5) Issue #23840: tokenize.open() now closes the temporary binary file
on error to fix a resource warning.
This commit is contained in:
commit
24d262af0b
3 changed files with 21 additions and 6 deletions
|
@ -435,11 +435,15 @@ def open(filename):
|
|||
detect_encoding().
|
||||
"""
|
||||
buffer = _builtin_open(filename, 'rb')
|
||||
encoding, lines = detect_encoding(buffer.readline)
|
||||
buffer.seek(0)
|
||||
text = TextIOWrapper(buffer, encoding, line_buffering=True)
|
||||
text.mode = 'r'
|
||||
return text
|
||||
try:
|
||||
encoding, lines = detect_encoding(buffer.readline)
|
||||
buffer.seek(0)
|
||||
text = TextIOWrapper(buffer, encoding, line_buffering=True)
|
||||
text.mode = 'r'
|
||||
return text
|
||||
except:
|
||||
buffer.close()
|
||||
raise
|
||||
|
||||
|
||||
def tokenize(readline):
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue