remove trailing whitespaces
This commit is contained in:
@@ -230,8 +230,8 @@ Py::List PropertyContainerPy::getPropertiesList(void) const
|
||||
}
|
||||
|
||||
|
||||
PyObject* PropertyContainerPy::dumpPropertyContent(PyObject *args, PyObject *kwds) {
|
||||
|
||||
PyObject* PropertyContainerPy::dumpPropertyContent(PyObject *args, PyObject *kwds)
|
||||
{
|
||||
int compression = 3;
|
||||
char* property;
|
||||
static char* kwds_def[] = {"Property", "Compression",NULL};
|
||||
@@ -239,36 +239,37 @@ PyObject* PropertyContainerPy::dumpPropertyContent(PyObject *args, PyObject *kwd
|
||||
if (!PyArg_ParseTupleAndKeywords(args, kwds, "s|i", kwds_def, &property, &compression)) {
|
||||
return NULL;
|
||||
}
|
||||
|
||||
|
||||
Property* prop = getPropertyContainerPtr()->getPropertyByName(property);
|
||||
if (!prop) {
|
||||
PyErr_Format(PyExc_AttributeError, "Property container has no property '%s'", property);
|
||||
return 0;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
//setup the stream. the in flag is needed to make "read" work
|
||||
std::stringstream stream(std::stringstream::out | std::stringstream::in | std::stringstream::binary);
|
||||
try {
|
||||
prop->dumpToStream(stream, compression);
|
||||
prop->dumpToStream(stream, compression);
|
||||
}
|
||||
catch(...) {
|
||||
catch (...) {
|
||||
PyErr_SetString(PyExc_IOError, "Unable parse content into binary representation");
|
||||
return NULL;
|
||||
}
|
||||
|
||||
|
||||
//build the byte array with correct size
|
||||
if(!stream.seekp(0, stream.end)) {
|
||||
if (!stream.seekp(0, stream.end)) {
|
||||
PyErr_SetString(PyExc_IOError, "Unable to find end of stream");
|
||||
return NULL;
|
||||
}
|
||||
}
|
||||
|
||||
std::stringstream::pos_type offset = stream.tellp();
|
||||
if(!stream.seekg(0, stream.beg)) {
|
||||
if (!stream.seekg(0, stream.beg)) {
|
||||
PyErr_SetString(PyExc_IOError, "Unable to find begin of stream");
|
||||
return NULL;
|
||||
}
|
||||
|
||||
|
||||
PyObject* ba = PyByteArray_FromStringAndSize(NULL, offset);
|
||||
|
||||
|
||||
//use the buffer protocol to access the underlying array and write into it
|
||||
Py_buffer buf = Py_buffer();
|
||||
PyObject_GetBuffer(ba, &buf, PyBUF_WRITABLE);
|
||||
@@ -279,48 +280,48 @@ PyObject* PropertyContainerPy::dumpPropertyContent(PyObject *args, PyObject *kwd
|
||||
}
|
||||
PyBuffer_Release(&buf);
|
||||
}
|
||||
catch(...) {
|
||||
catch (...) {
|
||||
PyBuffer_Release(&buf);
|
||||
PyErr_SetString(PyExc_IOError, "Error copying data into byte array");
|
||||
return NULL;
|
||||
}
|
||||
|
||||
return ba;
|
||||
|
||||
return ba;
|
||||
}
|
||||
|
||||
PyObject* PropertyContainerPy::restorePropertyContent(PyObject *args) {
|
||||
|
||||
PyObject* PropertyContainerPy::restorePropertyContent(PyObject *args)
|
||||
{
|
||||
PyObject* buffer;
|
||||
char* property;
|
||||
if( !PyArg_ParseTuple(args, "sO", &property, &buffer) )
|
||||
return NULL;
|
||||
|
||||
|
||||
Property* prop = getPropertyContainerPtr()->getPropertyByName(property);
|
||||
if (!prop) {
|
||||
PyErr_Format(PyExc_AttributeError, "Property container has no property '%s'", property);
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
//check if it really is a buffer
|
||||
if( !PyObject_CheckBuffer(buffer) ) {
|
||||
PyErr_SetString(PyExc_TypeError, "Must be a buffer object");
|
||||
return NULL;
|
||||
}
|
||||
|
||||
|
||||
Py_buffer buf;
|
||||
if(PyObject_GetBuffer(buffer, &buf, PyBUF_SIMPLE) < 0)
|
||||
return NULL;
|
||||
|
||||
|
||||
if(!PyBuffer_IsContiguous(&buf, 'C')) {
|
||||
PyErr_SetString(PyExc_TypeError, "Buffer must be contiguous");
|
||||
return NULL;
|
||||
}
|
||||
|
||||
|
||||
//check if it really is a buffer
|
||||
try {
|
||||
typedef boost::iostreams::basic_array_source<char> Device;
|
||||
boost::iostreams::stream<Device> stream((char*)buf.buf, buf.len);
|
||||
prop->restoreFromStream(stream);
|
||||
prop->restoreFromStream(stream);
|
||||
}
|
||||
catch(...) {
|
||||
PyErr_SetString(PyExc_IOError, "Unable to restore content");
|
||||
|
||||
Reference in New Issue
Block a user