Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
C
cpython
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
Kirill Smelkov
cpython
Commits
7e15845f
Commit
7e15845f
authored
Jan 18, 2009
by
Martin v. Löwis
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Issue #4815: Offer conversion to UTF-8 if source files have
no encoding declaration and are not encoded in UTF-8.
parent
975a0797
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
31 additions
and
12 deletions
+31
-12
Lib/idlelib/IOBinding.py
Lib/idlelib/IOBinding.py
+28
-12
Lib/idlelib/NEWS.txt
Lib/idlelib/NEWS.txt
+3
-0
No files found.
Lib/idlelib/IOBinding.py
View file @
7e15845f
...
@@ -7,7 +7,7 @@ import tkinter.filedialog as tkFileDialog
...
@@ -7,7 +7,7 @@ import tkinter.filedialog as tkFileDialog
import
tkinter.messagebox
as
tkMessageBox
import
tkinter.messagebox
as
tkMessageBox
import
re
import
re
from
tkinter
import
*
from
tkinter
import
*
from
tkinter.simpledialog
import
SimpleDialo
g
from
tkinter.simpledialog
import
askstrin
g
from
idlelib.configHandler
import
idleConf
from
idlelib.configHandler
import
idleConf
...
@@ -211,7 +211,7 @@ class IOBinding:
...
@@ -211,7 +211,7 @@ class IOBinding:
except
IOError
as
msg
:
except
IOError
as
msg
:
tkMessageBox
.
showerror
(
"I/O Error"
,
str
(
msg
),
master
=
self
.
text
)
tkMessageBox
.
showerror
(
"I/O Error"
,
str
(
msg
),
master
=
self
.
text
)
return
False
return
False
chars
=
self
.
_decode
(
two_lines
,
bytes
)
chars
,
converted
=
self
.
_decode
(
two_lines
,
bytes
)
if
chars
is
None
:
if
chars
is
None
:
tkMessageBox
.
showerror
(
"Decoding Error"
,
tkMessageBox
.
showerror
(
"Decoding Error"
,
"File %s
\
n
Failed to Decode"
%
filename
,
"File %s
\
n
Failed to Decode"
%
filename
,
...
@@ -227,6 +227,10 @@ class IOBinding:
...
@@ -227,6 +227,10 @@ class IOBinding:
self
.
text
.
insert
(
"1.0"
,
chars
)
self
.
text
.
insert
(
"1.0"
,
chars
)
self
.
reset_undo
()
self
.
reset_undo
()
self
.
set_filename
(
filename
)
self
.
set_filename
(
filename
)
if
converted
:
# We need to save the conversion results first
# before being able to execute the code
self
.
set_saved
(
False
)
self
.
text
.
mark_set
(
"insert"
,
"1.0"
)
self
.
text
.
mark_set
(
"insert"
,
"1.0"
)
self
.
text
.
see
(
"insert"
)
self
.
text
.
see
(
"insert"
)
self
.
updaterecentfileslist
(
filename
)
self
.
updaterecentfileslist
(
filename
)
...
@@ -241,11 +245,11 @@ class IOBinding:
...
@@ -241,11 +245,11 @@ class IOBinding:
chars
=
bytes
[
3
:].
decode
(
"utf-8"
)
chars
=
bytes
[
3
:].
decode
(
"utf-8"
)
except
UnicodeDecodeError
:
except
UnicodeDecodeError
:
# has UTF-8 signature, but fails to decode...
# has UTF-8 signature, but fails to decode...
return
None
return
None
,
False
else
:
else
:
# Indicates that this file originally had a BOM
# Indicates that this file originally had a BOM
self
.
fileencoding
=
'BOM'
self
.
fileencoding
=
'BOM'
return
chars
return
chars
,
False
# Next look for coding specification
# Next look for coding specification
try
:
try
:
enc
=
coding_spec
(
two_lines
)
enc
=
coding_spec
(
two_lines
)
...
@@ -257,36 +261,48 @@ class IOBinding:
...
@@ -257,36 +261,48 @@ class IOBinding:
master
=
self
.
text
)
master
=
self
.
text
)
enc
=
None
enc
=
None
except
UnicodeDecodeError
:
except
UnicodeDecodeError
:
return
None
return
None
,
False
if
enc
:
if
enc
:
try
:
try
:
chars
=
str
(
bytes
,
enc
)
chars
=
str
(
bytes
,
enc
)
self
.
fileencoding
=
enc
self
.
fileencoding
=
enc
return
chars
return
chars
,
False
except
UnicodeDecodeError
:
except
UnicodeDecodeError
:
pass
pass
# Try ascii:
# Try ascii:
try
:
try
:
chars
=
str
(
bytes
,
'ascii'
)
chars
=
str
(
bytes
,
'ascii'
)
self
.
fileencoding
=
None
self
.
fileencoding
=
None
return
chars
return
chars
,
False
except
UnicodeDecodeError
:
except
UnicodeDecodeError
:
pass
pass
# Try utf-8:
# Try utf-8:
try
:
try
:
chars
=
str
(
bytes
,
'utf-8'
)
chars
=
str
(
bytes
,
'utf-8'
)
self
.
fileencoding
=
'utf-8'
self
.
fileencoding
=
'utf-8'
return
chars
return
chars
,
False
except
UnicodeDecodeError
:
except
UnicodeDecodeError
:
pass
pass
# Finally, try the locale's encoding. This is deprecated;
# Finally, try the locale's encoding. This is deprecated;
# the user should declare a non-ASCII encoding
# the user should declare a non-ASCII encoding
try
:
try
:
chars
=
str
(
bytes
,
locale_encoding
)
# Wait for the editor window to appear
self
.
fileencoding
=
locale_encoding
self
.
editwin
.
text
.
update
()
except
UnicodeDecodeError
:
enc
=
askstring
(
"Specify file encoding"
,
"The file's encoding is invalid for Python 3.x.
\
n
"
"IDLE will convert it to UTF-8.
\
n
"
"What is the current encoding of the file?"
,
initialvalue
=
locale_encoding
,
parent
=
self
.
editwin
.
text
)
if
enc
:
chars
=
str
(
bytes
,
enc
)
self
.
fileencoding
=
None
return
chars
,
True
except
(
UnicodeDecodeError
,
LookupError
):
pass
pass
return
chars
# None on failure
return
None
,
False
# None on failure
def
maybesave
(
self
):
def
maybesave
(
self
):
if
self
.
get_saved
():
if
self
.
get_saved
():
...
...
Lib/idlelib/NEWS.txt
View file @
7e15845f
...
@@ -3,6 +3,9 @@ What's New in IDLE 3.1a1?
...
@@ -3,6 +3,9 @@ What's New in IDLE 3.1a1?
*Release date: XX-XXX-XXXX*
*Release date: XX-XXX-XXXX*
- Issue #4815: Offer conversion to UTF-8 if source files have
no encoding declaration and are not encoded in UTF-8.
- Issue #4008: Fix problems with non-ASCII source files.
- Issue #4008: Fix problems with non-ASCII source files.
- Issue #4323: Always encode source as UTF-8 without asking
- Issue #4323: Always encode source as UTF-8 without asking
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment