TD: Wrap PyArg_ParseTupleAndKeywords

This commit is contained in:
Chris Hennes
2023-08-25 13:19:09 -05:00
parent 079617a58e
commit c60944ed62
3 changed files with 15 additions and 9 deletions

View File

@@ -40,6 +40,7 @@
#include <App/DocumentObjectPy.h>
#include <Base/Console.h>
#include <Base/Exception.h>
#include <Base/PyWrapParseTupleAndKeywords.h>
#include <Base/Vector3D.h>
#include <Base/VectorPy.h>
#include <Mod/Import/App/dxf/ImpExpDxf.h>
@@ -1093,7 +1094,9 @@ private:
Py::Object projectToSVG(const Py::Tuple& args, const Py::Dict& keys)
{
static char* argNames[] = {"topoShape", "direction", "type", "tolerance", "vStyle", "v0Style", "v1Style", "hStyle", "h0Style", "h1Style", nullptr};
static const std::array<const char *, 11> argNames{"topoShape", "direction", "type", "tolerance", "vStyle",
"v0Style", "v1Style", "hStyle", "h0Style", "h1Style",
nullptr};
PyObject *pcObjShape = nullptr;
PyObject *pcObjDir = nullptr;
const char *extractionTypePy = nullptr;
@@ -1114,7 +1117,7 @@ private:
// Get the arguments
if (!PyArg_ParseTupleAndKeywords(
if (!Base::Wrapped_ParseTupleAndKeywords(
args.ptr(), keys.ptr(),
"O!|O!sfOOOOOO",
argNames,
@@ -1122,9 +1125,9 @@ private:
&(Base::VectorPy::Type), &pcObjDir,
&extractionTypePy, &tol,
&vStylePy, &v0StylePy, &v1StylePy,
&hStylePy, &h0StylePy, &h1StylePy))
&hStylePy, &h0StylePy, &h1StylePy)) {
throw Py::Exception();
}
// Convert all arguments into the right format

View File

@@ -26,6 +26,7 @@
#endif
#include <Base/Console.h>
#include <Base/PyWrapParseTupleAndKeywords.h>
#include "CenterLinePy.h"
#include "DrawUtil.h"
@@ -130,8 +131,8 @@ void CenterLinePy::setFormat(Py::Dict arg)
double weight = 0.5;
PyObject* pColor = color.ptr();
PyObject* visible = Py_True;
static char* kw[] = {"style", "weight", "color", "visible", nullptr};
if (!PyArg_ParseTupleAndKeywords(dummy.ptr(), arg.ptr(), "|idO!O!", kw,
static const std::array<const char *, 5> kw{"style", "weight", "color", "visible", nullptr};
if (!Base::Wrapped_ParseTupleAndKeywords(dummy.ptr(), arg.ptr(), "|idO!O!", kw,
&style, &weight, &PyTuple_Type, &pColor, &PyBool_Type, &visible)) {
throw Py::ValueError("Expected {'style':int, 'weight':float, 'color':tuple, 'visible':bool} dict");
}

View File

@@ -27,6 +27,8 @@
# include <boost/uuid/uuid_io.hpp>
#endif
#include <Base/PyWrapParseTupleAndKeywords.h>
#include "CosmeticEdgePy.h"
#include "CosmeticEdgePy.cpp"
#include "Cosmetic.h"
@@ -122,9 +124,9 @@ void CosmeticEdgePy::setFormat(Py::Dict arg)
double weight = 0.5;
PyObject* pColor = color.ptr();
PyObject* visible = Py_True;
static char* kw[] = {"style", "weight", "color", "visible", nullptr};
if (!PyArg_ParseTupleAndKeywords(dummy.ptr(), arg.ptr(), "|idO!O!", kw,
&style, &weight, &PyTuple_Type, &pColor, &PyBool_Type, &visible)) {
static const std::array<const char *, 5> kw{"style", "weight", "color", "visible", nullptr};
if (!Base::Wrapped_ParseTupleAndKeywords(dummy.ptr(), arg.ptr(), "|idO!O!", kw,
&style, &weight, &PyTuple_Type, &pColor, &PyBool_Type, &visible)) {
throw Py::ValueError("Expected {'style':int, 'weight':float, 'color':tuple, 'visible':bool} dict");
}