| 111 | } |
| 112 | |
| 113 | std::string PyObject_StdStringRepr(PyObject* obj) { |
| 114 | OwnedRef unicode_ref(PyObject_Repr(obj)); |
| 115 | OwnedRef bytes_ref; |
| 116 | |
| 117 | if (unicode_ref) { |
| 118 | bytes_ref.reset( |
| 119 | PyUnicode_AsEncodedString(unicode_ref.obj(), "utf8", "backslashreplace")); |
| 120 | } |
| 121 | if (!bytes_ref) { |
| 122 | PyErr_Clear(); |
| 123 | std::stringstream ss; |
| 124 | ss << "<object of type '" << Py_TYPE(obj)->tp_name << "' repr() failed>"; |
| 125 | return ss.str(); |
| 126 | } |
| 127 | return PyBytes_AsStdString(bytes_ref.obj()); |
| 128 | } |
| 129 | |
| 130 | Status PyObject_StdStringStr(PyObject* obj, std::string* out) { |
| 131 | OwnedRef string_ref(PyObject_Str(obj)); |
no test coverage detected