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
7e2a54cd
Kaydet (Commit)
7e2a54cd
authored
Mar 14, 2017
tarafından
Xiang Zhang
Kaydeden (comit)
GitHub
Mar 14, 2017
Dosyalara gözat
Seçenekler
Dosyalara Gözat
İndir
Eposta Yamaları
Sade Fark
bpo-28856: Let %b format for bytes support objects that follow the buffer protocol (GH-546)
üst
9e52c907
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
23 additions
and
3 deletions
+23
-3
test_format.py
Lib/test/test_format.py
+6
-2
NEWS
Misc/NEWS
+3
-0
bytesobject.c
Objects/bytesobject.c
+14
-1
No files found.
Lib/test/test_format.py
Dosyayı görüntüle @
7e2a54cd
...
...
@@ -332,10 +332,12 @@ class FormatTest(unittest.TestCase):
testcommon
(
b
"
%
b"
,
b
"abc"
,
b
"abc"
)
testcommon
(
b
"
%
b"
,
bytearray
(
b
"def"
),
b
"def"
)
testcommon
(
b
"
%
b"
,
fb
,
b
"123"
)
testcommon
(
b
"
%
b"
,
memoryview
(
b
"abc"
),
b
"abc"
)
# # %s is an alias for %b -- should only be used for Py2/3 code
testcommon
(
b
"
%
s"
,
b
"abc"
,
b
"abc"
)
testcommon
(
b
"
%
s"
,
bytearray
(
b
"def"
),
b
"def"
)
testcommon
(
b
"
%
s"
,
fb
,
b
"123"
)
testcommon
(
b
"
%
s"
,
memoryview
(
b
"abc"
),
b
"abc"
)
# %a will give the equivalent of
# repr(some_obj).encode('ascii', 'backslashreplace')
testcommon
(
b
"
%
a"
,
3.14
,
b
"3.14"
)
...
...
@@ -372,9 +374,11 @@ class FormatTest(unittest.TestCase):
test_exc
(
b
"
%
c"
,
3.14
,
TypeError
,
"
%
c requires an integer in range(256) or a single byte"
)
test_exc
(
b
"
%
b"
,
"Xc"
,
TypeError
,
"
%
b requires bytes, or an object that implements __bytes__, not 'str'"
)
"
%
b requires a bytes-like object, "
"or an object that implements __bytes__, not 'str'"
)
test_exc
(
b
"
%
s"
,
"Wd"
,
TypeError
,
"
%
b requires bytes, or an object that implements __bytes__, not 'str'"
)
"
%
b requires a bytes-like object, "
"or an object that implements __bytes__, not 'str'"
)
if
maxsize
==
2
**
31
-
1
:
# crashes 2.2.1 and earlier:
...
...
Misc/NEWS
Dosyayı görüntüle @
7e2a54cd
...
...
@@ -10,6 +10,9 @@ What's New in Python 3.7.0 alpha 1?
Core and Builtins
-----------------
- bpo-28856: Fix an oversight that %b format for bytes should support objects
follow the buffer protocol.
- bpo-29723: The ``sys.path[0]`` initialization change for bpo-29139 caused a
regression by revealing an inconsistency in how sys.path is initialized when
executing ``__main__`` from a zipfile, directory, or other import location.
...
...
Objects/bytesobject.c
Dosyayı görüntüle @
7e2a54cd
...
...
@@ -528,6 +528,8 @@ byte_converter(PyObject *arg, char *p)
return
0
;
}
static
PyObject
*
_PyBytes_FromBuffer
(
PyObject
*
x
);
static
PyObject
*
format_obj
(
PyObject
*
v
,
const
char
**
pbuf
,
Py_ssize_t
*
plen
)
{
...
...
@@ -564,8 +566,19 @@ format_obj(PyObject *v, const char **pbuf, Py_ssize_t *plen)
*
plen
=
PyBytes_GET_SIZE
(
result
);
return
result
;
}
/* does it support buffer protocol? */
if
(
PyObject_CheckBuffer
(
v
))
{
/* maybe we can avoid making a copy of the buffer object here? */
result
=
_PyBytes_FromBuffer
(
v
);
if
(
result
==
NULL
)
return
NULL
;
*
pbuf
=
PyBytes_AS_STRING
(
result
);
*
plen
=
PyBytes_GET_SIZE
(
result
);
return
result
;
}
PyErr_Format
(
PyExc_TypeError
,
"%%b requires bytes, or an object that implements __bytes__, not '%.100s'"
,
"%%b requires a bytes-like object, "
"or an object that implements __bytes__, not '%.100s'"
,
Py_TYPE
(
v
)
->
tp_name
);
return
NULL
;
}
...
...
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