Show More
@@ -115,7 +115,8 b' PyObject *unhexlify(const char *str, int' | |||||
115 | } |
|
115 | } | |
116 |
|
116 | |||
117 | static inline PyObject *_asciitransform(PyObject *str_obj, |
|
117 | static inline PyObject *_asciitransform(PyObject *str_obj, | |
118 |
const char table[128] |
|
118 | const char table[128], | |
|
119 | PyObject *fallback_fn) | |||
119 | { |
|
120 | { | |
120 | char *str, *newstr; |
|
121 | char *str, *newstr; | |
121 | Py_ssize_t i, len; |
|
122 | Py_ssize_t i, len; | |
@@ -134,11 +135,16 b' static inline PyObject *_asciitransform(' | |||||
134 | for (i = 0; i < len; i++) { |
|
135 | for (i = 0; i < len; i++) { | |
135 | char c = str[i]; |
|
136 | char c = str[i]; | |
136 | if (c & 0x80) { |
|
137 | if (c & 0x80) { | |
137 | PyObject *err = PyUnicodeDecodeError_Create( |
|
138 | if (fallback_fn != NULL) { | |
138 | "ascii", str, len, i, (i + 1), |
|
139 | ret = PyObject_CallFunctionObjArgs(fallback_fn, | |
139 | "unexpected code byte"); |
|
140 | str_obj, NULL); | |
140 | PyErr_SetObject(PyExc_UnicodeDecodeError, err); |
|
141 | } else { | |
141 | Py_XDECREF(err); |
|
142 | PyObject *err = PyUnicodeDecodeError_Create( | |
|
143 | "ascii", str, len, i, (i + 1), | |||
|
144 | "unexpected code byte"); | |||
|
145 | PyErr_SetObject(PyExc_UnicodeDecodeError, err); | |||
|
146 | Py_XDECREF(err); | |||
|
147 | } | |||
142 | goto quit; |
|
148 | goto quit; | |
143 | } |
|
149 | } | |
144 | newstr[i] = table[(unsigned char)c]; |
|
150 | newstr[i] = table[(unsigned char)c]; | |
@@ -156,7 +162,7 b' static PyObject *asciilower(PyObject *se' | |||||
156 | PyObject *str_obj; |
|
162 | PyObject *str_obj; | |
157 | if (!PyArg_ParseTuple(args, "O!:asciilower", &PyBytes_Type, &str_obj)) |
|
163 | if (!PyArg_ParseTuple(args, "O!:asciilower", &PyBytes_Type, &str_obj)) | |
158 | return NULL; |
|
164 | return NULL; | |
159 | return _asciitransform(str_obj, lowertable); |
|
165 | return _asciitransform(str_obj, lowertable, NULL); | |
160 | } |
|
166 | } | |
161 |
|
167 | |||
162 | static PyObject *asciiupper(PyObject *self, PyObject *args) |
|
168 | static PyObject *asciiupper(PyObject *self, PyObject *args) | |
@@ -164,7 +170,7 b' static PyObject *asciiupper(PyObject *se' | |||||
164 | PyObject *str_obj; |
|
170 | PyObject *str_obj; | |
165 | if (!PyArg_ParseTuple(args, "O!:asciiupper", &PyBytes_Type, &str_obj)) |
|
171 | if (!PyArg_ParseTuple(args, "O!:asciiupper", &PyBytes_Type, &str_obj)) | |
166 | return NULL; |
|
172 | return NULL; | |
167 | return _asciitransform(str_obj, uppertable); |
|
173 | return _asciitransform(str_obj, uppertable, NULL); | |
168 | } |
|
174 | } | |
169 |
|
175 | |||
170 | /* |
|
176 | /* |
General Comments 0
You need to be logged in to leave comments.
Login now