##// END OF EJS Templates
parsers._asciitransform: also accept a fallback function...
Siddharth Agarwal -
r24606:e4a733c3 default
parent child Browse files
Show More
@@ -115,7 +115,8 b' PyObject *unhexlify(const char *str, int'
115 115 }
116 116
117 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 121 char *str, *newstr;
121 122 Py_ssize_t i, len;
@@ -134,11 +135,16 b' static inline PyObject *_asciitransform('
134 135 for (i = 0; i < len; i++) {
135 136 char c = str[i];
136 137 if (c & 0x80) {
137 PyObject *err = PyUnicodeDecodeError_Create(
138 "ascii", str, len, i, (i + 1),
139 "unexpected code byte");
140 PyErr_SetObject(PyExc_UnicodeDecodeError, err);
141 Py_XDECREF(err);
138 if (fallback_fn != NULL) {
139 ret = PyObject_CallFunctionObjArgs(fallback_fn,
140 str_obj, NULL);
141 } else {
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 148 goto quit;
143 149 }
144 150 newstr[i] = table[(unsigned char)c];
@@ -156,7 +162,7 b' static PyObject *asciilower(PyObject *se'
156 162 PyObject *str_obj;
157 163 if (!PyArg_ParseTuple(args, "O!:asciilower", &PyBytes_Type, &str_obj))
158 164 return NULL;
159 return _asciitransform(str_obj, lowertable);
165 return _asciitransform(str_obj, lowertable, NULL);
160 166 }
161 167
162 168 static PyObject *asciiupper(PyObject *self, PyObject *args)
@@ -164,7 +170,7 b' static PyObject *asciiupper(PyObject *se'
164 170 PyObject *str_obj;
165 171 if (!PyArg_ParseTuple(args, "O!:asciiupper", &PyBytes_Type, &str_obj))
166 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