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
c0937f79
Kaydet (Commit)
c0937f79
authored
May 18, 2015
tarafından
Serhiy Storchaka
Dosyalara gözat
Seçenekler
Dosyalara Gözat
İndir
Sade Fark
Issue #24102: Fixed exception type checking in standard error handlers.
üst
f4e60305
ca7fecb0
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
47 additions
and
27 deletions
+47
-27
test_codeccallbacks.py
Lib/test/test_codeccallbacks.py
+24
-0
NEWS
Misc/NEWS
+2
-0
codecs.c
Python/codecs.c
+21
-27
No files found.
Lib/test/test_codeccallbacks.py
Dosyayı görüntüle @
c0937f79
...
@@ -1046,6 +1046,30 @@ class CodecCallbackTest(unittest.TestCase):
...
@@ -1046,6 +1046,30 @@ class CodecCallbackTest(unittest.TestCase):
with
self
.
assertRaises
(
TypeError
):
with
self
.
assertRaises
(
TypeError
):
data
.
decode
(
encoding
,
"test.replacing"
)
data
.
decode
(
encoding
,
"test.replacing"
)
def
test_fake_error_class
(
self
):
handlers
=
[
codecs
.
strict_errors
,
codecs
.
ignore_errors
,
codecs
.
replace_errors
,
codecs
.
backslashreplace_errors
,
codecs
.
namereplace_errors
,
codecs
.
xmlcharrefreplace_errors
,
codecs
.
lookup_error
(
'surrogateescape'
),
codecs
.
lookup_error
(
'surrogatepass'
),
]
for
cls
in
UnicodeEncodeError
,
UnicodeDecodeError
,
UnicodeTranslateError
:
class
FakeUnicodeError
(
str
):
__class__
=
cls
for
handler
in
handlers
:
with
self
.
subTest
(
handler
=
handler
,
error_class
=
cls
):
self
.
assertRaises
(
TypeError
,
handler
,
FakeUnicodeError
())
class
FakeUnicodeError
(
Exception
):
__class__
=
cls
for
handler
in
handlers
:
with
self
.
subTest
(
handler
=
handler
,
error_class
=
cls
):
with
self
.
assertRaises
((
TypeError
,
FakeUnicodeError
)):
handler
(
FakeUnicodeError
())
if
__name__
==
"__main__"
:
if
__name__
==
"__main__"
:
unittest
.
main
()
unittest
.
main
()
Misc/NEWS
Dosyayı görüntüle @
c0937f79
...
@@ -10,6 +10,8 @@ Release date: 2015-05-24
...
@@ -10,6 +10,8 @@ Release date: 2015-05-24
Core and Builtins
Core and Builtins
-----------------
-----------------
- Issue #24102: Fixed exception type checking in standard error handlers.
- Issue #15027: The UTF-32 encoder is now 3x to 7x faster.
- Issue #15027: The UTF-32 encoder is now 3x to 7x faster.
- Issue #23290: Optimize set_merge() for cases where the target is empty.
- Issue #23290: Optimize set_merge() for cases where the target is empty.
...
...
Python/codecs.c
Dosyayı görüntüle @
c0937f79
...
@@ -662,18 +662,9 @@ PyObject *PyCodec_LookupError(const char *name)
...
@@ -662,18 +662,9 @@ PyObject *PyCodec_LookupError(const char *name)
static
void
wrong_exception_type
(
PyObject
*
exc
)
static
void
wrong_exception_type
(
PyObject
*
exc
)
{
{
_Py_IDENTIFIER
(
__class__
);
PyErr_Format
(
PyExc_TypeError
,
_Py_IDENTIFIER
(
__name__
);
"don't know how to handle %.200s in error callback"
,
PyObject
*
type
=
_PyObject_GetAttrId
(
exc
,
&
PyId___class__
);
exc
->
ob_type
->
tp_name
);
if
(
type
!=
NULL
)
{
PyObject
*
name
=
_PyObject_GetAttrId
(
type
,
&
PyId___name__
);
Py_DECREF
(
type
);
if
(
name
!=
NULL
)
{
PyErr_Format
(
PyExc_TypeError
,
"don't know how to handle %S in error callback"
,
name
);
Py_DECREF
(
name
);
}
}
}
}
PyObject
*
PyCodec_StrictErrors
(
PyObject
*
exc
)
PyObject
*
PyCodec_StrictErrors
(
PyObject
*
exc
)
...
@@ -689,15 +680,16 @@ PyObject *PyCodec_StrictErrors(PyObject *exc)
...
@@ -689,15 +680,16 @@ PyObject *PyCodec_StrictErrors(PyObject *exc)
PyObject
*
PyCodec_IgnoreErrors
(
PyObject
*
exc
)
PyObject
*
PyCodec_IgnoreErrors
(
PyObject
*
exc
)
{
{
Py_ssize_t
end
;
Py_ssize_t
end
;
if
(
PyObject_IsInstance
(
exc
,
PyExc_UnicodeEncodeError
))
{
if
(
PyObject_TypeCheck
(
exc
,
(
PyTypeObject
*
)
PyExc_UnicodeEncodeError
))
{
if
(
PyUnicodeEncodeError_GetEnd
(
exc
,
&
end
))
if
(
PyUnicodeEncodeError_GetEnd
(
exc
,
&
end
))
return
NULL
;
return
NULL
;
}
}
else
if
(
PyObject_
IsInstance
(
exc
,
PyExc_UnicodeDecodeError
))
{
else
if
(
PyObject_
TypeCheck
(
exc
,
(
PyTypeObject
*
)
PyExc_UnicodeDecodeError
))
{
if
(
PyUnicodeDecodeError_GetEnd
(
exc
,
&
end
))
if
(
PyUnicodeDecodeError_GetEnd
(
exc
,
&
end
))
return
NULL
;
return
NULL
;
}
}
else
if
(
PyObject_
IsInstance
(
exc
,
PyExc_UnicodeTranslateError
))
{
else
if
(
PyObject_
TypeCheck
(
exc
,
(
PyTypeObject
*
)
PyExc_UnicodeTranslateError
))
{
if
(
PyUnicodeTranslateError_GetEnd
(
exc
,
&
end
))
if
(
PyUnicodeTranslateError_GetEnd
(
exc
,
&
end
))
return
NULL
;
return
NULL
;
}
}
...
@@ -713,7 +705,7 @@ PyObject *PyCodec_ReplaceErrors(PyObject *exc)
...
@@ -713,7 +705,7 @@ PyObject *PyCodec_ReplaceErrors(PyObject *exc)
{
{
Py_ssize_t
start
,
end
,
i
,
len
;
Py_ssize_t
start
,
end
,
i
,
len
;
if
(
PyObject_
IsInstance
(
exc
,
PyExc_UnicodeEncodeError
))
{
if
(
PyObject_
TypeCheck
(
exc
,
(
PyTypeObject
*
)
PyExc_UnicodeEncodeError
))
{
PyObject
*
res
;
PyObject
*
res
;
int
kind
;
int
kind
;
void
*
data
;
void
*
data
;
...
@@ -732,14 +724,14 @@ PyObject *PyCodec_ReplaceErrors(PyObject *exc)
...
@@ -732,14 +724,14 @@ PyObject *PyCodec_ReplaceErrors(PyObject *exc)
assert
(
_PyUnicode_CheckConsistency
(
res
,
1
));
assert
(
_PyUnicode_CheckConsistency
(
res
,
1
));
return
Py_BuildValue
(
"(Nn)"
,
res
,
end
);
return
Py_BuildValue
(
"(Nn)"
,
res
,
end
);
}
}
else
if
(
PyObject_
IsInstance
(
exc
,
PyExc_UnicodeDecodeError
))
{
else
if
(
PyObject_
TypeCheck
(
exc
,
(
PyTypeObject
*
)
PyExc_UnicodeDecodeError
))
{
if
(
PyUnicodeDecodeError_GetEnd
(
exc
,
&
end
))
if
(
PyUnicodeDecodeError_GetEnd
(
exc
,
&
end
))
return
NULL
;
return
NULL
;
return
Py_BuildValue
(
"(Cn)"
,
return
Py_BuildValue
(
"(Cn)"
,
(
int
)
Py_UNICODE_REPLACEMENT_CHARACTER
,
(
int
)
Py_UNICODE_REPLACEMENT_CHARACTER
,
end
);
end
);
}
}
else
if
(
PyObject_
IsInstance
(
exc
,
PyExc_UnicodeTranslateError
))
{
else
if
(
PyObject_
TypeCheck
(
exc
,
(
PyTypeObject
*
)
PyExc_UnicodeTranslateError
))
{
PyObject
*
res
;
PyObject
*
res
;
int
kind
;
int
kind
;
void
*
data
;
void
*
data
;
...
@@ -766,7 +758,7 @@ PyObject *PyCodec_ReplaceErrors(PyObject *exc)
...
@@ -766,7 +758,7 @@ PyObject *PyCodec_ReplaceErrors(PyObject *exc)
PyObject
*
PyCodec_XMLCharRefReplaceErrors
(
PyObject
*
exc
)
PyObject
*
PyCodec_XMLCharRefReplaceErrors
(
PyObject
*
exc
)
{
{
if
(
PyObject_
IsInstance
(
exc
,
PyExc_UnicodeEncodeError
))
{
if
(
PyObject_
TypeCheck
(
exc
,
(
PyTypeObject
*
)
PyExc_UnicodeEncodeError
))
{
PyObject
*
restuple
;
PyObject
*
restuple
;
PyObject
*
object
;
PyObject
*
object
;
Py_ssize_t
i
;
Py_ssize_t
i
;
...
@@ -873,7 +865,7 @@ PyObject *PyCodec_BackslashReplaceErrors(PyObject *exc)
...
@@ -873,7 +865,7 @@ PyObject *PyCodec_BackslashReplaceErrors(PyObject *exc)
int
ressize
;
int
ressize
;
Py_UCS4
c
;
Py_UCS4
c
;
if
(
PyObject_
IsInstance
(
exc
,
PyExc_UnicodeDecodeError
))
{
if
(
PyObject_
TypeCheck
(
exc
,
(
PyTypeObject
*
)
PyExc_UnicodeDecodeError
))
{
unsigned
char
*
p
;
unsigned
char
*
p
;
if
(
PyUnicodeDecodeError_GetStart
(
exc
,
&
start
))
if
(
PyUnicodeDecodeError_GetStart
(
exc
,
&
start
))
return
NULL
;
return
NULL
;
...
@@ -903,7 +895,7 @@ PyObject *PyCodec_BackslashReplaceErrors(PyObject *exc)
...
@@ -903,7 +895,7 @@ PyObject *PyCodec_BackslashReplaceErrors(PyObject *exc)
Py_DECREF
(
object
);
Py_DECREF
(
object
);
return
Py_BuildValue
(
"(Nn)"
,
res
,
end
);
return
Py_BuildValue
(
"(Nn)"
,
res
,
end
);
}
}
if
(
PyObject_
IsInstance
(
exc
,
PyExc_UnicodeEncodeError
))
{
if
(
PyObject_
TypeCheck
(
exc
,
(
PyTypeObject
*
)
PyExc_UnicodeEncodeError
))
{
if
(
PyUnicodeEncodeError_GetStart
(
exc
,
&
start
))
if
(
PyUnicodeEncodeError_GetStart
(
exc
,
&
start
))
return
NULL
;
return
NULL
;
if
(
PyUnicodeEncodeError_GetEnd
(
exc
,
&
end
))
if
(
PyUnicodeEncodeError_GetEnd
(
exc
,
&
end
))
...
@@ -911,7 +903,7 @@ PyObject *PyCodec_BackslashReplaceErrors(PyObject *exc)
...
@@ -911,7 +903,7 @@ PyObject *PyCodec_BackslashReplaceErrors(PyObject *exc)
if
(
!
(
object
=
PyUnicodeEncodeError_GetObject
(
exc
)))
if
(
!
(
object
=
PyUnicodeEncodeError_GetObject
(
exc
)))
return
NULL
;
return
NULL
;
}
}
else
if
(
PyObject_
IsInstance
(
exc
,
PyExc_UnicodeTranslateError
))
{
else
if
(
PyObject_
TypeCheck
(
exc
,
(
PyTypeObject
*
)
PyExc_UnicodeTranslateError
))
{
if
(
PyUnicodeTranslateError_GetStart
(
exc
,
&
start
))
if
(
PyUnicodeTranslateError_GetStart
(
exc
,
&
start
))
return
NULL
;
return
NULL
;
if
(
PyUnicodeTranslateError_GetEnd
(
exc
,
&
end
))
if
(
PyUnicodeTranslateError_GetEnd
(
exc
,
&
end
))
...
@@ -977,7 +969,7 @@ static int ucnhash_initialized = 0;
...
@@ -977,7 +969,7 @@ static int ucnhash_initialized = 0;
PyObject
*
PyCodec_NameReplaceErrors
(
PyObject
*
exc
)
PyObject
*
PyCodec_NameReplaceErrors
(
PyObject
*
exc
)
{
{
if
(
PyObject_
IsInstance
(
exc
,
PyExc_UnicodeEncodeError
))
{
if
(
PyObject_
TypeCheck
(
exc
,
(
PyTypeObject
*
)
PyExc_UnicodeEncodeError
))
{
PyObject
*
restuple
;
PyObject
*
restuple
;
PyObject
*
object
;
PyObject
*
object
;
Py_ssize_t
i
;
Py_ssize_t
i
;
...
@@ -1150,7 +1142,8 @@ PyCodec_SurrogatePassErrors(PyObject *exc)
...
@@ -1150,7 +1142,8 @@ PyCodec_SurrogatePassErrors(PyObject *exc)
Py_ssize_t
start
;
Py_ssize_t
start
;
Py_ssize_t
end
;
Py_ssize_t
end
;
PyObject
*
res
;
PyObject
*
res
;
if
(
PyObject_IsInstance
(
exc
,
PyExc_UnicodeEncodeError
))
{
if
(
PyObject_TypeCheck
(
exc
,
(
PyTypeObject
*
)
PyExc_UnicodeEncodeError
))
{
unsigned
char
*
outp
;
unsigned
char
*
outp
;
if
(
PyUnicodeEncodeError_GetStart
(
exc
,
&
start
))
if
(
PyUnicodeEncodeError_GetStart
(
exc
,
&
start
))
return
NULL
;
return
NULL
;
...
@@ -1227,7 +1220,7 @@ PyCodec_SurrogatePassErrors(PyObject *exc)
...
@@ -1227,7 +1220,7 @@ PyCodec_SurrogatePassErrors(PyObject *exc)
Py_DECREF
(
object
);
Py_DECREF
(
object
);
return
restuple
;
return
restuple
;
}
}
else
if
(
PyObject_
IsInstance
(
exc
,
PyExc_UnicodeDecodeError
))
{
else
if
(
PyObject_
TypeCheck
(
exc
,
(
PyTypeObject
*
)
PyExc_UnicodeDecodeError
))
{
unsigned
char
*
p
;
unsigned
char
*
p
;
Py_UCS4
ch
=
0
;
Py_UCS4
ch
=
0
;
if
(
PyUnicodeDecodeError_GetStart
(
exc
,
&
start
))
if
(
PyUnicodeDecodeError_GetStart
(
exc
,
&
start
))
...
@@ -1312,7 +1305,8 @@ PyCodec_SurrogateEscapeErrors(PyObject *exc)
...
@@ -1312,7 +1305,8 @@ PyCodec_SurrogateEscapeErrors(PyObject *exc)
Py_ssize_t
start
;
Py_ssize_t
start
;
Py_ssize_t
end
;
Py_ssize_t
end
;
PyObject
*
res
;
PyObject
*
res
;
if
(
PyObject_IsInstance
(
exc
,
PyExc_UnicodeEncodeError
))
{
if
(
PyObject_TypeCheck
(
exc
,
(
PyTypeObject
*
)
PyExc_UnicodeEncodeError
))
{
char
*
outp
;
char
*
outp
;
if
(
PyUnicodeEncodeError_GetStart
(
exc
,
&
start
))
if
(
PyUnicodeEncodeError_GetStart
(
exc
,
&
start
))
return
NULL
;
return
NULL
;
...
@@ -1343,7 +1337,7 @@ PyCodec_SurrogateEscapeErrors(PyObject *exc)
...
@@ -1343,7 +1337,7 @@ PyCodec_SurrogateEscapeErrors(PyObject *exc)
Py_DECREF
(
object
);
Py_DECREF
(
object
);
return
restuple
;
return
restuple
;
}
}
else
if
(
PyObject_
IsInstance
(
exc
,
PyExc_UnicodeDecodeError
))
{
else
if
(
PyObject_
TypeCheck
(
exc
,
(
PyTypeObject
*
)
PyExc_UnicodeDecodeError
))
{
PyObject
*
str
;
PyObject
*
str
;
unsigned
char
*
p
;
unsigned
char
*
p
;
Py_UCS2
ch
[
4
];
/* decode up to 4 bad bytes. */
Py_UCS2
ch
[
4
];
/* decode up to 4 bad bytes. */
...
...
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