App: Add support for in-memory Metadata creation
This commit is contained in:
committed by
Chris Hennes
parent
a637937cac
commit
766923a3da
@@ -1,24 +1,24 @@
|
||||
/***************************************************************************
|
||||
* Copyright (c) 2021 Chris Hennes <chennes@pioneerlibrarysystem.org> *
|
||||
* *
|
||||
* This file is part of the FreeCAD CAx development system. *
|
||||
* *
|
||||
* This library is free software; you can redistribute it and/or *
|
||||
* modify it under the terms of the GNU Library General Public *
|
||||
* License as published by the Free Software Foundation; either *
|
||||
* version 2 of the License, or (at your option) any later version. *
|
||||
* *
|
||||
* This library is distributed in the hope that it will be useful, *
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
|
||||
* GNU Library General Public License for more details. *
|
||||
* *
|
||||
* You should have received a copy of the GNU Library General Public *
|
||||
* License along with this library; see the file LICENSE.html. If not, *
|
||||
* write to the Free Software Foundation, Inc., 59 Temple Place, *
|
||||
* Suite 330, Boston, MA 02111-1307, USA *
|
||||
* *
|
||||
***************************************************************************/
|
||||
/**************************************************************************
|
||||
* *
|
||||
* Copyright (c) 2022 FreeCAD Project Association *
|
||||
* *
|
||||
* This file is part of FreeCAD. *
|
||||
* *
|
||||
* FreeCAD is free software: you can redistribute it and/or modify it *
|
||||
* under the terms of the GNU Lesser General Public License as *
|
||||
* published by the Free Software Foundation, either version 2.1 of the *
|
||||
* License, or (at your option) any later version. *
|
||||
* *
|
||||
* FreeCAD is distributed in the hope that it will be useful, but *
|
||||
* WITHOUT ANY WARRANTY; without even the implied warranty of *
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU *
|
||||
* Lesser General Public License for more details. *
|
||||
* *
|
||||
* You should have received a copy of the GNU Lesser General Public *
|
||||
* License along with FreeCAD. If not, see *
|
||||
* <https://www.gnu.org/licenses/>. *
|
||||
* *
|
||||
**************************************************************************/
|
||||
|
||||
#include "PreCompiled.h"
|
||||
|
||||
@@ -63,6 +63,25 @@ int MetadataPy::PyInit(PyObject *args, PyObject * /*kwd*/)
|
||||
return 0;
|
||||
}
|
||||
|
||||
// Data may be passed directly in as a bytes-like object buffer
|
||||
PyErr_Clear();
|
||||
Py_buffer dataBuffer;
|
||||
if (PyArg_ParseTuple(args, "y*", &dataBuffer)) {
|
||||
try {
|
||||
// NB: This is making a copy of the buffer for simplicity, but that shouldn't be
|
||||
// necessary. Use either a string_view or a span to avoid the copy in the future.
|
||||
auto md = new Metadata(
|
||||
std::string(static_cast<const char*>(dataBuffer.buf), dataBuffer.len)
|
||||
);
|
||||
setTwinPointer(md);
|
||||
return 0;
|
||||
}
|
||||
catch (const Base::XMLBaseException&) {
|
||||
// If the XML read failed, this might have been a path to a file, rather than a
|
||||
// bytes-like object. Fall through to the next case.
|
||||
}
|
||||
}
|
||||
|
||||
// Main class constructor -- takes a file path, loads the metadata from it
|
||||
PyErr_Clear();
|
||||
char *filename;
|
||||
|
||||
Reference in New Issue
Block a user