forked from qt-creator/qt-creator
Debugger: Make sure there are no bools in Python code
Python doesn't like lowercase "true" or "false", so we have to convert those to int before we send the command. Change-Id: Id30ebbb0714cae23b030c78eec5e59378ac467bb Reviewed-by: Christian Stenger <christian.stenger@theqtcompany.com>
This commit is contained in:
committed by
Christian Stenger
parent
ed4bfff644
commit
2186e42697
@@ -853,14 +853,37 @@ void DebuggerCommand::arg(const char *name, const QJsonValue &value)
|
||||
args = addToJsonObject(args, name, value);
|
||||
}
|
||||
|
||||
static QJsonValue translateJsonToPython(const QJsonValue &value)
|
||||
{
|
||||
// TODO: Verify that this covers all incompatibilities between python and json.
|
||||
switch (value.type()) {
|
||||
case QJsonValue::Bool:
|
||||
// Python doesn't understand lowercase "true" or "false"
|
||||
return QJsonValue(value.toBool() ? 1 : 0);
|
||||
case QJsonValue::Object: {
|
||||
QJsonObject object = value.toObject();
|
||||
for (QJsonObject::iterator i = object.begin(); i != object.end(); ++i)
|
||||
i.value() = translateJsonToPython(i.value());
|
||||
return object;
|
||||
}
|
||||
case QJsonValue::Array: {
|
||||
QJsonArray array = value.toArray();
|
||||
for (QJsonArray::iterator i = array.begin(); i != array.end(); ++i)
|
||||
*i = translateJsonToPython(*i);
|
||||
return array;
|
||||
}
|
||||
default:
|
||||
return value;
|
||||
}
|
||||
}
|
||||
|
||||
QByteArray DebuggerCommand::argsToPython() const
|
||||
{
|
||||
// TODO: Verify that this is really Python.
|
||||
|
||||
if (args.isArray())
|
||||
return QJsonDocument(args.toArray()).toJson(QJsonDocument::Compact);
|
||||
QJsonValue pythonCompatible(translateJsonToPython(args));
|
||||
if (pythonCompatible.isArray())
|
||||
return QJsonDocument(pythonCompatible.toArray()).toJson(QJsonDocument::Compact);
|
||||
else
|
||||
return QJsonDocument(args.toObject()).toJson(QJsonDocument::Compact);
|
||||
return QJsonDocument(pythonCompatible.toObject()).toJson(QJsonDocument::Compact);
|
||||
}
|
||||
|
||||
QByteArray DebuggerCommand::argsToString() const
|
||||
|
Reference in New Issue
Block a user