* Helper function to support byte objects as well as unicode strings. * * NOTE: Steals a reference to `str` (although usually returns it unmodified). */
| 43 | * NOTE: Steals a reference to `str` (although usually returns it unmodified). |
| 44 | */ |
| 45 | static inline PyObject * |
| 46 | process_stringlike(PyObject *str, const char *encoding) |
| 47 | { |
| 48 | if (PyBytes_Check(str)) { |
| 49 | PyObject *ustr; |
| 50 | ustr = PyUnicode_FromEncodedObject(str, encoding, NULL); |
| 51 | if (ustr == NULL) { |
| 52 | return NULL; |
| 53 | } |
| 54 | Py_DECREF(str); |
| 55 | return ustr; |
| 56 | } |
| 57 | else if (!PyUnicode_Check(str)) { |
| 58 | PyErr_SetString(PyExc_TypeError, |
| 59 | "non-string returned while reading data"); |
| 60 | Py_DECREF(str); |
| 61 | return NULL; |
| 62 | } |
| 63 | return str; |
| 64 | } |
| 65 | |
| 66 | |
| 67 | static inline void |
no outgoing calls
no test coverage detected