Base: remove Py2 code
This commit is contained in:
@@ -480,7 +480,6 @@ PyObject *ConsoleSingleton::sPyMessage(PyObject * /*self*/, PyObject *args)
|
||||
if (!PyArg_ParseTuple(args, "O", &output))
|
||||
return NULL;
|
||||
|
||||
#if PY_MAJOR_VERSION >= 3
|
||||
const char* string=0;
|
||||
PyObject* unicode=0;
|
||||
if (PyUnicode_Check(output)) {
|
||||
@@ -491,23 +490,6 @@ PyObject *ConsoleSingleton::sPyMessage(PyObject * /*self*/, PyObject *args)
|
||||
if (unicode)
|
||||
string = PyUnicode_AsUTF8(unicode);
|
||||
}
|
||||
#else
|
||||
const char* string=0;
|
||||
PyObject* unicode=0;
|
||||
if (PyUnicode_Check(output)) {
|
||||
unicode = PyUnicode_AsEncodedObject(output, "utf-8", "strict");
|
||||
if (unicode)
|
||||
string = PyString_AsString(unicode);
|
||||
}
|
||||
else if (PyString_Check(output)) {
|
||||
string = PyString_AsString(output);
|
||||
}
|
||||
else {
|
||||
unicode = PyObject_Str(output);
|
||||
if (unicode)
|
||||
string = PyString_AsString(unicode);
|
||||
}
|
||||
#endif
|
||||
|
||||
PY_TRY {
|
||||
if (string)
|
||||
@@ -526,7 +508,6 @@ PyObject *ConsoleSingleton::sPyWarning(PyObject * /*self*/, PyObject *args)
|
||||
if (!PyArg_ParseTuple(args, "O", &output))
|
||||
return NULL;
|
||||
|
||||
#if PY_MAJOR_VERSION >= 3
|
||||
const char* string=0;
|
||||
PyObject* unicode=0;
|
||||
if (PyUnicode_Check(output)) {
|
||||
@@ -537,23 +518,6 @@ PyObject *ConsoleSingleton::sPyWarning(PyObject * /*self*/, PyObject *args)
|
||||
if (unicode)
|
||||
string = PyUnicode_AsUTF8(unicode);
|
||||
}
|
||||
#else
|
||||
const char* string=0;
|
||||
PyObject* unicode=0;
|
||||
if (PyUnicode_Check(output)) {
|
||||
unicode = PyUnicode_AsEncodedObject(output, "utf-8", "strict");
|
||||
if (unicode)
|
||||
string = PyString_AsString(unicode);
|
||||
}
|
||||
else if (PyString_Check(output)) {
|
||||
string = PyString_AsString(output);
|
||||
}
|
||||
else {
|
||||
unicode = PyObject_Str(output);
|
||||
if (unicode)
|
||||
string = PyString_AsString(unicode);
|
||||
}
|
||||
#endif
|
||||
|
||||
PY_TRY {
|
||||
if (string)
|
||||
@@ -572,7 +536,6 @@ PyObject *ConsoleSingleton::sPyError(PyObject * /*self*/, PyObject *args)
|
||||
if (!PyArg_ParseTuple(args, "O", &output))
|
||||
return NULL;
|
||||
|
||||
#if PY_MAJOR_VERSION >= 3
|
||||
const char* string=0;
|
||||
PyObject* unicode=0;
|
||||
if (PyUnicode_Check(output)) {
|
||||
@@ -583,23 +546,6 @@ PyObject *ConsoleSingleton::sPyError(PyObject * /*self*/, PyObject *args)
|
||||
if (unicode)
|
||||
string = PyUnicode_AsUTF8(unicode);
|
||||
}
|
||||
#else
|
||||
const char* string=0;
|
||||
PyObject* unicode=0;
|
||||
if (PyUnicode_Check(output)) {
|
||||
unicode = PyUnicode_AsEncodedObject(output, "utf-8", "strict");
|
||||
if (unicode)
|
||||
string = PyString_AsString(unicode);
|
||||
}
|
||||
else if (PyString_Check(output)) {
|
||||
string = PyString_AsString(output);
|
||||
}
|
||||
else {
|
||||
unicode = PyObject_Str(output);
|
||||
if (unicode)
|
||||
string = PyString_AsString(unicode);
|
||||
}
|
||||
#endif
|
||||
|
||||
PY_TRY {
|
||||
if (string)
|
||||
@@ -618,7 +564,6 @@ PyObject *ConsoleSingleton::sPyLog(PyObject * /*self*/, PyObject *args)
|
||||
if (!PyArg_ParseTuple(args, "O", &output))
|
||||
return NULL;
|
||||
|
||||
#if PY_MAJOR_VERSION >= 3
|
||||
const char* string=0;
|
||||
PyObject* unicode=0;
|
||||
if (PyUnicode_Check(output)) {
|
||||
@@ -629,23 +574,6 @@ PyObject *ConsoleSingleton::sPyLog(PyObject * /*self*/, PyObject *args)
|
||||
if (unicode)
|
||||
string = PyUnicode_AsUTF8(unicode);
|
||||
}
|
||||
#else
|
||||
const char* string=0;
|
||||
PyObject* unicode=0;
|
||||
if (PyUnicode_Check(output)) {
|
||||
unicode = PyUnicode_AsEncodedObject(output, "utf-8", "strict");
|
||||
if (unicode)
|
||||
string = PyString_AsString(unicode);
|
||||
}
|
||||
else if (PyString_Check(output)) {
|
||||
string = PyString_AsString(output);
|
||||
}
|
||||
else {
|
||||
unicode = PyObject_Str(output);
|
||||
if (unicode)
|
||||
string = PyString_AsString(unicode);
|
||||
}
|
||||
#endif
|
||||
|
||||
PY_TRY {
|
||||
if (string)
|
||||
@@ -950,11 +878,7 @@ std::stringstream &LogLevel::prefix(std::stringstream &str, const char *src, int
|
||||
PyFrameObject* frame = PyEval_GetFrame();
|
||||
if (frame) {
|
||||
line = PyFrame_GetLineNumber(frame);
|
||||
#if PY_MAJOR_VERSION >= 3
|
||||
src = PyUnicode_AsUTF8(frame->f_code->co_filename);
|
||||
#else
|
||||
src = PyString_AsString(frame->f_code->co_filename);
|
||||
#endif
|
||||
}
|
||||
}
|
||||
if (print_src && src && src[0]) {
|
||||
|
||||
@@ -111,11 +111,7 @@ PyObject * Exception::getPyObject(void)
|
||||
edict.setItem("sclassname", Py::String(typeid(*this).name()));
|
||||
edict.setItem("sErrMsg", Py::String(this->getMessage()));
|
||||
edict.setItem("sfile", Py::String(this->getFile()));
|
||||
#if PY_MAJOR_VERSION >= 3
|
||||
edict.setItem("iline", Py::Long(this->getLine()));
|
||||
#else
|
||||
edict.setItem("iline", Py::Int(this->getLine()));
|
||||
#endif
|
||||
edict.setItem("sfunction", Py::String(this->getFunction()));
|
||||
edict.setItem("swhat", Py::String(this->what()));
|
||||
edict.setItem("btranslatable", Py::Boolean(this->getTranslatable()));
|
||||
@@ -138,11 +134,7 @@ void Exception::setPyObject( PyObject * pydict)
|
||||
_sErrMsg = static_cast<std::string>(Py::String(edict.getItem("sErrMsg")));
|
||||
|
||||
if (edict.hasKey("iline"))
|
||||
#if PY_MAJOR_VERSION >= 3
|
||||
_line = static_cast<long>(Py::Long(edict.getItem("iline")));
|
||||
#else
|
||||
_line = static_cast<int>(Py::Int(edict.getItem("iline")));
|
||||
#endif
|
||||
if (edict.hasKey("btranslatable"))
|
||||
_isTranslatable = static_cast<bool>(Py::Boolean(edict.getItem("btranslatable")));
|
||||
if (edict.hasKey("breported"))
|
||||
|
||||
@@ -183,7 +183,6 @@ SystemExitException::SystemExitException()
|
||||
value = code;
|
||||
}
|
||||
|
||||
#if PY_MAJOR_VERSION >= 3
|
||||
if (PyLong_Check(value)) {
|
||||
errCode = PyLong_AsLong(value);
|
||||
}
|
||||
@@ -192,16 +191,6 @@ SystemExitException::SystemExitException()
|
||||
if (str)
|
||||
errMsg = errMsg + ": " + str;
|
||||
}
|
||||
#else
|
||||
if (PyInt_Check(value)) {
|
||||
errCode = PyInt_AsLong(value);
|
||||
}
|
||||
else {
|
||||
const char *str = PyString_AsString(value);
|
||||
if (str)
|
||||
errMsg = errMsg + ": " + str;
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
_sErrMsg = errMsg;
|
||||
@@ -279,11 +268,7 @@ std::string InterpreterSingleton::runString(const char *sCmd)
|
||||
PyObject* repr = PyObject_Repr(presult);
|
||||
Py_DECREF(presult);
|
||||
if (repr) {
|
||||
#if PY_MAJOR_VERSION >= 3
|
||||
std::string ret(PyUnicode_AsUTF8(repr));
|
||||
#else
|
||||
std::string ret(PyString_AsString(repr));
|
||||
#endif
|
||||
Py_DECREF(repr);
|
||||
return ret;
|
||||
}
|
||||
@@ -328,12 +313,8 @@ std::string InterpreterSingleton::runStringWithKey(const char *psCmd, const char
|
||||
if (!key_return_value.isString())
|
||||
key_return_value = key_return_value.str();
|
||||
|
||||
#if PY_MAJOR_VERSION >= 3
|
||||
Py::Bytes str = Py::String(key_return_value).encode("utf-8", "~E~");
|
||||
std::string result = static_cast<std::string>(str);
|
||||
#else
|
||||
std::string result = static_cast<std::string>(Py::String(key_return_value));
|
||||
#endif
|
||||
return result;
|
||||
}
|
||||
|
||||
@@ -368,10 +349,6 @@ void InterpreterSingleton::systemExit(void)
|
||||
int exitcode = 0;
|
||||
|
||||
PyErr_Fetch(&exception, &value, &tb);
|
||||
#if PY_MAJOR_VERSION < 3
|
||||
if (Py_FlushLine())
|
||||
PyErr_Clear();
|
||||
#endif
|
||||
fflush(stdout);
|
||||
if (value == NULL || value == Py_None)
|
||||
goto done;
|
||||
@@ -387,13 +364,8 @@ void InterpreterSingleton::systemExit(void)
|
||||
/* If we failed to dig out the 'code' attribute,
|
||||
just let the else clause below print the error. */
|
||||
}
|
||||
#if PY_MAJOR_VERSION < 3
|
||||
if (PyInt_Check(value))
|
||||
exitcode = (int)PyInt_AsLong(value);
|
||||
#else
|
||||
if (PyLong_Check(value))
|
||||
exitcode = (int)PyLong_AsLong(value);
|
||||
#endif
|
||||
else {
|
||||
PyObject_Print(value, stderr, Py_PRINT_RAW);
|
||||
PySys_WriteStderr("\n");
|
||||
@@ -435,13 +407,8 @@ void InterpreterSingleton::runInteractiveString(const char *sCmd)
|
||||
|
||||
RuntimeError exc(""); // do not use PyException since this clears the error indicator
|
||||
if (errdata) {
|
||||
#if PY_MAJOR_VERSION >= 3
|
||||
if (PyUnicode_Check(errdata))
|
||||
exc.setMessage(PyUnicode_AsUTF8(errdata));
|
||||
#else
|
||||
if (PyString_Check(errdata))
|
||||
exc.setMessage(PyString_AsString(errdata));
|
||||
#endif
|
||||
}
|
||||
PyErr_Restore(errobj, errdata, errtraceback);
|
||||
if (PyErr_Occurred())
|
||||
@@ -476,11 +443,7 @@ void InterpreterSingleton::runFile(const char*pxFileName, bool local)
|
||||
}
|
||||
|
||||
if (PyDict_GetItemString(dict, "__file__") == NULL) {
|
||||
#if PY_MAJOR_VERSION >= 3
|
||||
PyObject *f = PyUnicode_FromString(pxFileName);
|
||||
#else
|
||||
PyObject *f = PyString_FromString(pxFileName);
|
||||
#endif
|
||||
if (f == NULL) {
|
||||
fclose(fp);
|
||||
Py_DECREF(dict);
|
||||
@@ -585,7 +548,6 @@ const char* InterpreterSingleton::init(int argc,char *argv[])
|
||||
PyEval_InitThreads();
|
||||
#endif
|
||||
|
||||
#if PY_MAJOR_VERSION >= 3
|
||||
size_t size = argc;
|
||||
static std::vector<wchar_t *> _argv(size);
|
||||
for (int i = 0; i < argc; i++) {
|
||||
@@ -596,22 +558,15 @@ const char* InterpreterSingleton::init(int argc,char *argv[])
|
||||
#endif
|
||||
}
|
||||
PySys_SetArgv(argc, _argv.data());
|
||||
#else
|
||||
PySys_SetArgv(argc, argv);
|
||||
#endif
|
||||
PythonStdOutput::init_type();
|
||||
this->_global = PyEval_SaveThread();
|
||||
}
|
||||
#if PY_MAJOR_VERSION >= 3
|
||||
PyGILStateLocker lock;
|
||||
#if PY_MINOR_VERSION >= 5
|
||||
return Py_EncodeLocale(Py_GetPath(),NULL);
|
||||
#else
|
||||
return _Py_wchar2char(Py_GetPath(),NULL);
|
||||
#endif
|
||||
#else
|
||||
return Py_GetPath();
|
||||
#endif
|
||||
}
|
||||
|
||||
void InterpreterSingleton::replaceStdOutput()
|
||||
@@ -873,42 +828,13 @@ int getSWIGVersionFromModule(const std::string& module)
|
||||
#if (defined(HAVE_SWIG) && (HAVE_SWIG == 1))
|
||||
namespace Swig_python { extern int createSWIGPointerObj_T(const char* TypeName, void* obj, PyObject** ptr, int own); }
|
||||
#endif
|
||||
#if PY_MAJOR_VERSION < 3
|
||||
namespace Swig_1_3_25 { extern int createSWIGPointerObj_T(const char* TypeName, void* obj, PyObject** ptr, int own); }
|
||||
namespace Swig_1_3_33 { extern int createSWIGPointerObj_T(const char* TypeName, void* obj, PyObject** ptr, int own); }
|
||||
namespace Swig_1_3_36 { extern int createSWIGPointerObj_T(const char* TypeName, void* obj, PyObject** ptr, int own); }
|
||||
namespace Swig_1_3_38 { extern int createSWIGPointerObj_T(const char* TypeName, void* obj, PyObject** ptr, int own); }
|
||||
namespace Swig_1_3_40 { extern int createSWIGPointerObj_T(const char* TypeName, void* obj, PyObject** ptr, int own); }
|
||||
#endif
|
||||
|
||||
PyObject* InterpreterSingleton::createSWIGPointerObj(const char* Module, const char* TypeName, void* Pointer, int own)
|
||||
{
|
||||
int result = 0;
|
||||
PyObject* proxy=0;
|
||||
PyGILStateLocker locker;
|
||||
#if PY_MAJOR_VERSION < 3
|
||||
int version = getSWIGVersionFromModule(Module);
|
||||
switch (version)
|
||||
{
|
||||
case 66329:
|
||||
result = Swig_1_3_25::createSWIGPointerObj_T(TypeName, Pointer, &proxy, own);
|
||||
break;
|
||||
case 66337:
|
||||
result = Swig_1_3_33::createSWIGPointerObj_T(TypeName, Pointer, &proxy, own);
|
||||
break;
|
||||
case 66340:
|
||||
result = Swig_1_3_36::createSWIGPointerObj_T(TypeName, Pointer, &proxy, own);
|
||||
break;
|
||||
case 66342:
|
||||
result = Swig_1_3_38::createSWIGPointerObj_T(TypeName, Pointer, &proxy, own);
|
||||
break;
|
||||
case 66344:
|
||||
result = Swig_1_3_40::createSWIGPointerObj_T(TypeName, Pointer, &proxy, own);
|
||||
break;
|
||||
default:
|
||||
#else
|
||||
(void)Module;
|
||||
#endif
|
||||
#if (defined(HAVE_SWIG) && (HAVE_SWIG == 1))
|
||||
result = Swig_python::createSWIGPointerObj_T(TypeName, Pointer, &proxy, own);
|
||||
#else
|
||||
@@ -917,9 +843,6 @@ PyObject* InterpreterSingleton::createSWIGPointerObj(const char* Module, const c
|
||||
(void)own;
|
||||
result = -1; // indicates error
|
||||
#endif
|
||||
#if PY_MAJOR_VERSION < 3
|
||||
}
|
||||
#endif
|
||||
|
||||
if (result == 0)
|
||||
return proxy;
|
||||
@@ -931,41 +854,12 @@ PyObject* InterpreterSingleton::createSWIGPointerObj(const char* Module, const c
|
||||
#if (defined(HAVE_SWIG) && (HAVE_SWIG == 1))
|
||||
namespace Swig_python { extern int convertSWIGPointerObj_T(const char* TypeName, PyObject* obj, void** ptr, int flags); }
|
||||
#endif
|
||||
#if PY_MAJOR_VERSION < 3
|
||||
namespace Swig_1_3_25 { extern int convertSWIGPointerObj_T(const char* TypeName, PyObject* obj, void** ptr, int flags); }
|
||||
namespace Swig_1_3_33 { extern int convertSWIGPointerObj_T(const char* TypeName, PyObject* obj, void** ptr, int flags); }
|
||||
namespace Swig_1_3_36 { extern int convertSWIGPointerObj_T(const char* TypeName, PyObject* obj, void** ptr, int flags); }
|
||||
namespace Swig_1_3_38 { extern int convertSWIGPointerObj_T(const char* TypeName, PyObject* obj, void** ptr, int flags); }
|
||||
namespace Swig_1_3_40 { extern int convertSWIGPointerObj_T(const char* TypeName, PyObject* obj, void** ptr, int flags); }
|
||||
#endif
|
||||
|
||||
bool InterpreterSingleton::convertSWIGPointerObj(const char* Module, const char* TypeName, PyObject* obj, void** ptr, int flags)
|
||||
{
|
||||
int result = 0;
|
||||
PyGILStateLocker locker;
|
||||
#if PY_MAJOR_VERSION < 3
|
||||
int version = getSWIGVersionFromModule(Module);
|
||||
switch (version)
|
||||
{
|
||||
case 66329:
|
||||
result = Swig_1_3_25::convertSWIGPointerObj_T(TypeName, obj, ptr, flags);
|
||||
break;
|
||||
case 66337:
|
||||
result = Swig_1_3_33::convertSWIGPointerObj_T(TypeName, obj, ptr, flags);
|
||||
break;
|
||||
case 66340:
|
||||
result = Swig_1_3_36::convertSWIGPointerObj_T(TypeName, obj, ptr, flags);
|
||||
break;
|
||||
case 66342:
|
||||
result = Swig_1_3_38::convertSWIGPointerObj_T(TypeName, obj, ptr, flags);
|
||||
break;
|
||||
case 66344:
|
||||
result = Swig_1_3_40::convertSWIGPointerObj_T(TypeName, obj, ptr, flags);
|
||||
break;
|
||||
default:
|
||||
#else
|
||||
(void)Module;
|
||||
#endif
|
||||
#if (defined(HAVE_SWIG) && (HAVE_SWIG == 1))
|
||||
result = Swig_python::convertSWIGPointerObj_T(TypeName, obj, ptr, flags);
|
||||
#else
|
||||
@@ -975,9 +869,6 @@ bool InterpreterSingleton::convertSWIGPointerObj(const char* Module, const char*
|
||||
(void)flags;
|
||||
result = -1; // indicates error
|
||||
#endif
|
||||
#if PY_MAJOR_VERSION < 3
|
||||
}
|
||||
#endif
|
||||
|
||||
if (result == 0)
|
||||
return true;
|
||||
@@ -989,13 +880,6 @@ bool InterpreterSingleton::convertSWIGPointerObj(const char* Module, const char*
|
||||
#if (defined(HAVE_SWIG) && (HAVE_SWIG == 1))
|
||||
namespace Swig_python { extern void cleanupSWIG_T(const char* TypeName); }
|
||||
#endif
|
||||
#if PY_MAJOR_VERSION < 3
|
||||
namespace Swig_1_3_25 { extern void cleanupSWIG_T(const char* TypeName); }
|
||||
namespace Swig_1_3_33 { extern void cleanupSWIG_T(const char* TypeName); }
|
||||
namespace Swig_1_3_36 { extern void cleanupSWIG_T(const char* TypeName); }
|
||||
namespace Swig_1_3_38 { extern void cleanupSWIG_T(const char* TypeName); }
|
||||
namespace Swig_1_3_40 { extern void cleanupSWIG_T(const char* TypeName); }
|
||||
#endif
|
||||
|
||||
void InterpreterSingleton::cleanupSWIG(const char* TypeName)
|
||||
{
|
||||
@@ -1005,11 +889,4 @@ void InterpreterSingleton::cleanupSWIG(const char* TypeName)
|
||||
#else
|
||||
(void)TypeName;
|
||||
#endif
|
||||
#if PY_MAJOR_VERSION < 3
|
||||
Swig_1_3_25::cleanupSWIG_T(TypeName);
|
||||
Swig_1_3_33::cleanupSWIG_T(TypeName);
|
||||
Swig_1_3_36::cleanupSWIG_T(TypeName);
|
||||
Swig_1_3_38::cleanupSWIG_T(TypeName);
|
||||
Swig_1_3_40::cleanupSWIG_T(TypeName);
|
||||
#endif
|
||||
}
|
||||
|
||||
@@ -163,11 +163,7 @@ PyObject * MatrixPy::number_power_handler (PyObject* self, PyObject* other, PyOb
|
||||
{
|
||||
if (!PyObject_TypeCheck(self, &(MatrixPy::Type)) ||
|
||||
|
||||
#if PY_MAJOR_VERSION < 3
|
||||
!PyInt_Check(other)
|
||||
#else
|
||||
!PyLong_Check(other)
|
||||
#endif
|
||||
|| arg != Py_None
|
||||
)
|
||||
{
|
||||
@@ -613,11 +609,7 @@ PyObject* MatrixPy::analyze(PyObject * args)
|
||||
|
||||
PY_TRY {
|
||||
std::string type = getMatrixPtr()->analyse();
|
||||
#if PY_MAJOR_VERSION < 3
|
||||
return PyString_FromString(type.c_str());
|
||||
#else
|
||||
return PyUnicode_FromString(type.c_str());
|
||||
#endif
|
||||
}
|
||||
PY_CATCH;
|
||||
}
|
||||
@@ -909,43 +901,14 @@ PyObject * MatrixPy::number_or_handler (PyObject* /*self*/, PyObject* /*other*/)
|
||||
return 0;
|
||||
}
|
||||
|
||||
#if PY_MAJOR_VERSION < 3
|
||||
int MatrixPy::number_coerce_handler (PyObject ** /*self*/, PyObject ** /*other*/)
|
||||
{
|
||||
return 1;
|
||||
}
|
||||
#endif
|
||||
|
||||
PyObject * MatrixPy::number_int_handler (PyObject * /*self*/)
|
||||
{
|
||||
PyErr_SetString(PyExc_NotImplementedError, "Not implemented");
|
||||
return 0;
|
||||
}
|
||||
|
||||
#if PY_MAJOR_VERSION < 3
|
||||
PyObject * MatrixPy::number_long_handler (PyObject * /*self*/)
|
||||
{
|
||||
PyErr_SetString(PyExc_NotImplementedError, "Not implemented");
|
||||
return 0;
|
||||
}
|
||||
#endif
|
||||
|
||||
PyObject * MatrixPy::number_float_handler (PyObject * /*self*/)
|
||||
{
|
||||
PyErr_SetString(PyExc_NotImplementedError, "Not implemented");
|
||||
return 0;
|
||||
}
|
||||
|
||||
#if PY_MAJOR_VERSION < 3
|
||||
PyObject * MatrixPy::number_oct_handler (PyObject * /*self*/)
|
||||
{
|
||||
PyErr_SetString(PyExc_NotImplementedError, "Not implemented");
|
||||
return 0;
|
||||
}
|
||||
|
||||
PyObject * MatrixPy::number_hex_handler (PyObject * /*self*/)
|
||||
{
|
||||
PyErr_SetString(PyExc_NotImplementedError, "Not implemented");
|
||||
return 0;
|
||||
}
|
||||
#endif
|
||||
|
||||
@@ -350,11 +350,7 @@ Py::Object ParameterGrpPy::getInt(const Py::Tuple& args)
|
||||
int Int=0;
|
||||
if (!PyArg_ParseTuple(args.ptr(), "s|i", &pstr,&Int))
|
||||
throw Py::Exception();
|
||||
#if PY_MAJOR_VERSION < 3
|
||||
return Py::Int(_cParamGrp->GetInt(pstr,Int));
|
||||
#else
|
||||
return Py::Long(_cParamGrp->GetInt(pstr,Int));
|
||||
#endif
|
||||
}
|
||||
|
||||
Py::Object ParameterGrpPy::getInts(const Py::Tuple& args)
|
||||
@@ -389,12 +385,7 @@ Py::Object ParameterGrpPy::getUnsigned(const Py::Tuple& args)
|
||||
unsigned int UInt=0;
|
||||
if (!PyArg_ParseTuple(args.ptr(), "s|I", &pstr,&UInt))
|
||||
throw Py::Exception();
|
||||
#if PY_MAJOR_VERSION < 3
|
||||
PyObject* val = Py_BuildValue("I",_cParamGrp->GetUnsigned(pstr,UInt));
|
||||
return Py::asObject(val);
|
||||
#else
|
||||
return Py::Long(_cParamGrp->GetUnsigned(pstr,UInt));
|
||||
#endif
|
||||
}
|
||||
|
||||
Py::Object ParameterGrpPy::getUnsigneds(const Py::Tuple& args)
|
||||
@@ -660,11 +651,7 @@ Py::Object ParameterGrpPy::getContents(const Py::Tuple& args)
|
||||
Py::Tuple t3(3);
|
||||
t3.setItem(0,Py::String("Integer"));
|
||||
t3.setItem(1,Py::String(It3->first.c_str()));
|
||||
#if PY_MAJOR_VERSION < 3
|
||||
t3.setItem(2,Py::Int(It3->second));
|
||||
#else
|
||||
t3.setItem(2,Py::Long(It3->second));
|
||||
#endif
|
||||
list.append(t3);
|
||||
}
|
||||
|
||||
@@ -694,11 +681,7 @@ Py::Object ParameterGrpPy::getContents(const Py::Tuple& args)
|
||||
Py::Tuple t6(3);
|
||||
t6.setItem(0,Py::String("Unsigned Long"));
|
||||
t6.setItem(1,Py::String(It6->first.c_str()));
|
||||
#if PY_MAJOR_VERSION < 3
|
||||
t6.setItem(2,Py::asObject(Py_BuildValue("I",It6->second)));
|
||||
#else
|
||||
t6.setItem(2,Py::Long(It6->second));
|
||||
#endif
|
||||
list.append(t6);
|
||||
}
|
||||
|
||||
|
||||
@@ -326,11 +326,7 @@ PyObject *PlacementPy::getCustomAttributes(const char* attr) const
|
||||
// for backward compatibility
|
||||
if (strcmp(attr, "isNull") == 0) {
|
||||
PyObject *w, *res;
|
||||
#if PY_MAJOR_VERSION >= 3
|
||||
w = PyUnicode_InternFromString("isIdentity");
|
||||
#else
|
||||
w = PyString_InternFromString("isIdentity");
|
||||
#endif
|
||||
res = PyObject_GenericGetAttr(const_cast<PlacementPy *>(this), w);
|
||||
Py_XDECREF(w);
|
||||
return res;
|
||||
@@ -485,43 +481,15 @@ PyObject * PlacementPy::number_or_handler (PyObject* /*self*/, PyObject* /*other
|
||||
return 0;
|
||||
}
|
||||
|
||||
#if PY_MAJOR_VERSION < 3
|
||||
int PlacementPy::number_coerce_handler (PyObject ** /*self*/, PyObject ** /*other*/)
|
||||
{
|
||||
return 1;
|
||||
}
|
||||
#endif
|
||||
|
||||
PyObject * PlacementPy::number_int_handler (PyObject * /*self*/)
|
||||
{
|
||||
PyErr_SetString(PyExc_NotImplementedError, "Not implemented");
|
||||
return 0;
|
||||
}
|
||||
|
||||
#if PY_MAJOR_VERSION < 3
|
||||
PyObject * PlacementPy::number_long_handler (PyObject * /*self*/)
|
||||
{
|
||||
PyErr_SetString(PyExc_NotImplementedError, "Not implemented");
|
||||
return 0;
|
||||
}
|
||||
#endif
|
||||
|
||||
PyObject * PlacementPy::number_float_handler (PyObject * /*self*/)
|
||||
{
|
||||
PyErr_SetString(PyExc_NotImplementedError, "Not implemented");
|
||||
return 0;
|
||||
}
|
||||
|
||||
#if PY_MAJOR_VERSION < 3
|
||||
PyObject * PlacementPy::number_oct_handler (PyObject * /*self*/)
|
||||
{
|
||||
PyErr_SetString(PyExc_NotImplementedError, "Not implemented");
|
||||
return 0;
|
||||
}
|
||||
|
||||
PyObject * PlacementPy::number_hex_handler (PyObject * /*self*/)
|
||||
{
|
||||
PyErr_SetString(PyExc_NotImplementedError, "Not implemented");
|
||||
return 0;
|
||||
}
|
||||
#endif
|
||||
|
||||
@@ -91,17 +91,8 @@
|
||||
|
||||
/** Macro for initialization function of Python modules.
|
||||
*/
|
||||
#if PY_MAJOR_VERSION >= 3
|
||||
# define PyMOD_INIT_FUNC(name) PyMODINIT_FUNC PyInit_##name(void)
|
||||
#else
|
||||
# define PyMOD_INIT_FUNC(name) PyMODINIT_FUNC init##name(void)
|
||||
#endif
|
||||
|
||||
#if PY_MAJOR_VERSION >= 3
|
||||
# define PyMOD_Return(name) return name
|
||||
#else
|
||||
# define PyMOD_Return(name) return (void)name
|
||||
#endif
|
||||
|
||||
/**
|
||||
* Union to convert from PyTypeObject to PyObject pointer.
|
||||
|
||||
@@ -158,11 +158,7 @@ PP_Debug_Function(PyObject *func, PyObject *args)
|
||||
/* expand tuple at front */
|
||||
// it seems that some versions of python want just 2 arguments; in that
|
||||
// case, remove trailing 1
|
||||
#if (PY_MAJOR_VERSION>=2)&&(PY_MINOR_VERSION>=2)
|
||||
oops = _PyTuple_Resize(&args, (1 + PyTuple_Size(args)));
|
||||
#else
|
||||
oops = _PyTuple_Resize(&args, (1 + PyTuple_Size(args)),1);
|
||||
#endif
|
||||
oops |= PyTuple_SetItem(args, 0, func);
|
||||
if (oops)
|
||||
return NULL; /* "args = (funcobj,) + (arg,..)" */
|
||||
@@ -255,15 +251,9 @@ void PP_Fetch_Error_Text()
|
||||
pystring = NULL;
|
||||
if (errobj != NULL &&
|
||||
(pystring = PyObject_Str(errobj)) != NULL && /* str(errobj) */
|
||||
#if PY_MAJOR_VERSION >= 3
|
||||
(PyUnicode_Check(pystring)) ) /* str() increfs */
|
||||
{
|
||||
strncpy(PP_last_error_type, PyUnicode_AsUTF8(pystring), MAX); /*Py->C*/
|
||||
#else
|
||||
(PyString_Check(pystring)) ) /* str() increfs */
|
||||
{
|
||||
strncpy(PP_last_error_type, PyString_AsString(pystring), MAX); /*Py->C*/
|
||||
#endif
|
||||
PP_last_error_type[MAX-1] = '\0';
|
||||
}
|
||||
else
|
||||
@@ -285,11 +275,7 @@ void PP_Fetch_Error_Text()
|
||||
PyObject* value = PyDict_GetItemString(errdata,"swhat");
|
||||
|
||||
if (value!=NULL) {
|
||||
#if PY_MAJOR_VERSION < 3
|
||||
strncpy(PP_last_error_info, PyString_AsString(value), MAX);
|
||||
#else
|
||||
strncpy(PP_last_error_info, PyUnicode_AsUTF8(value), MAX);
|
||||
#endif
|
||||
PP_last_error_info[MAX-1] = '\0';
|
||||
}
|
||||
|
||||
@@ -298,15 +284,9 @@ void PP_Fetch_Error_Text()
|
||||
}
|
||||
else if (errdata != NULL &&
|
||||
(pystring = PyObject_Str(errdata)) != NULL && /* str(): increfs */
|
||||
#if PY_MAJOR_VERSION >= 3
|
||||
(PyUnicode_Check(pystring)) )
|
||||
{
|
||||
strncpy(PP_last_error_info, PyUnicode_AsUTF8(pystring), MAX); /*Py->C*/
|
||||
#else
|
||||
(PyString_Check(pystring)) )
|
||||
{
|
||||
strncpy(PP_last_error_info, PyString_AsString(pystring), MAX); /*Py->C*/
|
||||
#endif
|
||||
PP_last_error_info[MAX-1] = '\0';
|
||||
}
|
||||
else
|
||||
@@ -320,11 +300,7 @@ void PP_Fetch_Error_Text()
|
||||
|
||||
pystring = NULL;
|
||||
if (errtraceback != NULL &&
|
||||
#if PY_MAJOR_VERSION < 3
|
||||
(PP_Run_Function("StringIO", "StringIO", "O", &pystring, "()") == 0) &&
|
||||
#else
|
||||
(PP_Run_Function("io", "StringIO", "O", &pystring, "()") == 0) &&
|
||||
#endif
|
||||
|
||||
(PyTraceBack_Print(errtraceback, pystring) == 0) &&
|
||||
(PP_Run_Method(pystring, "getvalue", "s", &tempstr, "()") == 0) )
|
||||
@@ -338,11 +314,7 @@ void PP_Fetch_Error_Text()
|
||||
if(!frame)
|
||||
return;
|
||||
int line = PyFrame_GetLineNumber(frame);
|
||||
#if PY_MAJOR_VERSION >= 3
|
||||
const char *file = PyUnicode_AsUTF8(frame->f_code->co_filename);
|
||||
#else
|
||||
const char *file = PyString_AsString(frame->f_code->co_filename);
|
||||
#endif
|
||||
#ifdef FC_OS_WIN32
|
||||
const char *_f = strstr(file, "\\src\\");
|
||||
#else
|
||||
@@ -638,11 +610,7 @@ PP_Run_Bytecode(PyObject *codeobj, /* run compiled bytecode object */
|
||||
if (PP_DEBUG)
|
||||
presult = PP_Debug_Bytecode(codeobj, dict); /* run in pdb */
|
||||
else
|
||||
#if PY_MAJOR_VERSION >= 3
|
||||
presult = PyEval_EvalCode((PyObject*)codeobj, dict, dict);
|
||||
#else
|
||||
presult = PyEval_EvalCode((PyCodeObject *)codeobj, dict, dict);
|
||||
#endif
|
||||
return PP_Convert_Result(presult, resfmt, restarget); /* expr val to C */
|
||||
}
|
||||
|
||||
|
||||
@@ -265,26 +265,9 @@ PyObject * QuantityPy::number_int_handler (PyObject *self)
|
||||
}
|
||||
|
||||
QuantityPy* q = static_cast<QuantityPy*>(self);
|
||||
#if PY_MAJOR_VERSION < 3
|
||||
return PyInt_FromLong((long)q->getValue());
|
||||
#else
|
||||
return PyLong_FromLong((long)q->getValue());
|
||||
#endif
|
||||
}
|
||||
|
||||
#if PY_MAJOR_VERSION < 3
|
||||
PyObject * QuantityPy::number_long_handler (PyObject *self)
|
||||
{
|
||||
if (!PyObject_TypeCheck(self, &(QuantityPy::Type))) {
|
||||
PyErr_SetString(PyExc_TypeError, "Arg must be Quantity");
|
||||
return 0;
|
||||
}
|
||||
|
||||
QuantityPy* q = static_cast<QuantityPy*>(self);
|
||||
return PyInt_FromLong((long)q->getValue());
|
||||
}
|
||||
#endif
|
||||
|
||||
PyObject * QuantityPy::number_negative_handler (PyObject *self)
|
||||
{
|
||||
if (!PyObject_TypeCheck(self, &(QuantityPy::Type))) {
|
||||
@@ -324,10 +307,6 @@ static Quantity &pyToQuantity(Quantity &q, PyObject *pyobj) {
|
||||
q = *static_cast<Base::QuantityPy*>(pyobj)->getQuantityPtr();
|
||||
else if (PyFloat_Check(pyobj))
|
||||
q = Quantity(PyFloat_AsDouble(pyobj));
|
||||
#if PY_MAJOR_VERSION < 3
|
||||
else if (PyInt_Check(pyobj))
|
||||
q = Quantity(PyInt_AsLong(pyobj));
|
||||
#endif
|
||||
else if (PyLong_Check(pyobj))
|
||||
q = Quantity(PyLong_AsLong(pyobj));
|
||||
else {
|
||||
@@ -427,11 +406,6 @@ PyObject * QuantityPy::number_remainder_handler (PyObject *self, PyObject *other
|
||||
else if (PyFloat_Check(other)) {
|
||||
d2 = PyFloat_AsDouble(other);
|
||||
}
|
||||
#if PY_MAJOR_VERSION < 3
|
||||
else if (PyInt_Check(other)) {
|
||||
d2 = (double)PyInt_AsLong(other);
|
||||
}
|
||||
#endif
|
||||
else if (PyLong_Check(other)) {
|
||||
d2 = (double)PyLong_AsLong(other);
|
||||
}
|
||||
@@ -479,13 +453,6 @@ PyObject * QuantityPy::number_power_handler (PyObject *self, PyObject *other, Py
|
||||
double b = PyFloat_AsDouble(other);
|
||||
return new QuantityPy(new Quantity(a->pow(b)) );
|
||||
}
|
||||
#if PY_MAJOR_VERSION < 3
|
||||
else if (PyInt_Check(other)) {
|
||||
Base::Quantity *a = static_cast<QuantityPy*>(self) ->getQuantityPtr();
|
||||
double b = (double)PyInt_AsLong(other);
|
||||
return new QuantityPy(new Quantity(a->pow(b)));
|
||||
}
|
||||
#endif
|
||||
else if (PyLong_Check(other)) {
|
||||
Base::Quantity *a = static_cast<QuantityPy*>(self) ->getQuantityPtr();
|
||||
double b = (double)PyLong_AsLong(other);
|
||||
@@ -641,11 +608,7 @@ void QuantityPy::setFormat(Py::Dict arg)
|
||||
|
||||
if (arg.hasKey("NumberFormat")) {
|
||||
Py::Char form(arg.getItem("NumberFormat"));
|
||||
#if PY_MAJOR_VERSION >= 3
|
||||
std::string fmtstr = static_cast<std::string>(Py::String(form));
|
||||
#else
|
||||
std::string fmtstr = static_cast<std::string>(form);
|
||||
#endif
|
||||
if (fmtstr.size() != 1)
|
||||
throw Py::ValueError("Invalid format character");
|
||||
|
||||
@@ -740,21 +703,3 @@ PyObject * QuantityPy::number_or_handler (PyObject* /*self*/, PyObject* /*other*
|
||||
return 0;
|
||||
}
|
||||
|
||||
#if PY_MAJOR_VERSION < 3
|
||||
int QuantityPy::number_coerce_handler (PyObject** /*self*/, PyObject** /*other*/)
|
||||
{
|
||||
return 1;
|
||||
}
|
||||
|
||||
PyObject * QuantityPy::number_oct_handler (PyObject* /*self*/)
|
||||
{
|
||||
PyErr_SetString(PyExc_TypeError, "oct() argument can't be converted to oct");
|
||||
return 0;
|
||||
}
|
||||
|
||||
PyObject * QuantityPy::number_hex_handler (PyObject* /*self*/)
|
||||
{
|
||||
PyErr_SetString(PyExc_TypeError, "hex() argument can't be converted to hex");
|
||||
return 0;
|
||||
}
|
||||
#endif
|
||||
|
||||
@@ -491,11 +491,7 @@ PyObject * RotationPy::number_power_handler (PyObject* self, PyObject* other, Py
|
||||
{
|
||||
if (!PyObject_TypeCheck(self, &(RotationPy::Type)) ||
|
||||
|
||||
#if PY_MAJOR_VERSION < 3
|
||||
!PyInt_Check(other)
|
||||
#else
|
||||
!PyLong_Check(other)
|
||||
#endif
|
||||
|| arg != Py_None
|
||||
)
|
||||
{
|
||||
@@ -605,43 +601,15 @@ PyObject * RotationPy::number_or_handler (PyObject* /*self*/, PyObject* /*other*
|
||||
return 0;
|
||||
}
|
||||
|
||||
#if PY_MAJOR_VERSION < 3
|
||||
int RotationPy::number_coerce_handler (PyObject ** /*self*/, PyObject ** /*other*/)
|
||||
{
|
||||
return 1;
|
||||
}
|
||||
#endif
|
||||
|
||||
PyObject * RotationPy::number_int_handler (PyObject * /*self*/)
|
||||
{
|
||||
PyErr_SetString(PyExc_NotImplementedError, "Not implemented");
|
||||
return 0;
|
||||
}
|
||||
|
||||
#if PY_MAJOR_VERSION < 3
|
||||
PyObject * RotationPy::number_long_handler (PyObject * /*self*/)
|
||||
{
|
||||
PyErr_SetString(PyExc_NotImplementedError, "Not implemented");
|
||||
return 0;
|
||||
}
|
||||
#endif
|
||||
|
||||
PyObject * RotationPy::number_float_handler (PyObject * /*self*/)
|
||||
{
|
||||
PyErr_SetString(PyExc_NotImplementedError, "Not implemented");
|
||||
return 0;
|
||||
}
|
||||
|
||||
#if PY_MAJOR_VERSION < 3
|
||||
PyObject * RotationPy::number_oct_handler (PyObject * /*self*/)
|
||||
{
|
||||
PyErr_SetString(PyExc_NotImplementedError, "Not implemented");
|
||||
return 0;
|
||||
}
|
||||
|
||||
PyObject * RotationPy::number_hex_handler (PyObject * /*self*/)
|
||||
{
|
||||
PyErr_SetString(PyExc_NotImplementedError, "Not implemented");
|
||||
return 0;
|
||||
}
|
||||
#endif
|
||||
|
||||
@@ -572,7 +572,6 @@ PyStreambuf::int_type PyStreambuf::underflow()
|
||||
try {
|
||||
std::string c;
|
||||
Py::Object res(meth.apply(arg));
|
||||
#if PY_MAJOR_VERSION >= 3
|
||||
if (res.isBytes()) {
|
||||
c = static_cast<std::string>(Py::Bytes(res));
|
||||
}
|
||||
@@ -583,9 +582,6 @@ PyStreambuf::int_type PyStreambuf::underflow()
|
||||
// wrong type
|
||||
return traits_type::eof();
|
||||
}
|
||||
#else
|
||||
c = static_cast<std::string>(Py::String(res));
|
||||
#endif
|
||||
n = c.size();
|
||||
if (n == 0) {
|
||||
return traits_type::eof();
|
||||
@@ -656,11 +652,7 @@ bool PyStreambuf::writeStr(const char* str, std::streamsize num)
|
||||
return true;
|
||||
}
|
||||
else if (type == BytesIO) {
|
||||
#if PY_MAJOR_VERSION >= 3
|
||||
arg.setItem(0, Py::Bytes(str, num));
|
||||
#else
|
||||
arg.setItem(0, Py::String(str, num));
|
||||
#endif
|
||||
meth.apply(arg);
|
||||
return true;
|
||||
}
|
||||
@@ -675,11 +667,7 @@ bool PyStreambuf::writeStr(const char* str, std::streamsize num)
|
||||
catch (Py::Exception& e) {
|
||||
if (PyErr_ExceptionMatches(PyExc_TypeError)) {
|
||||
e.clear();
|
||||
#if PY_MAJOR_VERSION >= 3
|
||||
arg.setItem(0, Py::Bytes(str, num));
|
||||
#else
|
||||
arg.setItem(0, Py::String(str, num));
|
||||
#endif
|
||||
meth.apply(arg);
|
||||
type = BytesIO;
|
||||
return true;
|
||||
|
||||
@@ -153,11 +153,7 @@ std::string Base::Tools::escapedUnicodeFromUtf8(const char *s)
|
||||
|
||||
PyObject* escaped = PyUnicode_AsUnicodeEscapeString(unicode);
|
||||
if (escaped) {
|
||||
#if PY_MAJOR_VERSION >= 3
|
||||
escapedstr = std::string(PyBytes_AsString(escaped));
|
||||
#else
|
||||
escapedstr = std::string(PyString_AsString(escaped));
|
||||
#endif
|
||||
Py_DECREF(escaped);
|
||||
}
|
||||
|
||||
@@ -173,20 +169,9 @@ std::string Base::Tools::escapedUnicodeToUtf8(const std::string& s)
|
||||
PyObject* unicode = PyUnicode_DecodeUnicodeEscape(s.c_str(), s.size(), "strict");
|
||||
if (!unicode)
|
||||
return string;
|
||||
#if PY_MAJOR_VERSION >= 3
|
||||
if (PyUnicode_Check(unicode)) {
|
||||
string = PyUnicode_AsUTF8(unicode);
|
||||
}
|
||||
#else
|
||||
if (PyUnicode_Check(unicode)) {
|
||||
PyObject* value = PyUnicode_AsUTF8String(unicode);
|
||||
string = PyString_AsString(value);
|
||||
Py_DECREF(value);
|
||||
}
|
||||
else if (PyString_Check(unicode)) {
|
||||
string = PyString_AsString(unicode);
|
||||
}
|
||||
#endif
|
||||
Py_DECREF(unicode);
|
||||
return string;
|
||||
}
|
||||
|
||||
@@ -328,43 +328,14 @@ PyObject * UnitPy::number_or_handler (PyObject* /*self*/, PyObject* /*other*/)
|
||||
return 0;
|
||||
}
|
||||
|
||||
#if PY_MAJOR_VERSION < 3
|
||||
int UnitPy::number_coerce_handler (PyObject** /*self*/, PyObject** /*other*/)
|
||||
{
|
||||
return 1;
|
||||
}
|
||||
#endif
|
||||
|
||||
PyObject * UnitPy::number_int_handler (PyObject* /*self*/)
|
||||
{
|
||||
PyErr_SetString(PyExc_NotImplementedError, "Not implemented");
|
||||
return 0;
|
||||
}
|
||||
|
||||
#if PY_MAJOR_VERSION < 3
|
||||
PyObject * UnitPy::number_long_handler (PyObject* /*self*/)
|
||||
{
|
||||
PyErr_SetString(PyExc_NotImplementedError, "Not implemented");
|
||||
return 0;
|
||||
}
|
||||
#endif
|
||||
|
||||
PyObject * UnitPy::number_float_handler (PyObject* /*self*/)
|
||||
{
|
||||
PyErr_SetString(PyExc_NotImplementedError, "Not implemented");
|
||||
return 0;
|
||||
}
|
||||
|
||||
#if PY_MAJOR_VERSION < 3
|
||||
PyObject * UnitPy::number_oct_handler (PyObject* /*self*/)
|
||||
{
|
||||
PyErr_SetString(PyExc_NotImplementedError, "Not implemented");
|
||||
return 0;
|
||||
}
|
||||
|
||||
PyObject * UnitPy::number_hex_handler (PyObject* /*self*/)
|
||||
{
|
||||
PyErr_SetString(PyExc_NotImplementedError, "Not implemented");
|
||||
return 0;
|
||||
}
|
||||
#endif
|
||||
|
||||
@@ -213,13 +213,8 @@ QString UnitsApi::schemaTranslate(const Base::Quantity& quant, double &factor, Q
|
||||
|
||||
double UnitsApi::toDbl(PyObject *ArgObj, const Base::Unit &u)
|
||||
{
|
||||
#if PY_MAJOR_VERSION >= 3
|
||||
if (PyUnicode_Check(ArgObj)) {
|
||||
QString str = QString::fromUtf8(PyUnicode_AsUTF8(ArgObj));
|
||||
#else
|
||||
if (PyString_Check(ArgObj)) {
|
||||
QString str = QString::fromLatin1(PyString_AsString(ArgObj));
|
||||
#endif
|
||||
// Parse the string
|
||||
Quantity q = Quantity::parse(str);
|
||||
if (q.getUnit() == u)
|
||||
@@ -229,13 +224,8 @@ double UnitsApi::toDbl(PyObject *ArgObj, const Base::Unit &u)
|
||||
else if (PyFloat_Check(ArgObj)) {
|
||||
return PyFloat_AsDouble(ArgObj);
|
||||
}
|
||||
#if PY_MAJOR_VERSION < 3
|
||||
else if (PyInt_Check(ArgObj)) {
|
||||
return static_cast<double>(PyInt_AsLong(ArgObj));
|
||||
#else
|
||||
else if (PyLong_Check(ArgObj)) {
|
||||
return static_cast<double>(PyLong_AsLong(ArgObj));
|
||||
#endif
|
||||
}
|
||||
else {
|
||||
throw Base::UnitsMismatchError("Wrong parameter type!");
|
||||
@@ -245,13 +235,8 @@ double UnitsApi::toDbl(PyObject *ArgObj, const Base::Unit &u)
|
||||
Quantity UnitsApi::toQuantity(PyObject *ArgObj, const Base::Unit &u)
|
||||
{
|
||||
double d;
|
||||
#if PY_MAJOR_VERSION >= 3
|
||||
if (PyUnicode_Check(ArgObj)) {
|
||||
QString str = QString::fromUtf8(PyUnicode_AsUTF8(ArgObj));
|
||||
#else
|
||||
if (PyString_Check(ArgObj)) {
|
||||
QString str = QString::fromLatin1(PyString_AsString(ArgObj));
|
||||
#endif
|
||||
// Parse the string
|
||||
Quantity q = Quantity::parse(str);
|
||||
d = q.getValue();
|
||||
@@ -259,13 +244,8 @@ Quantity UnitsApi::toQuantity(PyObject *ArgObj, const Base::Unit &u)
|
||||
else if (PyFloat_Check(ArgObj)) {
|
||||
d = PyFloat_AsDouble(ArgObj);
|
||||
}
|
||||
#if PY_MAJOR_VERSION < 3
|
||||
else if (PyInt_Check(ArgObj)) {
|
||||
d = static_cast<double>(PyInt_AsLong(ArgObj));
|
||||
#else
|
||||
else if (PyLong_Check(ArgObj)) {
|
||||
d = static_cast<double>(PyLong_AsLong(ArgObj));
|
||||
#endif
|
||||
}
|
||||
else {
|
||||
throw Base::UnitsMismatchError("Wrong parameter type!");
|
||||
|
||||
@@ -155,14 +155,8 @@ PyObject* VectorPy::number_multiply_handler(PyObject *self, PyObject *other)
|
||||
double b = PyFloat_AsDouble(other);
|
||||
return new VectorPy(a * b);
|
||||
}
|
||||
#if PY_MAJOR_VERSION < 3
|
||||
else if (PyInt_Check(other)) {
|
||||
Base::Vector3d a = static_cast<VectorPy*>(self) ->value();
|
||||
long b = PyInt_AsLong(other);
|
||||
#else
|
||||
else if (PyLong_Check(other)) {
|
||||
long b = PyLong_AsLong(other);
|
||||
#endif
|
||||
return new VectorPy(a * (double)b);
|
||||
}
|
||||
else {
|
||||
@@ -176,13 +170,8 @@ PyObject* VectorPy::number_multiply_handler(PyObject *self, PyObject *other)
|
||||
double b = PyFloat_AsDouble(self);
|
||||
return new VectorPy(a * b);
|
||||
}
|
||||
#if PY_MAJOR_VERSION >= 3
|
||||
else if (PyLong_Check(self)) {
|
||||
long b = PyLong_AsLong(self);
|
||||
#else
|
||||
else if (PyInt_Check(self)) {
|
||||
long b = PyInt_AsLong(self);
|
||||
#endif
|
||||
return new VectorPy(a * (double)b);
|
||||
}
|
||||
else {
|
||||
@@ -252,11 +241,7 @@ PyObject * VectorPy::mapping_subscript(PyObject *self, PyObject *item)
|
||||
}
|
||||
else if (PySlice_Check(item)) {
|
||||
Py_ssize_t start, stop, step, slicelength, cur, i;
|
||||
#if PY_MAJOR_VERSION < 3
|
||||
PySliceObject* slice = reinterpret_cast<PySliceObject*>(item);
|
||||
#else
|
||||
PyObject* slice = item;
|
||||
#endif
|
||||
|
||||
if (PySlice_GetIndicesEx(slice,
|
||||
sequence_length(self),
|
||||
@@ -847,13 +832,6 @@ PyObject * VectorPy::number_or_handler (PyObject* self, PyObject* other)
|
||||
return 0;
|
||||
}
|
||||
|
||||
#if PY_MAJOR_VERSION < 3
|
||||
int VectorPy::number_coerce_handler (PyObject ** /*self*/, PyObject ** /*other*/)
|
||||
{
|
||||
return 1;
|
||||
}
|
||||
#endif
|
||||
|
||||
PyObject * VectorPy::number_int_handler (PyObject* self)
|
||||
{
|
||||
PyErr_Format(PyExc_TypeError, "int() argument must be a string or a number, not '%s'",
|
||||
@@ -861,32 +839,9 @@ PyObject * VectorPy::number_int_handler (PyObject* self)
|
||||
return 0;
|
||||
}
|
||||
|
||||
#if PY_MAJOR_VERSION < 3
|
||||
PyObject * VectorPy::number_long_handler (PyObject* self)
|
||||
{
|
||||
PyErr_Format(PyExc_TypeError, "long() argument must be a string or a number, not '%s'",
|
||||
Py_TYPE(self)->tp_name);
|
||||
return 0;
|
||||
}
|
||||
#endif
|
||||
|
||||
PyObject * VectorPy::number_float_handler (PyObject* self)
|
||||
{
|
||||
PyErr_Format(PyExc_TypeError, "float() argument must be a string or a number, not '%s'",
|
||||
Py_TYPE(self)->tp_name);
|
||||
return 0;
|
||||
}
|
||||
|
||||
#if PY_MAJOR_VERSION < 3
|
||||
PyObject * VectorPy::number_oct_handler (PyObject* /*self*/)
|
||||
{
|
||||
PyErr_SetString(PyExc_TypeError, "oct() argument can't be converted to oct");
|
||||
return 0;
|
||||
}
|
||||
|
||||
PyObject * VectorPy::number_hex_handler (PyObject* /*self*/)
|
||||
{
|
||||
PyErr_SetString(PyExc_TypeError, "hex() argument can't be converted to hex");
|
||||
return 0;
|
||||
}
|
||||
#endif
|
||||
|
||||
@@ -90,11 +90,7 @@ void cleanupSWIG_T(const char* TypeName)
|
||||
PyObject *key, *value;
|
||||
pos = 0;
|
||||
while (PyDict_Next(dict, &pos, &key, &value)) {
|
||||
#if PY_MAJOR_VERSION >= 3
|
||||
if (value != Py_None && PyUnicode_Check(key)) {
|
||||
#else
|
||||
if (value != Py_None && PyString_Check(key)) {
|
||||
#endif
|
||||
void* ptr = 0;
|
||||
if (SWIG_ConvertPtr(value, &ptr, 0, 0) == 0)
|
||||
PyDict_SetItem(dict, key, Py_None);
|
||||
|
||||
Reference in New Issue
Block a user