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:
Ulf Hermann
2015-11-30 14:49:18 +01:00
committed by Christian Stenger
parent ed4bfff644
commit 2186e42697

View File

@@ -853,14 +853,37 @@ void DebuggerCommand::arg(const char *name, const QJsonValue &value)
args = addToJsonObject(args, name, 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 QByteArray DebuggerCommand::argsToPython() const
{ {
// TODO: Verify that this is really Python. QJsonValue pythonCompatible(translateJsonToPython(args));
if (pythonCompatible.isArray())
if (args.isArray()) return QJsonDocument(pythonCompatible.toArray()).toJson(QJsonDocument::Compact);
return QJsonDocument(args.toArray()).toJson(QJsonDocument::Compact);
else else
return QJsonDocument(args.toObject()).toJson(QJsonDocument::Compact); return QJsonDocument(pythonCompatible.toObject()).toJson(QJsonDocument::Compact);
} }
QByteArray DebuggerCommand::argsToString() const QByteArray DebuggerCommand::argsToString() const