summaryrefslogtreecommitdiffstats
path: root/Lib/idlelib/ScriptBinding.py
diff options
context:
space:
mode:
authorVictor Stinner <victor.stinner@haypocalc.com>2011-09-01 22:57:04 (GMT)
committerVictor Stinner <victor.stinner@haypocalc.com>2011-09-01 22:57:04 (GMT)
commit85c6772aecd9cdcd87c9f4ede62dce041f581890 (patch)
tree241e1aa79315cac3ffb69ea5731e999a7ae3b999 /Lib/idlelib/ScriptBinding.py
parent0af0306396eb05c8c55951bc3dc04aa0a4c007ae (diff)
downloadcpython-85c6772aecd9cdcd87c9f4ede62dce041f581890.zip
cpython-85c6772aecd9cdcd87c9f4ede62dce041f581890.tar.gz
cpython-85c6772aecd9cdcd87c9f4ede62dce041f581890.tar.bz2
IDLE: fix some RessourceWarning, reuse tokenize.open()
Diffstat (limited to 'Lib/idlelib/ScriptBinding.py')
-rw-r--r--Lib/idlelib/ScriptBinding.py33
1 files changed, 14 insertions, 19 deletions
diff --git a/Lib/idlelib/ScriptBinding.py b/Lib/idlelib/ScriptBinding.py
index 90972b5..915e56e 100644
--- a/Lib/idlelib/ScriptBinding.py
+++ b/Lib/idlelib/ScriptBinding.py
@@ -67,25 +67,20 @@ class ScriptBinding:
def tabnanny(self, filename):
# XXX: tabnanny should work on binary files as well
- with open(filename, 'r', encoding='iso-8859-1') as f:
- two_lines = f.readline() + f.readline()
- encoding = IOBinding.coding_spec(two_lines)
- if not encoding:
- encoding = 'utf-8'
- f = open(filename, 'r', encoding=encoding)
- try:
- tabnanny.process_tokens(tokenize.generate_tokens(f.readline))
- except tokenize.TokenError as msg:
- msgtxt, (lineno, start) = msg
- self.editwin.gotoline(lineno)
- self.errorbox("Tabnanny Tokenizing Error",
- "Token Error: %s" % msgtxt)
- return False
- except tabnanny.NannyNag as nag:
- # The error messages from tabnanny are too confusing...
- self.editwin.gotoline(nag.get_lineno())
- self.errorbox("Tab/space error", indent_message)
- return False
+ with tokenize.open(filename) as f:
+ try:
+ tabnanny.process_tokens(tokenize.generate_tokens(f.readline))
+ except tokenize.TokenError as msg:
+ msgtxt, (lineno, start) = msg
+ self.editwin.gotoline(lineno)
+ self.errorbox("Tabnanny Tokenizing Error",
+ "Token Error: %s" % msgtxt)
+ return False
+ except tabnanny.NannyNag as nag:
+ # The error messages from tabnanny are too confusing...
+ self.editwin.gotoline(nag.get_lineno())
+ self.errorbox("Tab/space error", indent_message)
+ return False
return True
def checksyntax(self, filename):