Skip to content
Snippets Groups Projects
Commit ba1296e8 authored by Studer Gabriel's avatar Studer Gabriel
Browse files

don't use deprecated parser module

Python interpreter in DNG uses the parser module to identify simple
one line expressions. That module is gone in Python 3.10.
Functionality gets replaced by the builtin compile function.
parent f237848f
No related branches found
No related tags found
No related merge requests found
...@@ -21,6 +21,7 @@ ...@@ -21,6 +21,7 @@
#include "python_interpreter_worker.hh" #include "python_interpreter_worker.hh"
#include "python_interpreter.hh" #include "python_interpreter.hh"
namespace ost { namespace gui { namespace ost { namespace gui {
namespace { namespace {
...@@ -55,7 +56,7 @@ PythonInterpreterWorker::PythonInterpreterWorker(): ...@@ -55,7 +56,7 @@ PythonInterpreterWorker::PythonInterpreterWorker():
current_id_(), current_id_(),
awake_(false) awake_(false)
{ {
parse_expr_cmd_=bp::import("parser").attr("expr"); parse_expr_cmd_=bp::import("__main__").attr("__builtins__").attr("compile");
main_namespace_ = bp::extract<bp::dict>(bp::import("__main__").attr("__dict__")); main_namespace_ = bp::extract<bp::dict>(bp::import("__main__").attr("__dict__"));
repr_=bp::import("__main__").attr("__builtins__").attr("repr"); repr_=bp::import("__main__").attr("__builtins__").attr("repr");
#ifndef _MSC_VER #ifndef _MSC_VER
...@@ -98,16 +99,6 @@ unsigned int PythonInterpreterWorker::AddCommand(const QString& command) ...@@ -98,16 +99,6 @@ unsigned int PythonInterpreterWorker::AddCommand(const QString& command)
return command_id_; return command_id_;
} }
bool PythonInterpreterWorker::is_simple_expression_(const QString& expr)
{
try {
parse_expr_cmd_(bp::str(expr.toStdString()));
return true;
} catch(bp::error_already_set&) {
PyErr_Clear();
return false;
}
}
void PythonInterpreterWorker::run_command_(std::pair<unsigned int,QString> pair) void PythonInterpreterWorker::run_command_(std::pair<unsigned int,QString> pair)
{ {
#ifndef _MSC_VER #ifndef _MSC_VER
...@@ -148,7 +139,7 @@ void PythonInterpreterWorker::run_command_(std::pair<unsigned int,QString> pair) ...@@ -148,7 +139,7 @@ void PythonInterpreterWorker::run_command_(std::pair<unsigned int,QString> pair)
bool PythonInterpreterWorker::is_simple_expression(const QString& expr) bool PythonInterpreterWorker::is_simple_expression(const QString& expr)
{ {
try { try {
parse_expr_cmd_(bp::str(expr.toStdString())); parse_expr_cmd_(bp::str(expr.toStdString()), "<string>", "eval");
return true; return true;
} catch(bp::error_already_set&) { } catch(bp::error_already_set&) {
PyErr_Clear(); PyErr_Clear();
......
...@@ -62,7 +62,6 @@ protected slots: ...@@ -62,7 +62,6 @@ protected slots:
protected: protected:
bool is_simple_expression(const QString& expr); bool is_simple_expression(const QString& expr);
void run_command_(std::pair<unsigned int,QString> pair); void run_command_(std::pair<unsigned int,QString> pair);
bool is_simple_expression_(const QString& expr);
QQueue<std::pair<unsigned int,QString> > exec_queue_; QQueue<std::pair<unsigned int,QString> > exec_queue_;
unsigned int command_id_; unsigned int command_id_;
boost::shared_ptr<OutputRedirector> output_redirector_; boost::shared_ptr<OutputRedirector> output_redirector_;
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment