=========================
+gh-85320: IDLE now reads and writes its configuration files and the
+breakpoints file using UTF-8 instead of the locale encoding.
+Files with non-ASCII characters and non-UTF-8 encoding may need
+to be opened in an editor and resaved with UTF-8 encoding.
+
gh-143774: Better explain the operation of Format / Format Paragraph.
Patch by Terry J. Reedy.
def Load(self):
"Load the configuration file from disk."
- if self.file:
- self.read(self.file)
+ if self.file and os.path.exists(self.file):
+ with open(self.file, encoding='utf-8', errors='replace') as f:
+ self.read_file(f)
class IdleUserConfParser(IdleConfParser):
"""
if fname and fname[0] != '#':
if not self.IsEmpty():
try:
- cfgFile = open(fname, 'w')
+ cfgFile = open(fname, 'w', encoding='utf-8')
except OSError:
os.unlink(fname)
- cfgFile = open(fname, 'w')
+ cfgFile = open(fname, 'w', encoding='utf-8')
with cfgFile:
self.write(cfgFile)
elif os.path.exists(self.file):
breaks = self.breakpoints
filename = self.io.filename
try:
- with open(self.breakpointPath) as fp:
+ with open(self.breakpointPath,
+ encoding='utf-8', errors='replace') as fp:
lines = fp.readlines()
except OSError:
lines = []
try:
- with open(self.breakpointPath, "w") as new_file:
+ with open(self.breakpointPath, "w", encoding='utf-8') as new_file:
for line in lines:
if not line.startswith(filename + '='):
new_file.write(line)
if filename is None:
return
if os.path.isfile(self.breakpointPath):
- with open(self.breakpointPath) as fp:
+ with open(self.breakpointPath,
+ encoding='utf-8', errors='replace') as fp:
lines = fp.readlines()
for line in lines:
if line.startswith(filename + '='):
--- /dev/null
+IDLE now reads and writes its configuration files and the breakpoints file
+using UTF-8 instead of the locale encoding. This keeps non-ASCII data (such
+as non-ASCII paths) from being corrupted and makes the files portable between
+environments.