App: Wrap PyArg_ParseTupleAndKeywords
This commit is contained in:
@@ -29,6 +29,7 @@
|
||||
#include <Base/FileInfo.h>
|
||||
#include <Base/Interpreter.h>
|
||||
#include <Base/Parameter.h>
|
||||
#include <Base/PyWrapParseTupleAndKeywords.h>
|
||||
#include <Base/Sequencer.h>
|
||||
|
||||
#include "Application.h"
|
||||
@@ -250,10 +251,11 @@ PyObject* Application::sOpenDocument(PyObject * /*self*/, PyObject *args, PyObje
|
||||
{
|
||||
char* Name;
|
||||
PyObject *hidden = Py_False;
|
||||
static char *kwlist[] = {"name", "hidden", nullptr};
|
||||
if (!PyArg_ParseTupleAndKeywords(args, kwd, "et|O!", kwlist,
|
||||
"utf-8", &Name, &PyBool_Type, &hidden))
|
||||
static const std::array<const char *, 3> kwlist {"name", "hidden", nullptr};
|
||||
if (!Base::Wrapped_ParseTupleAndKeywords(args, kwd, "et|O!", kwlist,
|
||||
"utf-8", &Name, &PyBool_Type, &hidden)) {
|
||||
return nullptr;
|
||||
}
|
||||
std::string EncodedName = std::string(Name);
|
||||
PyMem_Free(Name);
|
||||
try {
|
||||
@@ -277,10 +279,11 @@ PyObject* Application::sNewDocument(PyObject * /*self*/, PyObject *args, PyObjec
|
||||
char *usrName = nullptr;
|
||||
PyObject *hidden = Py_False;
|
||||
PyObject *temp = Py_False;
|
||||
static char *kwlist[] = {"name", "label", "hidden", "temp", nullptr};
|
||||
if (!PyArg_ParseTupleAndKeywords(args, kwd, "|etetO!O!", kwlist,
|
||||
"utf-8", &docName, "utf-8", &usrName, &PyBool_Type, &hidden, &PyBool_Type, &temp))
|
||||
static const std::array<const char *, 5> kwlist {"name", "label", "hidden", "temp", nullptr};
|
||||
if (!Base::Wrapped_ParseTupleAndKeywords(args, kwd, "|etetO!O!", kwlist,
|
||||
"utf-8", &docName, "utf-8", &usrName, &PyBool_Type, &hidden, &PyBool_Type, &temp)) {
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
PY_TRY {
|
||||
App::Document* doc = GetApplication().newDocument(docName, usrName, !Base::asBoolean(hidden), Base::asBoolean(temp));
|
||||
|
||||
@@ -24,6 +24,7 @@
|
||||
|
||||
#include <Base/GeometryPyCXX.h>
|
||||
#include <Base/MatrixPy.h>
|
||||
#include <Base/PyWrapParseTupleAndKeywords.h>
|
||||
|
||||
#include "DocumentObject.h"
|
||||
#include "Document.h"
|
||||
@@ -432,12 +433,13 @@ PyObject* DocumentObjectPy::getSubObject(PyObject *args, PyObject *keywds)
|
||||
PyObject *doTransform = Py_True;
|
||||
short depth = 0;
|
||||
|
||||
static char *kwlist[] = {"subname", "retType", "matrix", "transform", "depth", nullptr};
|
||||
if (!PyArg_ParseTupleAndKeywords(args, keywds, "O|hO!O!h", kwlist,
|
||||
&obj, &retType, &Base::MatrixPy::Type, &pyMat, &PyBool_Type, &doTransform, &depth))
|
||||
static const std::array<const char *, 6> kwlist {"subname", "retType", "matrix", "transform", "depth", nullptr};
|
||||
if (!Base::Wrapped_ParseTupleAndKeywords(args, keywds, "O|hO!O!h", kwlist, &obj, &retType, &Base::MatrixPy::Type,
|
||||
&pyMat, &PyBool_Type, &doTransform, &depth)) {
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
if (retType < 0 || retType > 6) {
|
||||
if (retType < 0 || static_cast<size_t> (retType) > kwlist.size()) {
|
||||
PyErr_SetString(PyExc_ValueError, "invalid retType, can only be integer 0~6");
|
||||
return nullptr;
|
||||
}
|
||||
@@ -576,10 +578,11 @@ PyObject* DocumentObjectPy::getLinkedObject(PyObject *args, PyObject *keywds)
|
||||
PyObject *pyMat = Py_None;
|
||||
PyObject *transform = Py_True;
|
||||
short depth = 0;
|
||||
static char *kwlist[] = {"recursive","matrix","transform","depth", nullptr};
|
||||
if (!PyArg_ParseTupleAndKeywords(args, keywds, "|O!OO!h", kwlist,
|
||||
&PyBool_Type,&recursive,&pyMat,&PyBool_Type,&transform,&depth))
|
||||
static const std::array<const char *, 5> kwlist {"recursive","matrix","transform","depth", nullptr};
|
||||
if (!Base::Wrapped_ParseTupleAndKeywords(args, keywds, "|O!OO!h", kwlist,
|
||||
&PyBool_Type, &recursive, &pyMat, &PyBool_Type, &transform, &depth)) {
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
PY_TRY {
|
||||
Base::PyTypeCheck(&pyMat, &Base::MatrixPy::Type, "expect argument 'matrix' to be of type Base.Matrix");
|
||||
|
||||
@@ -36,6 +36,7 @@
|
||||
#include "DocumentPy.h"
|
||||
#include "DocumentPy.cpp"
|
||||
#include <boost/regex.hpp>
|
||||
#include <Base/PyWrapParseTupleAndKeywords.h>
|
||||
|
||||
using namespace App;
|
||||
|
||||
@@ -254,14 +255,16 @@ PyObject* DocumentPy::exportGraphviz(PyObject * args)
|
||||
|
||||
PyObject* DocumentPy::addObject(PyObject *args, PyObject *kwd)
|
||||
{
|
||||
char *sType,*sName=nullptr,*sViewType=nullptr;
|
||||
PyObject* obj=nullptr;
|
||||
PyObject* view=nullptr;
|
||||
PyObject *attach=Py_False;
|
||||
static char *kwlist[] = {"type","name","objProxy","viewProxy","attach","viewType",nullptr};
|
||||
if (!PyArg_ParseTupleAndKeywords(args,kwd,"s|sOOO!s",
|
||||
kwlist, &sType,&sName,&obj,&view,&PyBool_Type,&attach,&sViewType))
|
||||
char *sType, *sName = nullptr, *sViewType = nullptr;
|
||||
PyObject *obj = nullptr;
|
||||
PyObject *view = nullptr;
|
||||
PyObject *attach = Py_False;
|
||||
static const std::array<const char *, 7> kwlist{"type", "name", "objProxy", "viewProxy", "attach", "viewType",
|
||||
nullptr};
|
||||
if (!Base::Wrapped_ParseTupleAndKeywords(args, kwd, "s|sOOO!s",
|
||||
kwlist, &sType, &sName, &obj, &view, &PyBool_Type, &attach, &sViewType)) {
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
DocumentObject *pcFtr = nullptr;
|
||||
|
||||
@@ -658,10 +661,10 @@ PyObject* DocumentPy::getObjectsByLabel(PyObject *args)
|
||||
PyObject* DocumentPy::findObjects(PyObject *args, PyObject *kwds)
|
||||
{
|
||||
const char *sType = "App::DocumentObject", *sName = nullptr, *sLabel = nullptr;
|
||||
static char *kwlist[] = {"Type", "Name", "Label", nullptr};
|
||||
if (!PyArg_ParseTupleAndKeywords(args, kwds, "|sss",
|
||||
kwlist, &sType, &sName, &sLabel))
|
||||
static const std::array<const char *, 4> kwlist{"Type", "Name", "Label", nullptr};
|
||||
if (!Base::Wrapped_ParseTupleAndKeywords(args, kwds, "|sss", kwlist, &sType, &sName, &sLabel)) {
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
Base::Type type = Base::Type::getTypeIfDerivedFrom(sType, App::DocumentObject::getClassTypeId(), true);
|
||||
if (type.isBad()) {
|
||||
|
||||
@@ -26,6 +26,7 @@
|
||||
// inclusion of the generated files (generated out of MaterialPy.xml)
|
||||
#include "MaterialPy.h"
|
||||
#include "MaterialPy.cpp"
|
||||
#include <Base/PyWrapParseTupleAndKeywords.h>
|
||||
|
||||
using namespace App;
|
||||
|
||||
@@ -44,11 +45,13 @@ int MaterialPy::PyInit(PyObject* args, PyObject* kwds)
|
||||
PyObject* emissive = nullptr;
|
||||
PyObject* shininess = nullptr;
|
||||
PyObject* transparency = nullptr;
|
||||
static char* kwds_colors[] = { "DiffuseColor", "AmbientColor", "SpecularColor", "EmissiveColor", "Shininess", "Transparency", nullptr };
|
||||
static const std::array<const char *, 7> kwds_colors{"DiffuseColor", "AmbientColor", "SpecularColor",
|
||||
"EmissiveColor", "Shininess", "Transparency", nullptr};
|
||||
|
||||
if (!PyArg_ParseTupleAndKeywords(args, kwds, "|OOOOOO", kwds_colors,
|
||||
&diffuse, &ambient, &specular, &emissive, &shininess, &transparency))
|
||||
if (!Base::Wrapped_ParseTupleAndKeywords(args, kwds, "|OOOOOO", kwds_colors,
|
||||
&diffuse, &ambient, &specular, &emissive, &shininess, &transparency)) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
if (diffuse) {
|
||||
setDiffuseColor(Py::Tuple(diffuse));
|
||||
|
||||
@@ -30,6 +30,7 @@
|
||||
#include "PropertyContainer.h"
|
||||
#include "Property.h"
|
||||
#include "DocumentObject.h"
|
||||
#include <Base/PyWrapParseTupleAndKeywords.h>
|
||||
|
||||
#include <boost/iostreams/device/array.hpp>
|
||||
#include <boost/iostreams/stream.hpp>
|
||||
@@ -466,10 +467,11 @@ PyObject* PropertyContainerPy::dumpPropertyContent(PyObject *args, PyObject *kwd
|
||||
{
|
||||
int compression = 3;
|
||||
const char* property;
|
||||
static char* kwds_def[] = {"Property", "Compression", nullptr};
|
||||
static const std::array<const char *, 3> kwds_def {"Property", "Compression", nullptr};
|
||||
PyErr_Clear();
|
||||
if (!PyArg_ParseTupleAndKeywords(args, kwds, "s|i", kwds_def, &property, &compression))
|
||||
if (!Base::Wrapped_ParseTupleAndKeywords(args, kwds, "s|i", kwds_def, &property, &compression)) {
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
Property* prop = getPropertyContainerPtr()->getPropertyByName(property);
|
||||
if (!prop) {
|
||||
|
||||
@@ -26,6 +26,7 @@
|
||||
|
||||
#include "StringHasherPy.h"
|
||||
#include "StringHasherPy.cpp"
|
||||
#include <Base/PyWrapParseTupleAndKeywords.h>
|
||||
|
||||
using namespace App;
|
||||
|
||||
@@ -45,8 +46,8 @@ PyObject *StringHasherPy::PyMake(struct _typeobject *, PyObject *, PyObject *)
|
||||
// constructor method
|
||||
int StringHasherPy::PyInit(PyObject* args, PyObject* kwds)
|
||||
{
|
||||
char* kw[] = {nullptr};
|
||||
if (!PyArg_ParseTupleAndKeywords(args, kwds, "", kw)) {
|
||||
static const std::array<const char *, 1> kwlist {nullptr};
|
||||
if (!Base::Wrapped_ParseTupleAndKeywords(args, kwds, "", kwlist)) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user