mirror of
https://github.com/python/cpython.git
synced 2025-09-26 18:29:57 +00:00
Drop Py_UNICODE based encode exceptions.
This commit is contained in:
parent
3d325191bf
commit
12be46ca84
1 changed files with 22 additions and 60 deletions
|
@ -253,12 +253,6 @@ unicode_encode_call_errorhandler(const char *errors,
|
||||||
|
|
||||||
static void
|
static void
|
||||||
raise_encode_exception(PyObject **exceptionObject,
|
raise_encode_exception(PyObject **exceptionObject,
|
||||||
const char *encoding,
|
|
||||||
const Py_UNICODE *unicode, Py_ssize_t size,
|
|
||||||
Py_ssize_t startpos, Py_ssize_t endpos,
|
|
||||||
const char *reason);
|
|
||||||
static void
|
|
||||||
raise_encode_exception_obj(PyObject **exceptionObject,
|
|
||||||
const char *encoding,
|
const char *encoding,
|
||||||
PyObject *unicode,
|
PyObject *unicode,
|
||||||
Py_ssize_t startpos, Py_ssize_t endpos,
|
Py_ssize_t startpos, Py_ssize_t endpos,
|
||||||
|
@ -3058,8 +3052,7 @@ PyUnicode_EncodeFSDefault(PyObject *unicode)
|
||||||
if (errmsg == NULL)
|
if (errmsg == NULL)
|
||||||
errmsg = "Py_wchar2char() failed";
|
errmsg = "Py_wchar2char() failed";
|
||||||
raise_encode_exception(&exc,
|
raise_encode_exception(&exc,
|
||||||
"filesystemencoding",
|
"filesystemencoding", unicode,
|
||||||
PyUnicode_AS_UNICODE(unicode), PyUnicode_GET_SIZE(unicode),
|
|
||||||
error_pos, error_pos+1,
|
error_pos, error_pos+1,
|
||||||
errmsg);
|
errmsg);
|
||||||
Py_XDECREF(exc);
|
Py_XDECREF(exc);
|
||||||
|
@ -4783,7 +4776,7 @@ _PyUnicode_AsUTF8String(PyObject *unicode, const char *errors)
|
||||||
for(k=0; k<repsize; k++) {
|
for(k=0; k<repsize; k++) {
|
||||||
c = prep[k];
|
c = prep[k];
|
||||||
if (0x80 <= c) {
|
if (0x80 <= c) {
|
||||||
raise_encode_exception_obj(&exc, "utf-8",
|
raise_encode_exception(&exc, "utf-8",
|
||||||
unicode,
|
unicode,
|
||||||
i-1, i,
|
i-1, i,
|
||||||
"surrogates not allowed");
|
"surrogates not allowed");
|
||||||
|
@ -6405,32 +6398,6 @@ PyUnicode_DecodeLatin1(const char *s,
|
||||||
/* create or adjust a UnicodeEncodeError */
|
/* create or adjust a UnicodeEncodeError */
|
||||||
static void
|
static void
|
||||||
make_encode_exception(PyObject **exceptionObject,
|
make_encode_exception(PyObject **exceptionObject,
|
||||||
const char *encoding,
|
|
||||||
const Py_UNICODE *unicode, Py_ssize_t size,
|
|
||||||
Py_ssize_t startpos, Py_ssize_t endpos,
|
|
||||||
const char *reason)
|
|
||||||
{
|
|
||||||
if (*exceptionObject == NULL) {
|
|
||||||
*exceptionObject = PyUnicodeEncodeError_Create(
|
|
||||||
encoding, unicode, size, startpos, endpos, reason);
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
if (PyUnicodeEncodeError_SetStart(*exceptionObject, startpos))
|
|
||||||
goto onError;
|
|
||||||
if (PyUnicodeEncodeError_SetEnd(*exceptionObject, endpos))
|
|
||||||
goto onError;
|
|
||||||
if (PyUnicodeEncodeError_SetReason(*exceptionObject, reason))
|
|
||||||
goto onError;
|
|
||||||
return;
|
|
||||||
onError:
|
|
||||||
Py_DECREF(*exceptionObject);
|
|
||||||
*exceptionObject = NULL;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/* This is ultimately going t replace above function. */
|
|
||||||
static void
|
|
||||||
make_encode_exception_obj(PyObject **exceptionObject,
|
|
||||||
const char *encoding,
|
const char *encoding,
|
||||||
PyObject *unicode,
|
PyObject *unicode,
|
||||||
Py_ssize_t startpos, Py_ssize_t endpos,
|
Py_ssize_t startpos, Py_ssize_t endpos,
|
||||||
|
@ -6458,25 +6425,12 @@ make_encode_exception_obj(PyObject **exceptionObject,
|
||||||
/* raises a UnicodeEncodeError */
|
/* raises a UnicodeEncodeError */
|
||||||
static void
|
static void
|
||||||
raise_encode_exception(PyObject **exceptionObject,
|
raise_encode_exception(PyObject **exceptionObject,
|
||||||
const char *encoding,
|
|
||||||
const Py_UNICODE *unicode, Py_ssize_t size,
|
|
||||||
Py_ssize_t startpos, Py_ssize_t endpos,
|
|
||||||
const char *reason)
|
|
||||||
{
|
|
||||||
make_encode_exception(exceptionObject,
|
|
||||||
encoding, unicode, size, startpos, endpos, reason);
|
|
||||||
if (*exceptionObject != NULL)
|
|
||||||
PyCodec_StrictErrors(*exceptionObject);
|
|
||||||
}
|
|
||||||
/* This is ultimately going to replace above function. */
|
|
||||||
static void
|
|
||||||
raise_encode_exception_obj(PyObject **exceptionObject,
|
|
||||||
const char *encoding,
|
const char *encoding,
|
||||||
PyObject *unicode,
|
PyObject *unicode,
|
||||||
Py_ssize_t startpos, Py_ssize_t endpos,
|
Py_ssize_t startpos, Py_ssize_t endpos,
|
||||||
const char *reason)
|
const char *reason)
|
||||||
{
|
{
|
||||||
make_encode_exception_obj(exceptionObject,
|
make_encode_exception(exceptionObject,
|
||||||
encoding, unicode, startpos, endpos, reason);
|
encoding, unicode, startpos, endpos, reason);
|
||||||
if (*exceptionObject != NULL)
|
if (*exceptionObject != NULL)
|
||||||
PyCodec_StrictErrors(*exceptionObject);
|
PyCodec_StrictErrors(*exceptionObject);
|
||||||
|
@ -6509,7 +6463,7 @@ unicode_encode_call_errorhandler(const char *errors,
|
||||||
return NULL;
|
return NULL;
|
||||||
len = PyUnicode_GET_LENGTH(unicode);
|
len = PyUnicode_GET_LENGTH(unicode);
|
||||||
|
|
||||||
make_encode_exception_obj(exceptionObject,
|
make_encode_exception(exceptionObject,
|
||||||
encoding, unicode, startpos, endpos, reason);
|
encoding, unicode, startpos, endpos, reason);
|
||||||
if (*exceptionObject == NULL)
|
if (*exceptionObject == NULL)
|
||||||
return NULL;
|
return NULL;
|
||||||
|
@ -6617,7 +6571,7 @@ unicode_encode_ucs1(PyObject *unicode,
|
||||||
}
|
}
|
||||||
switch (known_errorHandler) {
|
switch (known_errorHandler) {
|
||||||
case 1: /* strict */
|
case 1: /* strict */
|
||||||
raise_encode_exception_obj(&exc, encoding, unicode, collstart, collend, reason);
|
raise_encode_exception(&exc, encoding, unicode, collstart, collend, reason);
|
||||||
goto onError;
|
goto onError;
|
||||||
case 2: /* replace */
|
case 2: /* replace */
|
||||||
while (collstart++<collend)
|
while (collstart++<collend)
|
||||||
|
@ -6712,7 +6666,7 @@ unicode_encode_ucs1(PyObject *unicode,
|
||||||
for (i = 0; repsize-->0; ++i, ++str) {
|
for (i = 0; repsize-->0; ++i, ++str) {
|
||||||
c = PyUnicode_READ_CHAR(repunicode, i);
|
c = PyUnicode_READ_CHAR(repunicode, i);
|
||||||
if (c >= limit) {
|
if (c >= limit) {
|
||||||
raise_encode_exception_obj(&exc, encoding, unicode,
|
raise_encode_exception(&exc, encoding, unicode,
|
||||||
pos, pos+1, reason);
|
pos, pos+1, reason);
|
||||||
Py_DECREF(repunicode);
|
Py_DECREF(repunicode);
|
||||||
goto onError;
|
goto onError;
|
||||||
|
@ -7434,7 +7388,7 @@ encode_code_page_errors(UINT code_page, PyObject **outbytes,
|
||||||
if (errors == NULL || strcmp(errors, "strict") == 0) {
|
if (errors == NULL || strcmp(errors, "strict") == 0) {
|
||||||
/* The last error was ERROR_NO_UNICODE_TRANSLATION,
|
/* The last error was ERROR_NO_UNICODE_TRANSLATION,
|
||||||
then we raise a UnicodeEncodeError. */
|
then we raise a UnicodeEncodeError. */
|
||||||
make_encode_exception_obj(&exc, encoding, unicode, 0, 0, reason);
|
make_encode_exception(&exc, encoding, unicode, 0, 0, reason);
|
||||||
if (exc != NULL) {
|
if (exc != NULL) {
|
||||||
PyCodec_StrictErrors(exc);
|
PyCodec_StrictErrors(exc);
|
||||||
Py_DECREF(exc);
|
Py_DECREF(exc);
|
||||||
|
@ -7555,7 +7509,7 @@ encode_code_page_errors(UINT code_page, PyObject **outbytes,
|
||||||
for (i=0; i < outsize; i++) {
|
for (i=0; i < outsize; i++) {
|
||||||
Py_UCS4 ch = PyUnicode_READ(kind, data, i);
|
Py_UCS4 ch = PyUnicode_READ(kind, data, i);
|
||||||
if (ch > 127) {
|
if (ch > 127) {
|
||||||
raise_encode_exception_obj(&exc,
|
raise_encode_exception(&exc,
|
||||||
encoding, unicode,
|
encoding, unicode,
|
||||||
pos, pos + 1,
|
pos, pos + 1,
|
||||||
"unable to encode error handler result to ASCII");
|
"unable to encode error handler result to ASCII");
|
||||||
|
@ -8250,7 +8204,7 @@ charmap_encoding_error(
|
||||||
}
|
}
|
||||||
switch (*known_errorHandler) {
|
switch (*known_errorHandler) {
|
||||||
case 1: /* strict */
|
case 1: /* strict */
|
||||||
raise_encode_exception_obj(exceptionObject, encoding, unicode, collstartpos, collendpos, reason);
|
raise_encode_exception(exceptionObject, encoding, unicode, collstartpos, collendpos, reason);
|
||||||
return -1;
|
return -1;
|
||||||
case 2: /* replace */
|
case 2: /* replace */
|
||||||
for (collpos = collstartpos; collpos<collendpos; ++collpos) {
|
for (collpos = collstartpos; collpos<collendpos; ++collpos) {
|
||||||
|
@ -8259,7 +8213,7 @@ charmap_encoding_error(
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
else if (x==enc_FAILED) {
|
else if (x==enc_FAILED) {
|
||||||
raise_encode_exception_obj(exceptionObject, encoding, unicode, collstartpos, collendpos, reason);
|
raise_encode_exception(exceptionObject, encoding, unicode, collstartpos, collendpos, reason);
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -8278,7 +8232,7 @@ charmap_encoding_error(
|
||||||
if (x==enc_EXCEPTION)
|
if (x==enc_EXCEPTION)
|
||||||
return -1;
|
return -1;
|
||||||
else if (x==enc_FAILED) {
|
else if (x==enc_FAILED) {
|
||||||
raise_encode_exception_obj(exceptionObject, encoding, unicode, collstartpos, collendpos, reason);
|
raise_encode_exception(exceptionObject, encoding, unicode, collstartpos, collendpos, reason);
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -8319,7 +8273,7 @@ charmap_encoding_error(
|
||||||
}
|
}
|
||||||
else if (x==enc_FAILED) {
|
else if (x==enc_FAILED) {
|
||||||
Py_DECREF(repunicode);
|
Py_DECREF(repunicode);
|
||||||
raise_encode_exception_obj(exceptionObject, encoding, unicode, collstartpos, collendpos, reason);
|
raise_encode_exception(exceptionObject, encoding, unicode, collstartpos, collendpos, reason);
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -8990,7 +8944,11 @@ PyUnicode_EncodeDecimal(Py_UNICODE *s,
|
||||||
}
|
}
|
||||||
switch (known_errorHandler) {
|
switch (known_errorHandler) {
|
||||||
case 1: /* strict */
|
case 1: /* strict */
|
||||||
raise_encode_exception(&exc, encoding, s, length, collstart-s, collend-s, reason);
|
unicode = PyUnicode_FromUnicode(s, length);
|
||||||
|
if (unicode == NULL)
|
||||||
|
goto onError;
|
||||||
|
raise_encode_exception(&exc, encoding, unicode, collstart-s, collend-s, reason);
|
||||||
|
Py_DECREF(unicode);
|
||||||
goto onError;
|
goto onError;
|
||||||
case 2: /* replace */
|
case 2: /* replace */
|
||||||
for (p = collstart; p < collend; ++p)
|
for (p = collstart; p < collend; ++p)
|
||||||
|
@ -9035,8 +8993,12 @@ PyUnicode_EncodeDecimal(Py_UNICODE *s,
|
||||||
*output++ = (char)ch;
|
*output++ = (char)ch;
|
||||||
else {
|
else {
|
||||||
Py_DECREF(repunicode);
|
Py_DECREF(repunicode);
|
||||||
|
unicode = PyUnicode_FromUnicode(s, length);
|
||||||
|
if (unicode == NULL)
|
||||||
|
goto onError;
|
||||||
raise_encode_exception(&exc, encoding,
|
raise_encode_exception(&exc, encoding,
|
||||||
s, length, collstart-s, collend-s, reason);
|
unicode, collstart-s, collend-s, reason);
|
||||||
|
Py_DECREF(unicode);
|
||||||
goto onError;
|
goto onError;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue