| 118 | } |
| 119 | |
| 120 | PyObject* PersistencePy::restoreContent(PyObject* args) |
| 121 | { |
| 122 | PyObject* buffer = nullptr; |
| 123 | if (!PyArg_ParseTuple(args, "O", &buffer)) { |
| 124 | return nullptr; |
| 125 | } |
| 126 | |
| 127 | // check if it really is a buffer |
| 128 | if (!PyObject_CheckBuffer(buffer)) { |
| 129 | PyErr_SetString(PyExc_TypeError, "Must be a buffer object"); |
| 130 | return nullptr; |
| 131 | } |
| 132 | |
| 133 | Py_buffer buf; |
| 134 | if (PyObject_GetBuffer(buffer, &buf, PyBUF_SIMPLE) < 0) { |
| 135 | return nullptr; |
| 136 | } |
| 137 | |
| 138 | if (!PyBuffer_IsContiguous(&buf, 'C')) { |
| 139 | PyErr_SetString(PyExc_TypeError, "Buffer must be contiguous"); |
| 140 | return nullptr; |
| 141 | } |
| 142 | |
| 143 | // check if it really is a buffer |
| 144 | try { |
| 145 | using Device = boost::iostreams::basic_array_source<char>; |
| 146 | boost::iostreams::stream<Device> stream((char*)buf.buf, buf.len); |
| 147 | getPersistencePtr()->restoreFromStream(stream); |
| 148 | } |
| 149 | catch (...) { |
| 150 | PyErr_SetString(PyExc_IOError, "Unable to restore content"); |
| 151 | return nullptr; |
| 152 | } |
| 153 | |
| 154 | Py_Return; |
| 155 | } |
| 156 | |
| 157 | PyObject* PersistencePy::getCustomAttributes(const char*) const |
| 158 | { |