if (reduce != null) {
tup = reduce.__call__(Py.newInteger(protocol));
} else {
reduce = object.__findattr__("__reduce__");
if (reduce == null)
throw new PyException(UnpickleableError, object);
tup = reduce.__call__();
}
} else {
tup = reduce.__call__(object);
}
if (tup instanceof PyString) {
save_global(object, tup);
return;
}
if (!(tup instanceof PyTuple)) {
throw new PyException(PicklingError,
"Value returned by " + reduce.__repr__() +
" must be a tuple");
}
int l = tup.__len__();
if (l < 2 || l > 5) {
throw new PyException(PicklingError,
"tuple returned by " + reduce.__repr__() +
" must contain two to five elements");
}
PyObject callable = tup.__finditem__(0);
PyObject arg_tup = tup.__finditem__(1);
PyObject state = (l > 2) ? tup.__finditem__(2) : Py.None;
PyObject listitems = (l > 3) ? tup.__finditem__(3) : Py.None;
PyObject dictitems = (l > 4) ? tup.__finditem__(4) : Py.None;
if (!(arg_tup instanceof PyTuple) && arg_tup != Py.None) {
throw new PyException(PicklingError,
"Second element of tupe returned by " +
reduce.__repr__() + " must be a tuple");
}
save_reduce(callable, arg_tup, state, listitems, dictitems, object);
}