MCPcopy Create free account
hub / github.com/FreeCAD/FreeCAD / restoreContent

Method restoreContent

src/Base/PersistencePyImp.cpp:120–155  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

118}
119
120PyObject* 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
157PyObject* PersistencePy::getCustomAttributes(const char*) const
158{

Callers 5

test11Method · 0.80
test12Method · 0.80
test13Method · 0.80

Calls 1

restoreFromStreamMethod · 0.80

Tested by 4

test11Method · 0.64
test12Method · 0.64
test13Method · 0.64