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
eacee986
Kaydet (Commit)
eacee986
authored
Şub 04, 2017
tarafından
Steve Dower
Dosyalara gözat
Seçenekler
Dosyalara Gözat
İndir
Eposta Yamaları
Sade Fark
Issue #29409: Implement PEP 529 for io.FileIO (Patch by Eryk Sun)
üst
bf0fc39e
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
35 additions
and
18 deletions
+35
-18
test_fileio.py
Lib/test/test_fileio.py
+19
-1
NEWS
Misc/NEWS
+2
-0
fileio.c
Modules/_io/fileio.c
+14
-17
No files found.
Lib/test/test_fileio.py
Dosyayı görüntüle @
eacee986
...
...
@@ -9,7 +9,8 @@ from array import array
from
weakref
import
proxy
from
functools
import
wraps
from
test.support
import
TESTFN
,
check_warnings
,
run_unittest
,
make_bad_fd
,
cpython_only
from
test.support
import
(
TESTFN
,
TESTFN_UNICODE
,
check_warnings
,
run_unittest
,
make_bad_fd
,
cpython_only
)
from
collections
import
UserList
import
_io
# C implementation of io
...
...
@@ -432,6 +433,23 @@ class OtherFileTests:
finally
:
os
.
unlink
(
TESTFN
)
@unittest.skipIf
(
sys
.
getfilesystemencoding
()
!=
'utf-8'
,
"test only works for utf-8 filesystems"
)
def
testUtf8BytesOpen
(
self
):
# Opening a UTF-8 bytes filename
try
:
fn
=
TESTFN_UNICODE
.
encode
(
"utf-8"
)
except
UnicodeEncodeError
:
self
.
skipTest
(
'could not encode
%
r to utf-8'
%
TESTFN_UNICODE
)
f
=
self
.
FileIO
(
fn
,
"w"
)
try
:
f
.
write
(
b
"abc"
)
f
.
close
()
with
open
(
TESTFN_UNICODE
,
"rb"
)
as
f
:
self
.
assertEqual
(
f
.
read
(),
b
"abc"
)
finally
:
os
.
unlink
(
TESTFN_UNICODE
)
def
testConstructorHandlesNULChars
(
self
):
fn_with_NUL
=
'foo
\0
bar'
self
.
assertRaises
(
ValueError
,
self
.
FileIO
,
fn_with_NUL
,
'w'
)
...
...
Misc/NEWS
Dosyayı görüntüle @
eacee986
...
...
@@ -146,6 +146,8 @@ Library
Windows
-------
- Issue #29409: Implement PEP 529 for io.FileIO (Patch by Eryk Sun)
- Issue #29392: Prevent crash when passing invalid arguments into msvcrt module.
- Issue #25778: winreg does not truncate string correctly (Patch by Eryk Sun)
...
...
Modules/_io/fileio.c
Dosyayı görüntüle @
eacee986
...
...
@@ -230,12 +230,13 @@ _io_FileIO___init___impl(fileio *self, PyObject *nameobj, const char *mode,
int
closefd
,
PyObject
*
opener
)
/*[clinic end generated code: output=23413f68e6484bbd input=193164e293d6c097]*/
{
const
char
*
name
=
NULL
;
PyObject
*
stringobj
=
NULL
;
const
char
*
s
;
#ifdef MS_WINDOWS
Py_UNICODE
*
widename
=
NULL
;
#else
const
char
*
name
=
NULL
;
#endif
PyObject
*
stringobj
=
NULL
;
const
char
*
s
;
int
ret
=
0
;
int
rwa
=
0
,
plus
=
0
;
int
flags
=
0
;
...
...
@@ -277,24 +278,21 @@ _io_FileIO___init___impl(fileio *self, PyObject *nameobj, const char *mode,
PyErr_Clear
();
}
if
(
fd
<
0
)
{
#ifdef MS_WINDOWS
if
(
PyUnicode_Check
(
nameobj
))
{
Py_ssize_t
length
;
widename
=
PyUnicode_AsUnicodeAndSize
(
nameobj
,
&
length
);
if
(
widename
==
NULL
)
return
-
1
;
if
(
wcslen
(
widename
)
!=
length
)
{
PyErr_SetString
(
PyExc_ValueError
,
"embedded null character"
);
if
(
!
PyUnicode_FSDecoder
(
nameobj
,
&
stringobj
))
{
return
-
1
;
}
}
else
#endif
if
(
fd
<
0
)
{
widename
=
PyUnicode_AsUnicodeAndSize
(
stringobj
,
&
length
);
if
(
widename
==
NULL
)
return
-
1
;
#else
if
(
!
PyUnicode_FSConverter
(
nameobj
,
&
stringobj
))
{
return
-
1
;
}
name
=
PyBytes_AS_STRING
(
stringobj
);
#endif
}
s
=
mode
;
...
...
@@ -386,11 +384,10 @@ _io_FileIO___init___impl(fileio *self, PyObject *nameobj, const char *mode,
do
{
Py_BEGIN_ALLOW_THREADS
#ifdef MS_WINDOWS
if
(
widename
!=
NULL
)
self
->
fd
=
_wopen
(
widename
,
flags
,
0666
);
else
self
->
fd
=
_wopen
(
widename
,
flags
,
0666
);
#else
self
->
fd
=
open
(
name
,
flags
,
0666
);
#endif
self
->
fd
=
open
(
name
,
flags
,
0666
);
Py_END_ALLOW_THREADS
}
while
(
self
->
fd
<
0
&&
errno
==
EINTR
&&
!
(
async_err
=
PyErr_CheckSignals
()));
...
...
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