mirror of
https://github.com/python/cpython.git
synced 2025-07-21 18:25:22 +00:00
Whitespace Normalization
This commit is contained in:
parent
282f122250
commit
476740142d
1 changed files with 29 additions and 29 deletions
|
@ -416,35 +416,35 @@ class IOBinding:
|
||||||
return BOM_UTF8 + chars.encode("utf-8")
|
return BOM_UTF8 + chars.encode("utf-8")
|
||||||
# Nothing was declared, and we had not determined an encoding
|
# Nothing was declared, and we had not determined an encoding
|
||||||
# on loading. Recommend an encoding line.
|
# on loading. Recommend an encoding line.
|
||||||
config_encoding = idleConf.GetOption("main","EditorWindow",
|
config_encoding = idleConf.GetOption("main","EditorWindow",
|
||||||
"encoding")
|
"encoding")
|
||||||
if config_encoding == 'utf-8':
|
if config_encoding == 'utf-8':
|
||||||
# User has requested that we save files as UTF-8
|
# User has requested that we save files as UTF-8
|
||||||
return BOM_UTF8 + chars.encode("utf-8")
|
return BOM_UTF8 + chars.encode("utf-8")
|
||||||
ask_user = True
|
ask_user = True
|
||||||
try:
|
try:
|
||||||
chars = chars.encode(encoding)
|
chars = chars.encode(encoding)
|
||||||
enc = encoding
|
enc = encoding
|
||||||
if config_encoding == 'locale':
|
if config_encoding == 'locale':
|
||||||
ask_user = False
|
ask_user = False
|
||||||
except UnicodeError:
|
except UnicodeError:
|
||||||
chars = BOM_UTF8 + chars.encode("utf-8")
|
chars = BOM_UTF8 + chars.encode("utf-8")
|
||||||
enc = "utf-8"
|
enc = "utf-8"
|
||||||
if not ask_user:
|
if not ask_user:
|
||||||
return chars
|
return chars
|
||||||
dialog = EncodingMessage(self.editwin.top, enc)
|
dialog = EncodingMessage(self.editwin.top, enc)
|
||||||
dialog.go()
|
dialog.go()
|
||||||
if dialog.num == 1:
|
if dialog.num == 1:
|
||||||
# User asked us to edit the file
|
# User asked us to edit the file
|
||||||
encline = "# -*- coding: %s -*-\n" % enc
|
encline = "# -*- coding: %s -*-\n" % enc
|
||||||
firstline = self.text.get("1.0", "2.0")
|
firstline = self.text.get("1.0", "2.0")
|
||||||
if firstline.startswith("#!"):
|
if firstline.startswith("#!"):
|
||||||
# Insert encoding after #! line
|
# Insert encoding after #! line
|
||||||
self.text.insert("2.0", encline)
|
self.text.insert("2.0", encline)
|
||||||
else:
|
else:
|
||||||
self.text.insert("1.0", encline)
|
self.text.insert("1.0", encline)
|
||||||
return self.encode(self.text.get("1.0", "end-1c"))
|
return self.encode(self.text.get("1.0", "end-1c"))
|
||||||
return chars
|
return chars
|
||||||
|
|
||||||
def fixlastline(self):
|
def fixlastline(self):
|
||||||
c = self.text.get("end-2c")
|
c = self.text.get("end-2c")
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue