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
c4c2580d
Kaydet (Commit)
c4c2580d
authored
Kas 15, 2013
tarafından
Nick Coghlan
Dosyalara gözat
Seçenekler
Dosyalara Gözat
İndir
Eposta Yamaları
Sade Fark
Close 19609: narrow scope of codec exc chaining
üst
91d2c567
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
32 additions
and
15 deletions
+32
-15
test_codecs.py
Lib/test/test_codecs.py
+26
-11
codecs.c
Python/codecs.c
+6
-4
No files found.
Lib/test/test_codecs.py
Dosyayı görüntüle @
c4c2580d
...
...
@@ -2435,22 +2435,22 @@ class ExceptionChainingTest(unittest.TestCase):
self
.
check_wrapped
(
RuntimeError
(
msg
),
msg
)
@contextlib.contextmanager
def
assertNotWrapped
(
self
,
operation
,
exc_type
,
msg
):
def
assertNotWrapped
(
self
,
operation
,
exc_type
,
msg_re
,
msg
=
None
):
if
msg
is
None
:
msg
=
msg_re
with
self
.
assertRaisesRegex
(
exc_type
,
msg
)
as
caught
:
yield
caught
actual_msg
=
str
(
caught
.
exception
)
self
.
assertNotIn
(
operation
,
actual_msg
)
self
.
assertNotIn
(
self
.
codec_name
,
actual_msg
)
self
.
assertEqual
(
str
(
caught
.
exception
),
msg
)
def
check_not_wrapped
(
self
,
obj_to_raise
,
msg
):
def
check_not_wrapped
(
self
,
obj_to_raise
,
msg
_re
,
msg
=
None
):
self
.
set_codec
(
obj_to_raise
)
with
self
.
assertNotWrapped
(
"encoding"
,
RuntimeError
,
msg
):
with
self
.
assertNotWrapped
(
"encoding"
,
RuntimeError
,
msg
_re
,
msg
):
"str input"
.
encode
(
self
.
codec_name
)
with
self
.
assertNotWrapped
(
"encoding"
,
RuntimeError
,
msg
):
with
self
.
assertNotWrapped
(
"encoding"
,
RuntimeError
,
msg
_re
,
msg
):
codecs
.
encode
(
"str input"
,
self
.
codec_name
)
with
self
.
assertNotWrapped
(
"decoding"
,
RuntimeError
,
msg
):
with
self
.
assertNotWrapped
(
"decoding"
,
RuntimeError
,
msg
_re
,
msg
):
b
"bytes input"
.
decode
(
self
.
codec_name
)
with
self
.
assertNotWrapped
(
"decoding"
,
RuntimeError
,
msg
):
with
self
.
assertNotWrapped
(
"decoding"
,
RuntimeError
,
msg
_re
,
msg
):
codecs
.
decode
(
b
"bytes input"
,
self
.
codec_name
)
def
test_init_override_is_not_wrapped
(
self
):
...
...
@@ -2475,8 +2475,23 @@ class ExceptionChainingTest(unittest.TestCase):
self
.
check_not_wrapped
(
RuntimeError
(
1
),
"1"
)
def
test_multiple_args_is_not_wrapped
(
self
):
msg
=
"
\
('a', 'b', 'c'
\
)"
self
.
check_not_wrapped
(
RuntimeError
(
'a'
,
'b'
,
'c'
),
msg
)
msg_re
=
"
\
('a', 'b', 'c'
\
)"
msg
=
"('a', 'b', 'c')"
self
.
check_not_wrapped
(
RuntimeError
(
'a'
,
'b'
,
'c'
),
msg_re
,
msg
)
# http://bugs.python.org/issue19609
def
test_codec_lookup_failure_not_wrapped
(
self
):
msg
=
"unknown encoding:
%
s"
%
self
.
codec_name
# The initial codec lookup should not be wrapped
with
self
.
assertNotWrapped
(
"encoding"
,
LookupError
,
msg
):
"str input"
.
encode
(
self
.
codec_name
)
with
self
.
assertNotWrapped
(
"encoding"
,
LookupError
,
msg
):
codecs
.
encode
(
"str input"
,
self
.
codec_name
)
with
self
.
assertNotWrapped
(
"decoding"
,
LookupError
,
msg
):
b
"bytes input"
.
decode
(
self
.
codec_name
)
with
self
.
assertNotWrapped
(
"decoding"
,
LookupError
,
msg
):
codecs
.
decode
(
b
"bytes input"
,
self
.
codec_name
)
@unittest.skipUnless
(
sys
.
platform
==
'win32'
,
...
...
Python/codecs.c
Dosyayı görüntüle @
c4c2580d
...
...
@@ -370,8 +370,10 @@ PyObject *PyCodec_Encode(PyObject *object,
goto
onError
;
result
=
PyEval_CallObject
(
encoder
,
args
);
if
(
result
==
NULL
)
if
(
result
==
NULL
)
{
wrap_codec_error
(
"encoding"
,
encoding
);
goto
onError
;
}
if
(
!
PyTuple_Check
(
result
)
||
PyTuple_GET_SIZE
(
result
)
!=
2
)
{
...
...
@@ -392,7 +394,6 @@ PyObject *PyCodec_Encode(PyObject *object,
Py_XDECREF
(
result
);
Py_XDECREF
(
args
);
Py_XDECREF
(
encoder
);
wrap_codec_error
(
"encoding"
,
encoding
);
return
NULL
;
}
...
...
@@ -418,8 +419,10 @@ PyObject *PyCodec_Decode(PyObject *object,
goto
onError
;
result
=
PyEval_CallObject
(
decoder
,
args
);
if
(
result
==
NULL
)
if
(
result
==
NULL
)
{
wrap_codec_error
(
"decoding"
,
encoding
);
goto
onError
;
}
if
(
!
PyTuple_Check
(
result
)
||
PyTuple_GET_SIZE
(
result
)
!=
2
)
{
PyErr_SetString
(
PyExc_TypeError
,
...
...
@@ -439,7 +442,6 @@ PyObject *PyCodec_Decode(PyObject *object,
Py_XDECREF
(
args
);
Py_XDECREF
(
decoder
);
Py_XDECREF
(
result
);
wrap_codec_error
(
"decoding"
,
encoding
);
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