diff options
-rw-r--r-- | pidl/lib/Parse/Pidl/Samba4/Python.pm | 29 |
1 files changed, 26 insertions, 3 deletions
diff --git a/pidl/lib/Parse/Pidl/Samba4/Python.pm b/pidl/lib/Parse/Pidl/Samba4/Python.pm index 63f4b2baef..63f41a10ea 100644 --- a/pidl/lib/Parse/Pidl/Samba4/Python.pm +++ b/pidl/lib/Parse/Pidl/Samba4/Python.pm @@ -271,21 +271,44 @@ sub PythonStruct($$$$$$) $self->pidl("}"); $self->pidl(""); - $self->pidl("static PyObject *py_$name\_ndr_unpack(PyObject *py_obj, PyObject *args)"); + $self->pidl("static PyObject *py_$name\_ndr_unpack(PyObject *py_obj, PyObject *args, PyObject *kwargs)"); $self->pidl("{"); $self->indent; $self->pidl("$cname *object = ($cname *)pytalloc_get_ptr(py_obj);"); $self->pidl("DATA_BLOB blob;"); $self->pidl("int blob_length = 0;"); $self->pidl("enum ndr_err_code err;"); - $self->pidl("if (!PyArg_ParseTuple(args, \"s#:__ndr_unpack__\", &blob.data, &blob_length)) {"); + $self->pidl("const char * const kwnames[] = { \"data_blob\", \"allow_remaining\", NULL };"); + $self->pidl("PyObject *allow_remaining_obj = NULL;"); + $self->pidl("bool allow_remaining = false;"); + $self->pidl(""); + $self->pidl("if (!PyArg_ParseTupleAndKeywords(args, kwargs, \"s#|O:__ndr_unpack__\","); + $self->indent; + $self->pidl("discard_const_p(char *, kwnames),"); + $self->pidl("&blob.data, &blob_length,"); + $self->pidl("&allow_remaining_obj)) {"); + $self->deindent; $self->indent; $self->pidl("return NULL;"); $self->deindent; $self->pidl("}"); $self->pidl("blob.length = blob_length;"); $self->pidl(""); + $self->pidl("if (allow_remaining_obj && PyObject_IsTrue(allow_remaining_obj)) {"); + $self->indent; + $self->pidl("allow_remaining = true;"); + $self->deindent; + $self->pidl("}"); + $self->pidl(""); + $self->pidl("if (allow_remaining) {"); + $self->indent; + $self->pidl("err = ndr_pull_struct_blob(&blob, pytalloc_get_mem_ctx(py_obj), object, (ndr_pull_flags_fn_t)ndr_pull_$name);"); + $self->deindent; + $self->pidl("} else {"); + $self->indent; $self->pidl("err = ndr_pull_struct_blob_all(&blob, pytalloc_get_mem_ctx(py_obj), object, (ndr_pull_flags_fn_t)ndr_pull_$name);"); + $self->deindent; + $self->pidl("}"); $self->pidl("if (err != NDR_ERR_SUCCESS) {"); $self->indent; $self->pidl("PyErr_SetNdrError(err);"); @@ -318,7 +341,7 @@ sub PythonStruct($$$$$$) $self->pidl("static PyMethodDef $py_methods\[] = {"); $self->indent; $self->pidl("{ \"__ndr_pack__\", (PyCFunction)py_$name\_ndr_pack, METH_NOARGS, \"S.ndr_pack(object) -> blob\\nNDR pack\" },"); - $self->pidl("{ \"__ndr_unpack__\", (PyCFunction)py_$name\_ndr_unpack, METH_VARARGS, \"S.ndr_unpack(class, blob) -> None\\nNDR unpack\" },"); + $self->pidl("{ \"__ndr_unpack__\", (PyCFunction)py_$name\_ndr_unpack, METH_VARARGS|METH_KEYWORDS, \"S.ndr_unpack(class, blob, allow_remaining=False) -> None\\nNDR unpack\" },"); $self->pidl("{ \"__ndr_print__\", (PyCFunction)py_$name\_ndr_print, METH_VARARGS, \"S.ndr_print(object) -> None\\nNDR print\" },"); $self->pidl("{ NULL, NULL, 0, NULL }"); $self->deindent; |