summaryrefslogtreecommitdiffstats
path: root/Lib/idlelib/IOBinding.py
diff options
context:
space:
mode:
authorKurt B. Kaiser <kbk@shore.net>2002-12-14 04:38:51 (GMT)
committerKurt B. Kaiser <kbk@shore.net>2002-12-14 04:38:51 (GMT)
commitbfed346259b27a51153b1f1bf5e4f062247e6246 (patch)
treeed48082640fcfea43b806d83d6f8086249691d18 /Lib/idlelib/IOBinding.py
parent3c05c1f01e43e65705f5ff1ba8bce552c69321df (diff)
downloadcpython-bfed346259b27a51153b1f1bf5e4f062247e6246.zip
cpython-bfed346259b27a51153b1f1bf5e4f062247e6246.tar.gz
cpython-bfed346259b27a51153b1f1bf5e4f062247e6246.tar.bz2
M Debugger.py
M IOBinding.py M PyShell.py * Could not remove last set of saved breakpoints from a file * Starting with empty edit window, could not load a file * Multiple adjacent breakpoints were saved as one breakpoint * Storing breakpoints whenever a file is closed can get them out of synch with the saved version of a file. Only store them when the file is saved. * Add comment on current limitations on file editing in the presence of breakpoints. * Replace get_current_breaks() with update_breakpoints(), add an update to PyShellEditorWindow.breakpoints, which is the master breakpoint data structure, and which is used to reload the subprocess debugger. * Revert Debugger.Debugger.load_breakpoints() to use editwin.breakpoints. It is easier to debug the debugger if the breakpoint list in IDLE is identical to the list in the subprocess debugger and is transferred when the subprocess debugger is restarted, because this list can be easily queried. * Cleanup some linespacing and comments in IOBinding.py
Diffstat (limited to 'Lib/idlelib/IOBinding.py')
-rw-r--r--Lib/idlelib/IOBinding.py54
1 files changed, 11 insertions, 43 deletions
diff --git a/Lib/idlelib/IOBinding.py b/Lib/idlelib/IOBinding.py
index 594ecf6..a90157e 100644
--- a/Lib/idlelib/IOBinding.py
+++ b/Lib/idlelib/IOBinding.py
@@ -13,27 +13,8 @@ import tempfile
import tkFileDialog
import tkMessageBox
import re
-from configHandler import idleConf
-
-#$ event <<open-window-from-file>>
-#$ win <Control-o>
-#$ unix <Control-x><Control-f>
-
-#$ event <<save-window>>
-#$ win <Control-s>
-#$ unix <Control-x><Control-s>
-
-#$ event <<save-window-as-file>>
-#$ win <Alt-s>
-#$ unix <Control-x><Control-w>
-#$ event <<print-window>>
-#$ win <Control-p>
-#$ unix <Control-x><Control-p>
-
-#$ event <<save-copy-of-window-as-file>>
-#$ win <Alt-Shift-s>
-#$ unix <Control-x><w>
+from configHandler import idleConf
try:
from codecs import BOM_UTF8
@@ -85,11 +66,12 @@ else:
encoding = encoding.lower()
coding_re = re.compile("coding[:=]\s*([-\w_.]+)")
-def coding_spec(str):
+def coding_spec(str):
"""Return the encoding declaration according to PEP 263.
- Raise LookupError if the encoding is declared but unknown."""
+ Raise LookupError if the encoding is declared but unknown.
+ """
# Only consider the first two lines
str = str.split("\n")[:2]
str = "\n".join(str)
@@ -107,6 +89,7 @@ def coding_spec(str):
raise LookupError, "Unknown encoding "+name
return name
+
class IOBinding:
def __init__(self, editwin):
@@ -218,14 +201,14 @@ class IOBinding:
self.set_filename(filename)
self.text.mark_set("insert", "1.0")
self.text.see("insert")
-
self.updaterecentfileslist(filename)
return True
def decode(self, chars):
- # Try to create a Unicode string. If that fails, let Tcl try
- # its best
+ """Create a Unicode string
+ If that fails, let Tcl try its best
+ """
# Check presence of a UTF-8 signature first
if chars.startswith(BOM_UTF8):
try:
@@ -237,7 +220,6 @@ class IOBinding:
# Indicates that this file originally had a BOM
self.fileencoding = BOM_UTF8
return chars
-
# Next look for coding specification
try:
enc = coding_spec(chars)
@@ -248,19 +230,16 @@ class IOBinding:
"installation. The file may not display correctly" % name,
master = self.text)
enc = None
-
if enc:
try:
return unicode(chars, enc)
except UnicodeError:
pass
-
# If it is ASCII, we need not to record anything
try:
return unicode(chars, 'ascii')
except UnicodeError:
pass
-
# Finally, try the locale's encoding. This is deprecated;
# the user should declare a non-ASCII encoding
try:
@@ -295,8 +274,8 @@ class IOBinding:
else:
if self.writefile(self.filename):
self.set_saved(1)
+ self.editwin.store_file_breaks()
self.text.focus_set()
-
return "break"
def save_as(self, event):
@@ -305,8 +284,8 @@ class IOBinding:
if self.writefile(filename):
self.set_filename(filename)
self.set_saved(1)
+ self.editwin.store_file_breaks()
self.text.focus_set()
-
self.updaterecentfileslist(filename)
return "break"
@@ -315,7 +294,6 @@ class IOBinding:
if filename:
self.writefile(filename)
self.text.focus_set()
-
self.updaterecentfileslist(filename)
return "break"
@@ -326,7 +304,6 @@ class IOBinding:
f = open(filename, "w")
f.write(chars)
f.close()
- ## print "saved to", `filename`
return True
except IOError, msg:
tkMessageBox.showerror("I/O Error", str(msg),
@@ -338,14 +315,12 @@ class IOBinding:
# This is either plain ASCII, or Tk was returning mixed-encoding
# text to us. Don't try to guess further.
return chars
-
# See whether there is anything non-ASCII in it.
# If not, no need to figure out the encoding.
try:
return chars.encode('ascii')
except UnicodeError:
pass
-
# If there is an encoding declared, try this first.
try:
enc = coding_spec(chars)
@@ -358,17 +333,14 @@ class IOBinding:
return chars.encode(enc)
except UnicodeError:
failed = "Invalid encoding '%s'" % enc
-
if failed:
tkMessageBox.showerror(
"I/O Error",
"%s. Saving as UTF-8" % failed,
master = self.text)
-
# If there was a UTF-8 signature, use that. This should not fail
if self.fileencoding == BOM_UTF8 or failed:
return BOM_UTF8 + chars.encode("utf-8")
-
# Try the original file encoding next, if any
if self.fileencoding:
try:
@@ -380,7 +352,6 @@ class IOBinding:
% self.fileencoding,
master = self.text)
return BOM_UTF8 + chars.encode("utf-8")
-
# Nothing was declared, and we had not determined an encoding
# on loading. Recommend an encoding line.
try:
@@ -469,11 +440,8 @@ class IOBinding:
filetypes=self.filetypes)
return self.savedialog.show(initialdir=dir, initialfile=base)
-
def updaterecentfileslist(self,filename):
- #
- # Updates recent file list on all editor windows
- #
+ "Update recent file list on all editor windows"
self.editwin.UpdateRecentFilesList(filename)
def test():