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
1bebd8a2
Kaydet (Commit)
1bebd8a2
authored
May 04, 2017
tarafından
Serhiy Storchaka
Kaydeden (comit)
GitHub
May 04, 2017
Dosyalara gözat
Seçenekler
Dosyalara Gözat
İndir
Eposta Yamaları
Sade Fark
[3.6] bpo-30184: Add tests for invalid use of PyArg_ParseTupleAndKeywords. (GH-1316). (#1441)
(cherry picked from commit
5f161fd8
)
üst
af71364c
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
43 additions
and
20 deletions
+43
-20
test_capi.py
Lib/test/test_capi.py
+41
-18
_testcapimodule.c
Modules/_testcapimodule.c
+2
-2
No files found.
Lib/test/test_capi.py
Dosyayı görüntüle @
1bebd8a2
...
@@ -490,9 +490,8 @@ class SkipitemTest(unittest.TestCase):
...
@@ -490,9 +490,8 @@ class SkipitemTest(unittest.TestCase):
# test the format unit when not skipped
# test the format unit when not skipped
format
=
c
+
"i"
format
=
c
+
"i"
try
:
try
:
# (note: the format string must be bytes!)
_testcapi
.
parse_tuple_and_keywords
(
tuple_1
,
dict_b
,
_testcapi
.
parse_tuple_and_keywords
(
tuple_1
,
dict_b
,
format
.
encode
(
"ascii"
)
,
keywords
)
format
,
keywords
)
when_not_skipped
=
False
when_not_skipped
=
False
except
SystemError
as
e
:
except
SystemError
as
e
:
s
=
"argument 1 (impossible<bad format char>)"
s
=
"argument 1 (impossible<bad format char>)"
...
@@ -504,7 +503,7 @@ class SkipitemTest(unittest.TestCase):
...
@@ -504,7 +503,7 @@ class SkipitemTest(unittest.TestCase):
optional_format
=
"|"
+
format
optional_format
=
"|"
+
format
try
:
try
:
_testcapi
.
parse_tuple_and_keywords
(
empty_tuple
,
dict_b
,
_testcapi
.
parse_tuple_and_keywords
(
empty_tuple
,
dict_b
,
optional_format
.
encode
(
"ascii"
)
,
keywords
)
optional_format
,
keywords
)
when_skipped
=
False
when_skipped
=
False
except
SystemError
as
e
:
except
SystemError
as
e
:
s
=
"impossible<bad format char>: '{}'"
.
format
(
format
)
s
=
"impossible<bad format char>: '{}'"
.
format
(
format
)
...
@@ -517,40 +516,64 @@ class SkipitemTest(unittest.TestCase):
...
@@ -517,40 +516,64 @@ class SkipitemTest(unittest.TestCase):
self
.
assertIs
(
when_skipped
,
when_not_skipped
,
message
)
self
.
assertIs
(
when_skipped
,
when_not_skipped
,
message
)
def
test_parse_tuple_and_keywords
(
self
):
def
test_parse_tuple_and_keywords
(
self
):
#
parse_tuple_and_keywords error handling tests
#
Test handling errors in the parse_tuple_and_keywords helper itself
self
.
assertRaises
(
TypeError
,
_testcapi
.
parse_tuple_and_keywords
,
self
.
assertRaises
(
TypeError
,
_testcapi
.
parse_tuple_and_keywords
,
(),
{},
42
,
[])
(),
{},
42
,
[])
self
.
assertRaises
(
ValueError
,
_testcapi
.
parse_tuple_and_keywords
,
self
.
assertRaises
(
ValueError
,
_testcapi
.
parse_tuple_and_keywords
,
(),
{},
b
''
,
42
)
(),
{},
''
,
42
)
self
.
assertRaises
(
ValueError
,
_testcapi
.
parse_tuple_and_keywords
,
self
.
assertRaises
(
ValueError
,
_testcapi
.
parse_tuple_and_keywords
,
(),
{},
b
''
,
[
''
]
*
42
)
(),
{},
''
,
[
''
]
*
42
)
self
.
assertRaises
(
ValueError
,
_testcapi
.
parse_tuple_and_keywords
,
self
.
assertRaises
(
ValueError
,
_testcapi
.
parse_tuple_and_keywords
,
(),
{},
b
''
,
[
42
])
(),
{},
''
,
[
42
])
def
test_bad_use
(
self
):
# Test handling invalid format and keywords in
# PyArg_ParseTupleAndKeywords()
self
.
assertRaises
(
SystemError
,
_testcapi
.
parse_tuple_and_keywords
,
(
1
,),
{},
'||O'
,
[
'a'
])
self
.
assertRaises
(
SystemError
,
_testcapi
.
parse_tuple_and_keywords
,
(
1
,
2
),
{},
'|O|O'
,
[
'a'
,
'b'
])
self
.
assertRaises
(
SystemError
,
_testcapi
.
parse_tuple_and_keywords
,
(),
{
'a'
:
1
},
'$$O'
,
[
'a'
])
self
.
assertRaises
(
SystemError
,
_testcapi
.
parse_tuple_and_keywords
,
(),
{
'a'
:
1
,
'b'
:
2
},
'$O$O'
,
[
'a'
,
'b'
])
self
.
assertRaises
(
SystemError
,
_testcapi
.
parse_tuple_and_keywords
,
(),
{
'a'
:
1
},
'$|O'
,
[
'a'
])
self
.
assertRaises
(
SystemError
,
_testcapi
.
parse_tuple_and_keywords
,
(),
{
'a'
:
1
,
'b'
:
2
},
'$O|O'
,
[
'a'
,
'b'
])
self
.
assertRaises
(
SystemError
,
_testcapi
.
parse_tuple_and_keywords
,
(
1
,),
{},
'|O'
,
[
'a'
,
'b'
])
self
.
assertRaises
(
SystemError
,
_testcapi
.
parse_tuple_and_keywords
,
(
1
,),
{},
'|OO'
,
[
'a'
])
self
.
assertRaises
(
SystemError
,
_testcapi
.
parse_tuple_and_keywords
,
(),
{},
'|$O'
,
[
''
])
self
.
assertRaises
(
SystemError
,
_testcapi
.
parse_tuple_and_keywords
,
(),
{},
'|OO'
,
[
'a'
,
''
])
def
test_positional_only
(
self
):
def
test_positional_only
(
self
):
parse
=
_testcapi
.
parse_tuple_and_keywords
parse
=
_testcapi
.
parse_tuple_and_keywords
parse
((
1
,
2
,
3
),
{},
b
'OOO'
,
[
''
,
''
,
'a'
])
parse
((
1
,
2
,
3
),
{},
'OOO'
,
[
''
,
''
,
'a'
])
parse
((
1
,
2
),
{
'a'
:
3
},
b
'OOO'
,
[
''
,
''
,
'a'
])
parse
((
1
,
2
),
{
'a'
:
3
},
'OOO'
,
[
''
,
''
,
'a'
])
with
self
.
assertRaisesRegex
(
TypeError
,
with
self
.
assertRaisesRegex
(
TypeError
,
r'Function takes at least 2 positional arguments \(1 given\)'
):
r'Function takes at least 2 positional arguments \(1 given\)'
):
parse
((
1
,),
{
'a'
:
3
},
b
'OOO'
,
[
''
,
''
,
'a'
])
parse
((
1
,),
{
'a'
:
3
},
'OOO'
,
[
''
,
''
,
'a'
])
parse
((
1
,),
{},
b
'O|OO'
,
[
''
,
''
,
'a'
])
parse
((
1
,),
{},
'O|OO'
,
[
''
,
''
,
'a'
])
with
self
.
assertRaisesRegex
(
TypeError
,
with
self
.
assertRaisesRegex
(
TypeError
,
r'Function takes at least 1 positional arguments \(0 given\)'
):
r'Function takes at least 1 positional arguments \(0 given\)'
):
parse
((),
{},
b
'O|OO'
,
[
''
,
''
,
'a'
])
parse
((),
{},
'O|OO'
,
[
''
,
''
,
'a'
])
parse
((
1
,
2
),
{
'a'
:
3
},
b
'OO$O'
,
[
''
,
''
,
'a'
])
parse
((
1
,
2
),
{
'a'
:
3
},
'OO$O'
,
[
''
,
''
,
'a'
])
with
self
.
assertRaisesRegex
(
TypeError
,
with
self
.
assertRaisesRegex
(
TypeError
,
r'Function takes exactly 2 positional arguments \(1 given\)'
):
r'Function takes exactly 2 positional arguments \(1 given\)'
):
parse
((
1
,),
{
'a'
:
3
},
b
'OO$O'
,
[
''
,
''
,
'a'
])
parse
((
1
,),
{
'a'
:
3
},
'OO$O'
,
[
''
,
''
,
'a'
])
parse
((
1
,),
{},
b
'O|O$O'
,
[
''
,
''
,
'a'
])
parse
((
1
,),
{},
'O|O$O'
,
[
''
,
''
,
'a'
])
with
self
.
assertRaisesRegex
(
TypeError
,
with
self
.
assertRaisesRegex
(
TypeError
,
r'Function takes at least 1 positional arguments \(0 given\)'
):
r'Function takes at least 1 positional arguments \(0 given\)'
):
parse
((),
{},
b
'O|O$O'
,
[
''
,
''
,
'a'
])
parse
((),
{},
'O|O$O'
,
[
''
,
''
,
'a'
])
with
self
.
assertRaisesRegex
(
SystemError
,
r'Empty parameter name after \$'
):
with
self
.
assertRaisesRegex
(
SystemError
,
r'Empty parameter name after \$'
):
parse
((
1
,),
{},
b
'O|$OO'
,
[
''
,
''
,
'a'
])
parse
((
1
,),
{},
'O|$OO'
,
[
''
,
''
,
'a'
])
with
self
.
assertRaisesRegex
(
SystemError
,
'Empty keyword'
):
with
self
.
assertRaisesRegex
(
SystemError
,
'Empty keyword'
):
parse
((
1
,),
{},
b
'O|OO'
,
[
''
,
'a'
,
''
])
parse
((
1
,),
{},
'O|OO'
,
[
''
,
'a'
,
''
])
@unittest.skipUnless
(
threading
,
'Threading required for this test.'
)
@unittest.skipUnless
(
threading
,
'Threading required for this test.'
)
...
...
Modules/_testcapimodule.c
Dosyayı görüntüle @
1bebd8a2
...
@@ -1571,7 +1571,7 @@ parse_tuple_and_keywords(PyObject *self, PyObject *args)
...
@@ -1571,7 +1571,7 @@ parse_tuple_and_keywords(PyObject *self, PyObject *args)
{
{
PyObject
*
sub_args
;
PyObject
*
sub_args
;
PyObject
*
sub_kwargs
;
PyObject
*
sub_kwargs
;
char
*
sub_format
;
c
onst
c
har
*
sub_format
;
PyObject
*
sub_keywords
;
PyObject
*
sub_keywords
;
Py_ssize_t
i
,
size
;
Py_ssize_t
i
,
size
;
...
@@ -1584,7 +1584,7 @@ parse_tuple_and_keywords(PyObject *self, PyObject *args)
...
@@ -1584,7 +1584,7 @@ parse_tuple_and_keywords(PyObject *self, PyObject *args)
double
buffers
[
8
][
4
];
/* double ensures alignment where necessary */
double
buffers
[
8
][
4
];
/* double ensures alignment where necessary */
if
(
!
PyArg_ParseTuple
(
args
,
"OO
y
O:parse_tuple_and_keywords"
,
if
(
!
PyArg_ParseTuple
(
args
,
"OO
s
O:parse_tuple_and_keywords"
,
&
sub_args
,
&
sub_kwargs
,
&
sub_args
,
&
sub_kwargs
,
&
sub_format
,
&
sub_keywords
))
&
sub_format
,
&
sub_keywords
))
return
NULL
;
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