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
c6f9b2b7
Kaydet (Commit)
c6f9b2b7
authored
Eki 08, 2016
tarafından
Steve Dower
Dosyalara gözat
Seçenekler
Dosyalara Gözat
İndir
Eposta Yamaları
Sade Fark
Issue #28162: Fixes Ctrl+Z handling in console readall()
üst
ea200dba
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
51 additions
and
36 deletions
+51
-36
test_winconsoleio.py
Lib/test/test_winconsoleio.py
+22
-16
winconsoleio.c
Modules/_io/winconsoleio.c
+29
-20
No files found.
Lib/test/test_winconsoleio.py
Dosyayı görüntüle @
c6f9b2b7
...
...
@@ -107,16 +107,15 @@ class WindowsConsoleIOTests(unittest.TestCase):
source
=
'ϼўТλФЙ
\r\n
'
.
encode
(
'utf-16-le'
)
expected
=
'ϼўТλФЙ
\r\n
'
.
encode
(
'utf-8'
)
for
read_count
in
range
(
1
,
16
):
stdin
=
open
(
'CONIN$'
,
'rb'
,
buffering
=
0
)
write_input
(
stdin
,
source
)
with
open
(
'CONIN$'
,
'rb'
,
buffering
=
0
)
as
stdin
:
write_input
(
stdin
,
source
)
actual
=
b
''
while
not
actual
.
endswith
(
b
'
\n
'
):
b
=
stdin
.
read
(
read_count
)
actual
+=
b
actual
=
b
''
while
not
actual
.
endswith
(
b
'
\n
'
):
b
=
stdin
.
read
(
read_count
)
actual
+=
b
self
.
assertEqual
(
actual
,
expected
,
'stdin.read({})'
.
format
(
read_count
))
stdin
.
close
()
self
.
assertEqual
(
actual
,
expected
,
'stdin.read({})'
.
format
(
read_count
))
def
test_partial_surrogate_reads
(
self
):
# Test that reading less than 1 full character works when stdin
...
...
@@ -125,17 +124,24 @@ class WindowsConsoleIOTests(unittest.TestCase):
source
=
'
\U00101FFF\U00101001\r\n
'
.
encode
(
'utf-16-le'
)
expected
=
'
\U00101FFF\U00101001\r\n
'
.
encode
(
'utf-8'
)
for
read_count
in
range
(
1
,
16
):
stdin
=
open
(
'CONIN$'
,
'rb'
,
buffering
=
0
)
write_input
(
stdin
,
source
)
with
open
(
'CONIN$'
,
'rb'
,
buffering
=
0
)
as
stdin
:
write_input
(
stdin
,
source
)
actual
=
b
''
while
not
actual
.
endswith
(
b
'
\n
'
):
b
=
stdin
.
read
(
read_count
)
actual
+=
b
actual
=
b
''
while
not
actual
.
endswith
(
b
'
\n
'
):
b
=
stdin
.
read
(
read_count
)
actual
+=
b
self
.
assertEqual
(
actual
,
expected
,
'stdin.read({})'
.
format
(
read_count
))
stdin
.
close
()
self
.
assertEqual
(
actual
,
expected
,
'stdin.read({})'
.
format
(
read_count
))
def
test_ctrl_z
(
self
):
with
open
(
'CONIN$'
,
'rb'
,
buffering
=
0
)
as
stdin
:
source
=
'
\xC4\x1A\r\n
'
.
encode
(
'utf-16-le'
)
expected
=
'
\xC4
'
.
encode
(
'utf-8'
)
write_input
(
stdin
,
source
)
a
,
b
=
stdin
.
read
(
1
),
stdin
.
readall
()
self
.
assertEqual
(
expected
[
0
:
1
],
a
)
self
.
assertEqual
(
expected
[
1
:],
b
)
if
__name__
==
"__main__"
:
unittest
.
main
()
Modules/_io/winconsoleio.c
Dosyayı görüntüle @
c6f9b2b7
...
...
@@ -816,44 +816,53 @@ _io__WindowsConsoleIO_readall_impl(winconsoleio *self)
PyMem_Free
(
subbuf
);
/* when the read
starts with ^Z or
is empty we break */
if
(
n
==
0
||
buf
[
len
]
==
'\x1a'
)
/* when the read is empty we break */
if
(
n
==
0
)
break
;
len
+=
n
;
}
if
(
len
==
0
||
buf
[
0
]
==
'\x1a'
&&
_buflen
(
self
)
==
0
)
{
if
(
len
==
0
&&
_buflen
(
self
)
==
0
)
{
/* when the result starts with ^Z we return an empty buffer */
PyMem_Free
(
buf
);
return
PyBytes_FromStringAndSize
(
NULL
,
0
);
}
Py_BEGIN_ALLOW_THREADS
bytes_size
=
WideCharToMultiByte
(
CP_UTF8
,
0
,
buf
,
len
,
NULL
,
0
,
NULL
,
NULL
);
Py_END_ALLOW_THREADS
if
(
len
)
{
Py_BEGIN_ALLOW_THREADS
bytes_size
=
WideCharToMultiByte
(
CP_UTF8
,
0
,
buf
,
len
,
NULL
,
0
,
NULL
,
NULL
);
Py_END_ALLOW_THREADS
if
(
!
bytes_size
)
{
DWORD
err
=
GetLastError
();
PyMem_Free
(
buf
);
return
PyErr_SetFromWindowsErr
(
err
);
if
(
!
bytes_size
)
{
DWORD
err
=
GetLastError
();
PyMem_Free
(
buf
);
return
PyErr_SetFromWindowsErr
(
err
);
}
}
else
{
bytes_size
=
0
;
}
bytes_size
+=
_buflen
(
self
);
bytes
=
PyBytes_FromStringAndSize
(
NULL
,
bytes_size
);
rn
=
_copyfrombuf
(
self
,
PyBytes_AS_STRING
(
bytes
),
bytes_size
);
Py_BEGIN_ALLOW_THREADS
bytes_size
=
WideCharToMultiByte
(
CP_UTF8
,
0
,
buf
,
len
,
&
PyBytes_AS_STRING
(
bytes
)[
rn
],
bytes_size
-
rn
,
NULL
,
NULL
);
Py_END_ALLOW_THREADS
if
(
len
)
{
Py_BEGIN_ALLOW_THREADS
bytes_size
=
WideCharToMultiByte
(
CP_UTF8
,
0
,
buf
,
len
,
&
PyBytes_AS_STRING
(
bytes
)[
rn
],
bytes_size
-
rn
,
NULL
,
NULL
);
Py_END_ALLOW_THREADS
if
(
!
bytes_size
)
{
DWORD
err
=
GetLastError
();
PyMem_Free
(
buf
);
Py_CLEAR
(
bytes
);
return
PyErr_SetFromWindowsErr
(
err
);
if
(
!
bytes_size
)
{
DWORD
err
=
GetLastError
();
PyMem_Free
(
buf
);
Py_CLEAR
(
bytes
);
return
PyErr_SetFromWindowsErr
(
err
);
}
/* add back the number of preserved bytes */
bytes_size
+=
rn
;
}
PyMem_Free
(
buf
);
...
...
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