Created
April 1, 2015 20:48
-
-
Save itsmemattchung/dd7344397766c0a05605 to your computer and use it in GitHub Desktop.
Patch for tokenize.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
diff --git a/Lib/tokenize.py b/Lib/tokenize.py | |
index 8bc83fd..96edf6c 100644 | |
--- a/Lib/tokenize.py | |
+++ b/Lib/tokenize.py | |
@@ -434,12 +434,16 @@ def open(filename): | |
"""Open a file in read only mode using the encoding detected by | |
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: | |
+ 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 | |
+ except Exception as err: | |
+ buffer.close() | |
+ raise | |
def tokenize(readline): |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment