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
0855e706
Kaydet (Commit)
0855e706
authored
Tem 01, 2016
tarafından
Serhiy Storchaka
Dosyalara gözat
Seçenekler
Dosyalara Gözat
İndir
Eposta Yamaları
Sade Fark
Issue #27007: The fromhex() class methods of bytes and bytearray subclasses
now return an instance of corresponding subclass.
üst
cf8b42e9
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
50 additions
and
10 deletions
+50
-10
test_bytes.py
Lib/test/test_bytes.py
+26
-1
NEWS
Misc/NEWS
+6
-0
bytearrayobject.c
Objects/bytearrayobject.c
+8
-4
bytesobject.c
Objects/bytesobject.c
+6
-1
bytearrayobject.c.h
Objects/clinic/bytearrayobject.c.h
+4
-4
No files found.
Lib/test/test_bytes.py
Dosyayı görüntüle @
0855e706
...
...
@@ -1589,7 +1589,32 @@ class SubclassTest:
self
.
assertEqual
(
type
(
a
),
type
(
b
))
self
.
assertEqual
(
type
(
a
.
y
),
type
(
b
.
y
))
test_fromhex
=
BaseBytesTest
.
test_fromhex
def
test_fromhex
(
self
):
b
=
self
.
type2test
.
fromhex
(
'1a2B30'
)
self
.
assertEqual
(
b
,
b
'
\x1a\x2b\x30
'
)
self
.
assertIs
(
type
(
b
),
self
.
type2test
)
class
B1
(
self
.
basetype
):
def
__new__
(
cls
,
value
):
me
=
self
.
basetype
.
__new__
(
cls
,
value
)
me
.
foo
=
'bar'
return
me
b
=
B1
.
fromhex
(
'1a2B30'
)
self
.
assertEqual
(
b
,
b
'
\x1a\x2b\x30
'
)
self
.
assertIs
(
type
(
b
),
B1
)
self
.
assertEqual
(
b
.
foo
,
'bar'
)
class
B2
(
self
.
basetype
):
def
__init__
(
me
,
*
args
,
**
kwargs
):
if
self
.
basetype
is
not
bytes
:
self
.
basetype
.
__init__
(
me
,
*
args
,
**
kwargs
)
me
.
foo
=
'bar'
b
=
B2
.
fromhex
(
'1a2B30'
)
self
.
assertEqual
(
b
,
b
'
\x1a\x2b\x30
'
)
self
.
assertIs
(
type
(
b
),
B2
)
self
.
assertEqual
(
b
.
foo
,
'bar'
)
class
ByteArraySubclass
(
bytearray
):
...
...
Misc/NEWS
Dosyayı görüntüle @
0855e706
...
...
@@ -7,6 +7,12 @@ What's New in Python 3.6.0 alpha 3
*Release date: XXXX-XX-XX*
Core and Builtins
-----------------
- Issue #27007: The fromhex() class methods of bytes and bytearray subclasses
now return an instance of corresponding subclass.
Library
-------
...
...
Objects/bytearrayobject.c
Dosyayı görüntüle @
0855e706
...
...
@@ -1968,7 +1968,6 @@ bytearray_splitlines_impl(PyByteArrayObject *self, int keepends)
@classmethod
bytearray.fromhex
cls: self(type="PyObject*")
string: unicode
/
...
...
@@ -1979,10 +1978,15 @@ Example: bytearray.fromhex('B9 01EF') -> bytearray(b'\\xb9\\x01\\xef')
[clinic start generated code]*/
static
PyObject
*
bytearray_fromhex_impl
(
Py
Object
*
cls
,
PyObject
*
string
)
/*[clinic end generated code: output=
df3da60129b3700c input=907bbd2d34d9367a
]*/
bytearray_fromhex_impl
(
Py
TypeObject
*
type
,
PyObject
*
string
)
/*[clinic end generated code: output=
8f0f0b6d30fb3ba0 input=f033a16d1fb21f48
]*/
{
return
_PyBytes_FromHex
(
string
,
1
);
PyObject
*
result
=
_PyBytes_FromHex
(
string
,
type
==
&
PyByteArray_Type
);
if
(
type
!=
&
PyByteArray_Type
&&
result
!=
NULL
)
{
Py_SETREF
(
result
,
PyObject_CallFunctionObjArgs
((
PyObject
*
)
type
,
result
,
NULL
));
}
return
result
;
}
PyDoc_STRVAR
(
hex__doc__
,
...
...
Objects/bytesobject.c
Dosyayı görüntüle @
0855e706
...
...
@@ -2303,7 +2303,12 @@ static PyObject *
bytes_fromhex_impl
(
PyTypeObject
*
type
,
PyObject
*
string
)
/*[clinic end generated code: output=0973acc63661bb2e input=bf4d1c361670acd3]*/
{
return
_PyBytes_FromHex
(
string
,
0
);
PyObject
*
result
=
_PyBytes_FromHex
(
string
,
0
);
if
(
type
!=
&
PyBytes_Type
&&
result
!=
NULL
)
{
Py_SETREF
(
result
,
PyObject_CallFunctionObjArgs
((
PyObject
*
)
type
,
result
,
NULL
));
}
return
result
;
}
PyObject
*
...
...
Objects/clinic/bytearrayobject.c.h
Dosyayı görüntüle @
0855e706
...
...
@@ -636,10 +636,10 @@ PyDoc_STRVAR(bytearray_fromhex__doc__,
{"fromhex", (PyCFunction)bytearray_fromhex, METH_O|METH_CLASS, bytearray_fromhex__doc__},
static
PyObject
*
bytearray_fromhex_impl
(
Py
Object
*
cls
,
PyObject
*
string
);
bytearray_fromhex_impl
(
Py
TypeObject
*
type
,
PyObject
*
string
);
static
PyObject
*
bytearray_fromhex
(
PyTypeObject
*
cls
,
PyObject
*
arg
)
bytearray_fromhex
(
PyTypeObject
*
type
,
PyObject
*
arg
)
{
PyObject
*
return_value
=
NULL
;
PyObject
*
string
;
...
...
@@ -647,7 +647,7 @@ bytearray_fromhex(PyTypeObject *cls, PyObject *arg)
if
(
!
PyArg_Parse
(
arg
,
"U:fromhex"
,
&
string
))
{
goto
exit
;
}
return_value
=
bytearray_fromhex_impl
(
(
PyObject
*
)
cls
,
string
);
return_value
=
bytearray_fromhex_impl
(
type
,
string
);
exit:
return
return_value
;
...
...
@@ -716,4 +716,4 @@ bytearray_sizeof(PyByteArrayObject *self, PyObject *Py_UNUSED(ignored))
{
return
bytearray_sizeof_impl
(
self
);
}
/*[clinic end generated code: output=
044a6c26a836bcfe
input=a9049054013a1b77]*/
/*[clinic end generated code: output=
a32f183ebef159cc
input=a9049054013a1b77]*/
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