From 5a025c82f566b378a125abf0f9e74fc076d394c0 Mon Sep 17 00:00:00 2001 From: Andrew Tridgell Date: Sun, 22 Aug 2010 14:46:01 +1000 Subject: pidl: added a __ndr_print__() method on python NDR objects 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 | 13 +++++++++++++ 1 file changed, 13 insertions(+) (limited to 'pidl') diff --git a/pidl/lib/Parse/Pidl/Samba4/Python.pm b/pidl/lib/Parse/Pidl/Samba4/Python.pm index 75aa0a8172..b7d70fafaf 100644 --- a/pidl/lib/Parse/Pidl/Samba4/Python.pm +++ b/pidl/lib/Parse/Pidl/Samba4/Python.pm @@ -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("};"); -- cgit