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
a634e232
Kaydet (Commit)
a634e232
authored
Ock 06, 2017
tarafından
INADA Naoki
Dosyalara gözat
Seçenekler
Dosyalara Gözat
İndir
Eposta Yamaları
Sade Fark
Issue #29159: Fix regression in bytes(x) when x.__index__() raises Exception.
üst
a251fb02
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
40 additions
and
17 deletions
+40
-17
test_bytes.py
Lib/test/test_bytes.py
+13
-0
NEWS
Misc/NEWS
+2
-0
bytearrayobject.c
Objects/bytearrayobject.c
+13
-9
bytesobject.c
Objects/bytesobject.c
+12
-8
No files found.
Lib/test/test_bytes.py
Dosyayı görüntüle @
a634e232
...
...
@@ -4,6 +4,7 @@ XXX This is a mess. Common tests should be unified with string_tests.py (and
the latter should be modernized).
"""
import
array
import
os
import
re
import
sys
...
...
@@ -81,6 +82,18 @@ class BaseBytesTest:
self
.
assertRaises
(
ValueError
,
self
.
type2test
,
[
Indexable
(
-
1
)])
self
.
assertRaises
(
ValueError
,
self
.
type2test
,
[
Indexable
(
256
)])
def
test_from_buffer
(
self
):
a
=
self
.
type2test
(
array
.
array
(
'B'
,
[
1
,
2
,
3
]))
self
.
assertEqual
(
a
,
b
"
\x01\x02\x03
"
)
# http://bugs.python.org/issue29159
# Fallback when __index__ raises exception other than OverflowError
class
B
(
bytes
):
def
__index__
(
self
):
raise
TypeError
self
.
assertEqual
(
self
.
type2test
(
B
(
b
"foobar"
)),
b
"foobar"
)
def
test_from_ssize
(
self
):
self
.
assertEqual
(
self
.
type2test
(
0
),
b
''
)
self
.
assertEqual
(
self
.
type2test
(
1
),
b
'
\x00
'
)
...
...
Misc/NEWS
Dosyayı görüntüle @
a634e232
...
...
@@ -10,6 +10,8 @@ What's New in Python 3.6.1 release candidate 1?
Core and Builtins
-----------------
- Issue #29159: Fix regression in bytes(x) when x.__index__() raises Exception.
- Issue #28932: Do not include <sys/random.h> if it does not exist.
- Issue #25677: Correct the positioning of the syntax error caret for
...
...
Objects/bytearrayobject.c
Dosyayı görüntüle @
a634e232
...
...
@@ -798,18 +798,22 @@ bytearray_init(PyByteArrayObject *self, PyObject *args, PyObject *kwds)
if
(
PyIndex_Check
(
arg
))
{
count
=
PyNumber_AsSsize_t
(
arg
,
PyExc_OverflowError
);
if
(
count
==
-
1
&&
PyErr_Occurred
())
{
return
-
1
;
}
if
(
count
<
0
)
{
PyErr_SetString
(
PyExc_ValueError
,
"negative count"
);
return
-
1
;
if
(
PyErr_ExceptionMatches
(
PyExc_OverflowError
))
return
-
1
;
PyErr_Clear
();
/* fall through */
}
if
(
count
>
0
)
{
if
(
PyByteArray_Resize
((
PyObject
*
)
self
,
count
))
else
{
if
(
count
<
0
)
{
PyErr_SetString
(
PyExc_ValueError
,
"negative count"
);
return
-
1
;
memset
(
PyByteArray_AS_STRING
(
self
),
0
,
count
);
}
if
(
count
>
0
)
{
if
(
PyByteArray_Resize
((
PyObject
*
)
self
,
count
))
return
-
1
;
memset
(
PyByteArray_AS_STRING
(
self
),
0
,
count
);
}
return
0
;
}
return
0
;
}
/* Use the buffer API */
...
...
Objects/bytesobject.c
Dosyayı görüntüle @
a634e232
...
...
@@ -2593,16 +2593,20 @@ bytes_new(PyTypeObject *type, PyObject *args, PyObject *kwds)
if
(
PyIndex_Check
(
x
))
{
size
=
PyNumber_AsSsize_t
(
x
,
PyExc_OverflowError
);
if
(
size
==
-
1
&&
PyErr_Occurred
())
{
return
NULL
;
if
(
PyErr_ExceptionMatches
(
PyExc_OverflowError
))
return
NULL
;
PyErr_Clear
();
/* fall through */
}
if
(
size
<
0
)
{
PyErr_SetString
(
PyExc_ValueError
,
"negative count"
);
return
NULL
;
else
{
if
(
size
<
0
)
{
PyErr_SetString
(
PyExc_ValueError
,
"negative count"
);
return
NULL
;
}
new
=
_PyBytes_FromSize
(
size
,
1
);
if
(
new
==
NULL
)
return
NULL
;
return
new
;
}
new
=
_PyBytes_FromSize
(
size
,
1
);
if
(
new
==
NULL
)
return
NULL
;
return
new
;
}
return
PyBytes_FromObject
(
x
);
...
...
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