Skip to content
Projeler
Gruplar
Parçacıklar
Yardım
Yükleniyor...
Oturum aç / Kaydol
Gezinmeyi değiştir
C
cpython
Proje
Proje
Ayrıntılar
Etkinlik
Cycle Analytics
Depo (repository)
Depo (repository)
Dosyalar
Kayıtlar (commit)
Dallar (branch)
Etiketler
Katkıda bulunanlar
Grafik
Karşılaştır
Grafikler
Konular (issue)
0
Konular (issue)
0
Liste
Pano
Etiketler
Kilometre Taşları
Birleştirme (merge) Talepleri
0
Birleştirme (merge) Talepleri
0
CI / CD
CI / CD
İş akışları (pipeline)
İşler
Zamanlamalar
Grafikler
Paketler
Paketler
Wiki
Wiki
Parçacıklar
Parçacıklar
Üyeler
Üyeler
Collapse sidebar
Close sidebar
Etkinlik
Grafik
Grafikler
Yeni bir konu (issue) oluştur
İşler
Kayıtlar (commit)
Konu (issue) Panoları
Kenar çubuğunu aç
Batuhan Osman TASKAYA
cpython
Commits
1963ad31
Kaydet (Commit)
1963ad31
authored
Eyl 01, 2007
tarafından
Kurt B. Kaiser
Dosyalara gözat
Seçenekler
Dosyalara Gözat
İndir
Eposta Yamaları
Sade Fark
Saving a file containing unicode failed.
üst
bbb809ee
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
11 additions
and
14 deletions
+11
-14
IOBinding.py
Lib/idlelib/IOBinding.py
+11
-14
No files found.
Lib/idlelib/IOBinding.py
Dosyayı görüntüle @
1963ad31
...
@@ -11,11 +11,7 @@ from SimpleDialog import SimpleDialog
...
@@ -11,11 +11,7 @@ from SimpleDialog import SimpleDialog
from
idlelib.configHandler
import
idleConf
from
idlelib.configHandler
import
idleConf
try
:
from
codecs
import
BOM_UTF8
from
codecs
import
BOM_UTF8
except
ImportError
:
# only available since Python 2.3
BOM_UTF8
=
'
\xef\xbb\xbf
'
# Try setting the locale, so that we can find out
# Try setting the locale, so that we can find out
# what encoding to use
# what encoding to use
...
@@ -111,17 +107,18 @@ class EncodingMessage(SimpleDialog):
...
@@ -111,17 +107,18 @@ class EncodingMessage(SimpleDialog):
def
do_edit
(
self
):
def
do_edit
(
self
):
self
.
done
(
1
)
self
.
done
(
1
)
def
coding_spec
(
str
):
def
coding_spec
(
data
):
"""Return the encoding declaration according to PEP 263.
"""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.
"""
"""
# perform string manipulation in latin-1
if
isinstance
(
data
,
bytes
):
str
=
str
.
decode
(
"latin-1"
)
str
=
data
.
decode
(
'utf-8'
)
else
:
str
=
data
# Only consider the first two lines
# Only consider the first two lines
str
=
str
.
split
(
"
\n
"
)[:
2
]
str
=
str
.
split
(
"
\n
"
)[:
2
]
str
=
"
\n
"
.
join
(
str
)
str
=
"
\n
"
.
join
(
str
)
match
=
coding_re
.
search
(
str
)
match
=
coding_re
.
search
(
str
)
if
not
match
:
if
not
match
:
return
None
return
None
...
@@ -239,12 +236,12 @@ class IOBinding:
...
@@ -239,12 +236,12 @@ class IOBinding:
# open the file in binary mode so that we can handle
# open the file in binary mode so that we can handle
# end-of-line convention ourselves.
# end-of-line convention ourselves.
f
=
open
(
filename
,
'rb'
)
f
=
open
(
filename
,
'rb'
)
char
s
=
f
.
read
()
byte
s
=
f
.
read
()
f
.
close
()
f
.
close
()
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
(
char
s
)
chars
=
self
.
decode
(
byte
s
)
# We now convert all end-of-lines to '\n's
# We now convert all end-of-lines to '\n's
firsteol
=
self
.
eol_re
.
search
(
chars
)
firsteol
=
self
.
eol_re
.
search
(
chars
)
if
firsteol
:
if
firsteol
:
...
@@ -274,7 +271,7 @@ class IOBinding:
...
@@ -274,7 +271,7 @@ class IOBinding:
return
chars
return
chars
else
:
else
:
# Indicates that this file originally had a BOM
# Indicates that this file originally had a BOM
self
.
fileencoding
=
BOM_UTF8
self
.
fileencoding
=
'BOM'
return
chars
return
chars
# Next look for coding specification
# Next look for coding specification
try
:
try
:
...
@@ -401,10 +398,10 @@ class IOBinding:
...
@@ -401,10 +398,10 @@ class IOBinding:
if
failed
:
if
failed
:
tkMessageBox
.
showerror
(
tkMessageBox
.
showerror
(
"I/O Error"
,
"I/O Error"
,
"
%
s.
Saving as UTF-8"
%
failed
,
"
%
s.
\n
Saving as UTF-8"
%
failed
,
master
=
self
.
text
)
master
=
self
.
text
)
# If there was a UTF-8 signature, use that. This should not fail
# If there was a UTF-8 signature, use that. This should not fail
if
self
.
fileencoding
==
BOM_UTF8
or
failed
:
if
self
.
fileencoding
==
'BOM'
or
failed
:
return
BOM_UTF8
+
chars
.
encode
(
"utf-8"
)
return
BOM_UTF8
+
chars
.
encode
(
"utf-8"
)
# Try the original file encoding next, if any
# Try the original file encoding next, if any
if
self
.
fileencoding
:
if
self
.
fileencoding
:
...
...
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