Path: remove some more deprecated Py2 code
This commit is contained in:
@@ -96,13 +96,9 @@ static PyObject * areaGetParamsDesc(PyObject *, PyObject *args, PyObject *kwd) {
|
||||
if (!PyArg_ParseTupleAndKeywords(args, kwd, "|O",kwlist,&pcObj))
|
||||
return 0;
|
||||
|
||||
#if PY_MAJOR_VERSION < 3
|
||||
if(PyObject_IsTrue(pcObj))
|
||||
return PyString_FromString(PARAM_PY_DOC(NAME,AREA_PARAMS_STATIC_CONF));
|
||||
#else
|
||||
if(PyObject_IsTrue(pcObj))
|
||||
return PyUnicode_FromString(PARAM_PY_DOC(NAME,AREA_PARAMS_STATIC_CONF));
|
||||
#endif
|
||||
|
||||
PyObject *dict = PyDict_New();
|
||||
PARAM_PY_DICT_SET_DOC(dict,NAME,AREA_PARAMS_STATIC_CONF)
|
||||
return dict;
|
||||
|
||||
@@ -90,13 +90,8 @@ int CommandPy::PyInit(PyObject* args, PyObject* kwd)
|
||||
Py_ssize_t pos = 0;
|
||||
while (parameters && PyDict_Next(parameters, &pos, &key, &value)) {
|
||||
std::string ckey;
|
||||
#if PY_MAJOR_VERSION >= 3
|
||||
if (PyUnicode_Check(key)) {
|
||||
ckey = PyUnicode_AsUTF8(key);
|
||||
#else
|
||||
if (PyString_Check(key)) {
|
||||
ckey = PyString_AsString(key);
|
||||
#endif
|
||||
}
|
||||
else {
|
||||
PyErr_SetString(PyExc_TypeError, "The dictionary can only contain string keys");
|
||||
@@ -105,13 +100,8 @@ int CommandPy::PyInit(PyObject* args, PyObject* kwd)
|
||||
|
||||
boost::to_upper(ckey);
|
||||
double cvalue;
|
||||
#if PY_MAJOR_VERSION >= 3
|
||||
if (PyObject_TypeCheck(value,&(PyLong_Type))) {
|
||||
cvalue = (double)PyLong_AsLong(value);
|
||||
#else
|
||||
if (PyObject_TypeCheck(value,&(PyInt_Type))) {
|
||||
cvalue = (double)PyInt_AsLong(value);
|
||||
#endif
|
||||
}
|
||||
else if (PyObject_TypeCheck(value, &(PyFloat_Type))) {
|
||||
cvalue = PyFloat_AsDouble(value);
|
||||
@@ -179,13 +169,8 @@ void CommandPy::setParameters(Py::Dict arg)
|
||||
Py_ssize_t pos = 0;
|
||||
while (PyDict_Next(dict_copy, &pos, &key, &value)) {
|
||||
std::string ckey;
|
||||
#if PY_MAJOR_VERSION >= 3
|
||||
if (PyUnicode_Check(key)) {
|
||||
ckey = PyUnicode_AsUTF8(key);
|
||||
#else
|
||||
if (PyString_Check(key)) {
|
||||
ckey = PyString_AsString(key);
|
||||
#endif
|
||||
}
|
||||
else {
|
||||
throw Py::TypeError("The dictionary can only contain string keys");
|
||||
@@ -193,13 +178,8 @@ void CommandPy::setParameters(Py::Dict arg)
|
||||
|
||||
boost::to_upper(ckey);
|
||||
double cvalue;
|
||||
#if PY_MAJOR_VERSION >= 3
|
||||
if (PyObject_TypeCheck(value,&(PyLong_Type))) {
|
||||
cvalue = (double)PyLong_AsLong(value);
|
||||
#else
|
||||
if (PyObject_TypeCheck(value,&(PyInt_Type))) {
|
||||
cvalue = (double)PyInt_AsLong(value);
|
||||
#endif
|
||||
}
|
||||
else if (PyObject_TypeCheck(value, &(PyFloat_Type))) {
|
||||
cvalue = PyFloat_AsDouble(value);
|
||||
@@ -217,11 +197,7 @@ void CommandPy::setParameters(Py::Dict arg)
|
||||
PyObject* CommandPy::toGCode(PyObject *args)
|
||||
{
|
||||
if (PyArg_ParseTuple(args, "")) {
|
||||
#if PY_MAJOR_VERSION >= 3
|
||||
return PyUnicode_FromString(getCommandPtr()->toGCode().c_str());
|
||||
#else
|
||||
return PyString_FromString(getCommandPtr()->toGCode().c_str());
|
||||
#endif
|
||||
}
|
||||
throw Py::TypeError("This method accepts no argument");
|
||||
}
|
||||
@@ -301,13 +277,8 @@ int CommandPy::setCustomAttributes(const char* attr, PyObject* obj)
|
||||
if (isalpha(satt[0])) {
|
||||
boost::to_upper(satt);
|
||||
double cvalue;
|
||||
#if PY_MAJOR_VERSION >= 3
|
||||
if (PyObject_TypeCheck(obj,&(PyLong_Type))) {
|
||||
cvalue = (double)PyLong_AsLong(obj);
|
||||
#else
|
||||
if (PyObject_TypeCheck(obj,&(PyInt_Type))) {
|
||||
cvalue = (double)PyInt_AsLong(obj);
|
||||
#endif
|
||||
} else if (PyObject_TypeCheck(obj,&(PyFloat_Type))) {
|
||||
cvalue = PyFloat_AsDouble(obj);
|
||||
} else {
|
||||
|
||||
@@ -860,13 +860,8 @@
|
||||
#define PARAM_REF(_src,_seq) \
|
||||
BOOST_PP_SEQ_FOR_EACH_I(PARAM_REF_,_src,_seq)
|
||||
|
||||
#if PY_MAJOR_VERSION < 3
|
||||
#define PARAM_CAST_PYOBJ_short(_v) PyInt_FromLong(_v)
|
||||
#define PARAM_CAST_PYOBJ_long(_v) PyInt_FromLong(_v)
|
||||
#else
|
||||
#define PARAM_CAST_PYOBJ_short(_v) PyLong_FromLong(_v)
|
||||
#define PARAM_CAST_PYOBJ_long(_v) PyLong_FromLong(_v)
|
||||
#endif
|
||||
#define PARAM_CAST_PYOBJ_short(_v) PyLong_FromLong(_v)
|
||||
#define PARAM_CAST_PYOBJ_long(_v) PyLong_FromLong(_v)
|
||||
|
||||
#define PARAM_CAST_PYOBJ_double(_v) PyFloat_FromDouble(_v)
|
||||
#define PARAM_CAST_PYOBJ_bool(_v) ((_v)?Py_True:Py_False)
|
||||
@@ -877,13 +872,9 @@
|
||||
/** Stringize field to a Python string
|
||||
* \ingroup ParamPy ParamStringizer
|
||||
*/
|
||||
#if PY_MAJOR_VERSION < 3
|
||||
#define PARAM_PY_STR(_field,_param) \
|
||||
PyString_FromString(PARAM_FIELD_STR(_field,_param))
|
||||
#else
|
||||
#define PARAM_PY_STR(_field,_param) \
|
||||
PyUnicode_FromString(PARAM_FIELD_STR(_field,_param))
|
||||
#endif
|
||||
|
||||
/** Helper for #PARAM_PY_DICT_SET_VALUE */
|
||||
#define PARAM_PY_DICT_SET_VALUE_(_1,_args,_param) \
|
||||
PyDict_SetItem(BOOST_PP_TUPLE_ELEM(0,_args), \
|
||||
@@ -931,17 +922,10 @@
|
||||
#define PARAM_PY_DICT_DOC_enum2 PARAM_PY_DICT_DOC_enum
|
||||
|
||||
/** Helper for #PARAM_PY_DICT_SET_DOC */
|
||||
#if PY_MAJOR_VERSION < 3
|
||||
#define PARAM_PY_DICT_SET_DOC_(_1,_args,_param) \
|
||||
PyDict_SetItem(BOOST_PP_TUPLE_ELEM(0,_args), \
|
||||
PARAM_PY_STR(BOOST_PP_TUPLE_ELEM(1,_args),_param),\
|
||||
PyString_FromString(PARAM_TYPED(PARAM_PY_DICT_DOC_,_param)(_param)));
|
||||
#else
|
||||
#define PARAM_PY_DICT_SET_DOC_(_1,_args,_param) \
|
||||
PyDict_SetItem(BOOST_PP_TUPLE_ELEM(0,_args), \
|
||||
PARAM_PY_STR(BOOST_PP_TUPLE_ELEM(1,_args),_param),\
|
||||
PyUnicode_FromString(PARAM_TYPED(PARAM_PY_DICT_DOC_,_param)(_param)));
|
||||
#endif
|
||||
|
||||
/** Populate a Python dict with the doc field of the parameter sequence
|
||||
*
|
||||
|
||||
@@ -204,11 +204,7 @@ PyObject* PathPy::toGCode(PyObject * args)
|
||||
{
|
||||
if (PyArg_ParseTuple(args, "")) {
|
||||
std::string result = getToolpathPtr()->toGCode();
|
||||
#if PY_MAJOR_VERSION >= 3
|
||||
return PyUnicode_FromString(result.c_str());
|
||||
#else
|
||||
return PyString_FromString(result.c_str());
|
||||
#endif
|
||||
}
|
||||
throw Py::TypeError("This method accepts no argument");
|
||||
}
|
||||
|
||||
@@ -32,17 +32,10 @@
|
||||
|
||||
using namespace Path;
|
||||
|
||||
#if PY_MAJOR_VERSION >= 3
|
||||
# define PYSTRING_FROMSTRING(str) PyUnicode_FromString(str)
|
||||
# define PYINT_TYPE PyLong_Type
|
||||
# define PYINT_FROMLONG(l) PyLong_FromLong(l)
|
||||
# define PYINT_ASLONG(o) PyLong_AsLong(o)
|
||||
#else
|
||||
# define PYSTRING_FROMSTRING(str) PyString_FromString(str)
|
||||
# define PYINT_TYPE PyInt_Type
|
||||
# define PYINT_FROMLONG(l) PyInt_FromLong(l)
|
||||
# define PYINT_ASLONG(o) PyInt_AsLong(o)
|
||||
#endif
|
||||
#define PYSTRING_FROMSTRING(str) PyUnicode_FromString(str)
|
||||
#define PYINT_TYPE PyLong_Type
|
||||
#define PYINT_FROMLONG(l) PyLong_FromLong(l)
|
||||
#define PYINT_ASLONG(o) PyLong_AsLong(o)
|
||||
|
||||
|
||||
// returns a string which represents the object e.g. when printed in python
|
||||
|
||||
@@ -33,17 +33,10 @@
|
||||
|
||||
using namespace Path;
|
||||
|
||||
#if PY_MAJOR_VERSION >= 3
|
||||
# define PYSTRING_FROMSTRING(str) PyUnicode_FromString(str)
|
||||
# define PYINT_TYPE PyLong_Type
|
||||
# define PYINT_FROMLONG(l) PyLong_FromLong(l)
|
||||
# define PYINT_ASLONG(o) PyLong_AsLong(o)
|
||||
#else
|
||||
# define PYSTRING_FROMSTRING(str) PyString_FromString(str)
|
||||
# define PYINT_TYPE PyInt_Type
|
||||
# define PYINT_FROMLONG(l) PyInt_FromLong(l)
|
||||
# define PYINT_ASLONG(o) PyInt_AsLong(o)
|
||||
#endif
|
||||
#define PYSTRING_FROMSTRING(str) PyUnicode_FromString(str)
|
||||
#define PYINT_TYPE PyLong_Type
|
||||
#define PYINT_FROMLONG(l) PyLong_FromLong(l)
|
||||
#define PYINT_ASLONG(o) PyLong_AsLong(o)
|
||||
|
||||
// returns a string which represents the object e.g. when printed in python
|
||||
std::string TooltablePy::representation(void) const
|
||||
|
||||
Reference in New Issue
Block a user