pidl: added a __ndr_print__() method on python NDR objects
authorAndrew Tridgell <tridge@samba.org>
Sun, 22 Aug 2010 04:46:01 +0000 (14:46 +1000)
committerAndrew Tridgell <tridge@samba.org>
Sun, 22 Aug 2010 04:57:34 +0000 (14:57 +1000)
This allows you to print a returned NDR structure using
s.__ndr_print__() which gives an easy view of complex
structures, such as those from netlogon

pidl/lib/Parse/Pidl/Samba4/Python.pm

index 75aa0a8172704b8ab323454c1e4418f167a74d34..b7d70fafaf4de742fd1c426c3da79ed701d55773 100644 (file)
@@ -288,11 +288,24 @@ sub PythonStruct($$$$$$)
                $self->deindent;
                $self->pidl("}");
                $self->pidl("");
+
+               $self->pidl("static PyObject *py_$name\_ndr_print(PyObject *py_obj)");
+               $self->pidl("{");
+               $self->indent;
+               $self->pidl("$cname *object = ($cname *)py_talloc_get_ptr(py_obj);");
+               $self->pidl("char *retstr;");
+               $self->pidl("retstr = ndr_print_struct_string(py_talloc_get_mem_ctx(py_obj), (ndr_print_fn_t)ndr_print_$name, \"$name\", object);");
+               $self->pidl("return PyString_FromString(retstr);");
+               $self->deindent;
+               $self->pidl("}");
+               $self->pidl("");
+
                $py_methods = "py_$name\_methods";
                $self->pidl("static PyMethodDef $py_methods\[] = {");
                $self->indent;
                $self->pidl("{ \"__ndr_pack__\", (PyCFunction)py_$name\_ndr_pack, METH_NOARGS, \"S.pack() -> blob\\nNDR pack\" },");
                $self->pidl("{ \"__ndr_unpack__\", (PyCFunction)py_$name\_ndr_unpack, METH_VARARGS, \"S.unpack(blob) -> None\\nNDR unpack\" },");
+               $self->pidl("{ \"__ndr_print__\", (PyCFunction)py_$name\_ndr_print, METH_VARARGS, \"S.print(blob) -> None\\nNDR print\" },");
                $self->pidl("{ NULL, NULL, 0, NULL }");
                $self->deindent;
                $self->pidl("};");