@@ -2995,53 +2995,56 @@ static PyObject *
2995
2995
UnicodeEncodeError_str (PyObject * self )
2996
2996
{
2997
2997
PyUnicodeErrorObject * exc = (PyUnicodeErrorObject * )self ;
2998
- PyObject * res = NULL ;
2998
+ PyObject * result = NULL ;
2999
2999
PyObject * reason_str = NULL ;
3000
3000
PyObject * encoding_str = NULL ;
3001
3001
3002
- if (exc -> object == NULL ) {
3002
+ if (exc -> object == NULL )
3003
3003
/* Not properly initialized. */
3004
3004
return PyUnicode_FromString ("" );
3005
- }
3006
3005
3007
3006
/* Get reason and encoding as strings, which they might not be if
3008
3007
they've been modified after we were constructed. */
3009
3008
reason_str = PyObject_Str (exc -> reason );
3010
- if (reason_str == NULL ) {
3009
+ if (reason_str == NULL )
3011
3010
goto done ;
3012
- }
3013
3011
encoding_str = PyObject_Str (exc -> encoding );
3014
- if (encoding_str == NULL ) {
3012
+ if (encoding_str == NULL )
3015
3013
goto done ;
3016
- }
3017
3014
3018
3015
Py_ssize_t len = PyUnicode_GET_LENGTH (exc -> object );
3019
3016
Py_ssize_t start = exc -> start , end = exc -> end ;
3020
3017
3021
3018
if ((start >= 0 && start < len ) && (end >= 0 && end <= len ) && end == start + 1 ) {
3022
3019
Py_UCS4 badchar = PyUnicode_ReadChar (exc -> object , start );
3023
3020
const char * fmt ;
3024
- if (badchar <= 0xff ) {
3021
+ if (badchar <= 0xff )
3025
3022
fmt = "'%U' codec can't encode character '\\x%02x' in position %zd: %U" ;
3026
- }
3027
- else if (badchar <= 0xffff ) {
3023
+ else if (badchar <= 0xffff )
3028
3024
fmt = "'%U' codec can't encode character '\\u%04x' in position %zd: %U" ;
3029
- }
3030
- else {
3025
+ else
3031
3026
fmt = "'%U' codec can't encode character '\\U%08x' in position %zd: %U" ;
3032
- }
3033
- res = PyUnicode_FromFormat (fmt , encoding_str , (int )badchar , start , reason_str );
3027
+ result = PyUnicode_FromFormat (
3028
+ fmt ,
3029
+ encoding_str ,
3030
+ (int )badchar ,
3031
+ start ,
3032
+ reason_str
3033
+ );
3034
3034
}
3035
3035
else {
3036
- res = PyUnicode_FromFormat (
3036
+ result = PyUnicode_FromFormat (
3037
3037
"'%U' codec can't encode characters in position %zd-%zd: %U" ,
3038
- encoding_str , start , end - 1 , reason_str
3038
+ encoding_str ,
3039
+ start ,
3040
+ end - 1 ,
3041
+ reason_str
3039
3042
);
3040
3043
}
3041
3044
done :
3042
3045
Py_XDECREF (reason_str );
3043
3046
Py_XDECREF (encoding_str );
3044
- return res ;
3047
+ return result ;
3045
3048
}
3046
3049
3047
3050
static PyTypeObject _PyExc_UnicodeEncodeError = {
@@ -3110,46 +3113,49 @@ static PyObject *
3110
3113
UnicodeDecodeError_str (PyObject * self )
3111
3114
{
3112
3115
PyUnicodeErrorObject * exc = (PyUnicodeErrorObject * )self ;
3113
- PyObject * res = NULL ;
3116
+ PyObject * result = NULL ;
3114
3117
PyObject * reason_str = NULL ;
3115
3118
PyObject * encoding_str = NULL ;
3116
3119
3117
- if (exc -> object == NULL ) {
3120
+ if (exc -> object == NULL )
3118
3121
/* Not properly initialized. */
3119
3122
return PyUnicode_FromString ("" );
3120
- }
3121
3123
3122
3124
/* Get reason and encoding as strings, which they might not be if
3123
3125
they've been modified after we were constructed. */
3124
3126
reason_str = PyObject_Str (exc -> reason );
3125
- if (reason_str == NULL ) {
3127
+ if (reason_str == NULL )
3126
3128
goto done ;
3127
- }
3128
3129
encoding_str = PyObject_Str (exc -> encoding );
3129
- if (encoding_str == NULL ) {
3130
+ if (encoding_str == NULL )
3130
3131
goto done ;
3131
- }
3132
3132
3133
3133
Py_ssize_t len = PyBytes_GET_SIZE (exc -> object );
3134
3134
Py_ssize_t start = exc -> start , end = exc -> end ;
3135
3135
3136
3136
if ((start >= 0 && start < len ) && (end >= 0 && end <= len ) && end == start + 1 ) {
3137
3137
int badbyte = (int )(PyBytes_AS_STRING (exc -> object )[start ] & 0xff );
3138
- res = PyUnicode_FromFormat (
3138
+ result = PyUnicode_FromFormat (
3139
3139
"'%U' codec can't decode byte 0x%02x in position %zd: %U" ,
3140
- encoding_str , badbyte , start , reason_str
3140
+ encoding_str ,
3141
+ badbyte ,
3142
+ start ,
3143
+ reason_str
3141
3144
);
3142
3145
}
3143
3146
else {
3144
- res = PyUnicode_FromFormat (
3147
+ result = PyUnicode_FromFormat (
3145
3148
"'%U' codec can't decode bytes in position %zd-%zd: %U" ,
3146
- encoding_str , start , end - 1 , reason_str
3149
+ encoding_str ,
3150
+ start ,
3151
+ end - 1 ,
3152
+ reason_str
3147
3153
);
3148
3154
}
3149
3155
done :
3150
3156
Py_XDECREF (reason_str );
3151
3157
Py_XDECREF (encoding_str );
3152
- return res ;
3158
+ return result ;
3153
3159
}
3154
3160
3155
3161
static PyTypeObject _PyExc_UnicodeDecodeError = {
@@ -3208,47 +3214,41 @@ static PyObject *
3208
3214
UnicodeTranslateError_str (PyObject * self )
3209
3215
{
3210
3216
PyUnicodeErrorObject * exc = (PyUnicodeErrorObject * )self ;
3211
- PyObject * res = NULL ;
3217
+ PyObject * result = NULL ;
3212
3218
PyObject * reason_str = NULL ;
3213
3219
3214
- if (exc -> object == NULL ) {
3220
+ if (exc -> object == NULL )
3215
3221
/* Not properly initialized. */
3216
3222
return PyUnicode_FromString ("" );
3217
- }
3218
3223
3219
3224
/* Get reason as a string, which it might not be if it's been
3220
3225
modified after we were constructed. */
3221
3226
reason_str = PyObject_Str (exc -> reason );
3222
- if (reason_str == NULL ) {
3227
+ if (reason_str == NULL )
3223
3228
goto done ;
3224
- }
3225
3229
3226
3230
Py_ssize_t len = PyUnicode_GET_LENGTH (exc -> object );
3227
3231
Py_ssize_t start = exc -> start , end = exc -> end ;
3228
3232
3229
3233
if ((start >= 0 && start < len ) && (end >= 0 && end <= len ) && end == start + 1 ) {
3230
3234
Py_UCS4 badchar = PyUnicode_ReadChar (exc -> object , start );
3231
3235
const char * fmt ;
3232
- if (badchar <= 0xff ) {
3236
+ if (badchar <= 0xff )
3233
3237
fmt = "can't translate character '\\x%02x' in position %zd: %U" ;
3234
- }
3235
- else if (badchar <= 0xffff ) {
3238
+ else if (badchar <= 0xffff )
3236
3239
fmt = "can't translate character '\\u%04x' in position %zd: %U" ;
3237
- }
3238
- else {
3240
+ else
3239
3241
fmt = "can't translate character '\\U%08x' in position %zd: %U" ;
3240
- }
3241
- res = PyUnicode_FromFormat (fmt , (int )badchar , start , reason_str );
3242
- }
3243
- else {
3244
- res = PyUnicode_FromFormat (
3242
+ result = PyUnicode_FromFormat (fmt , (int )badchar , start , reason_str );
3243
+ } else {
3244
+ result = PyUnicode_FromFormat (
3245
3245
"can't translate characters in position %zd-%zd: %U" ,
3246
3246
start , end - 1 , reason_str
3247
3247
);
3248
3248
}
3249
3249
done :
3250
3250
Py_XDECREF (reason_str );
3251
- return res ;
3251
+ return result ;
3252
3252
}
3253
3253
3254
3254
static PyTypeObject _PyExc_UnicodeTranslateError = {
0 commit comments