[SCM] Samba Shared Repository - branch master updated - release-4-0-0alpha7-1181-g1856b99

Andrew Bartlett abartlet at samba.org
Tue Apr 21 09:16:44 GMT 2009


The branch, master has been updated
       via  1856b999c88e0e460fbf713b459d5d367db999f2 (commit)
      from  4c32978d973093903a5372a6f358275184bbcab2 (commit)

http://gitweb.samba.org/?p=samba.git;a=shortlog;h=master


- Log -----------------------------------------------------------------
commit 1856b999c88e0e460fbf713b459d5d367db999f2
Author: Andrew Bartlett <abartlet at samba.org>
Date:   Tue Apr 21 11:14:11 2009 +0200

    python/rpc: Add custom GUID.__str__, GUID.__repr__, GUID.__init__ and GUID.__cmp__.

-----------------------------------------------------------------------

Summary of changes:
 librpc/idl/misc.idl                                |    2 +
 source4/librpc/ndr/py_misc.c                       |   92 ++++++++++++++++++++
 .../scripting/python/samba/tests/dcerpc/misc.py    |   48 ++++++++++
 source4/selftest/tests.sh                          |    1 +
 4 files changed, 143 insertions(+), 0 deletions(-)
 create mode 100644 source4/librpc/ndr/py_misc.c
 create mode 100644 source4/scripting/python/samba/tests/dcerpc/misc.py


Changeset truncated at 500 lines:

diff --git a/librpc/idl/misc.idl b/librpc/idl/misc.idl
index c4d8c62..5bc3c9f 100644
--- a/librpc/idl/misc.idl
+++ b/librpc/idl/misc.idl
@@ -2,7 +2,9 @@
   miscellaneous IDL structures
 */
 
+
 [
+	pyhelper("librpc/ndr/py_misc.c"),
 	pointer_default(unique)
 ]
 interface misc
diff --git a/source4/librpc/ndr/py_misc.c b/source4/librpc/ndr/py_misc.c
new file mode 100644
index 0000000..4e25566
--- /dev/null
+++ b/source4/librpc/ndr/py_misc.c
@@ -0,0 +1,92 @@
+/* 
+   Unix SMB/CIFS implementation.
+   Samba utility functions
+   Copyright (C) Jelmer Vernooij <jelmer at samba.org> 2008
+   
+   This program is free software; you can redistribute it and/or modify
+   it under the terms of the GNU General Public License as published by
+   the Free Software Foundation; either version 3 of the License, or
+   (at your option) any later version.
+   
+   This program is distributed in the hope that it will be useful,
+   but WITHOUT ANY WARRANTY; without even the implied warranty of
+   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+   GNU General Public License for more details.
+   
+   You should have received a copy of the GNU General Public License
+   along with this program.  If not, see <http://www.gnu.org/licenses/>.
+*/
+#include <Python.h>
+#include "librpc/gen_ndr/misc.h"
+
+#ifndef Py_RETURN_NONE
+#define Py_RETURN_NONE return Py_INCREF(Py_None), Py_None
+#endif
+
+static int py_GUID_cmp(PyObject *py_self, PyObject *py_other)
+{
+	int ret;
+	struct GUID *self = py_talloc_get_ptr(py_self), *other;
+	other = py_talloc_get_ptr(py_other);
+	if (other == NULL)
+		return -1;
+
+	ret = GUID_compare(self, other);
+	if (ret < 0) {
+		return -1;
+	} else if (ret > 0) {
+		return 1;
+	} else {
+		return 0;
+	}
+}
+
+static PyObject *py_GUID_str(PyObject *py_self)
+{
+	struct GUID *self = py_talloc_get_ptr(py_self);
+	char *str = GUID_string(NULL, self);
+	PyObject *ret = PyString_FromString(str);
+	talloc_free(str);
+	return ret;
+}
+
+static PyObject *py_GUID_repr(PyObject *py_self)
+{
+	struct GUID *self = py_talloc_get_ptr(py_self);
+	char *str = GUID_string(NULL, self);
+	PyObject *ret = PyString_FromFormat("GUID('%s')", str);
+	talloc_free(str);
+	return ret;
+}
+
+static int py_GUID_init(PyObject *self, PyObject *args, PyObject *kwargs)
+{
+	char *str = NULL;
+	NTSTATUS status;
+	struct GUID *guid = py_talloc_get_ptr(self);
+	const char *kwnames[] = { "str", NULL };
+
+	if (!PyArg_ParseTupleAndKeywords(args, kwargs, "|s", discard_const_p(char *, kwnames), &str))
+		return -1;
+
+	if (str != NULL) {
+		status = GUID_from_string(str, guid);
+		if (!NT_STATUS_IS_OK(status)) {
+			PyErr_SetNTSTATUS(status);
+			return -1;
+		}
+	}
+
+	return 0;
+}
+
+static void py_GUID_patch(PyTypeObject *type)
+{
+	type->tp_init = py_GUID_init;
+	type->tp_str = py_GUID_str;
+	type->tp_repr = py_GUID_repr;
+	type->tp_compare = py_GUID_cmp;
+}
+
+#define PY_GUID_PATCH py_GUID_patch
+
diff --git a/source4/scripting/python/samba/tests/dcerpc/misc.py b/source4/scripting/python/samba/tests/dcerpc/misc.py
new file mode 100644
index 0000000..d9a5573
--- /dev/null
+++ b/source4/scripting/python/samba/tests/dcerpc/misc.py
@@ -0,0 +1,48 @@
+#!/usr/bin/python
+
+# Unix SMB/CIFS implementation.
+# Copyright (C) Jelmer Vernooij <jelmer at samba.org> 2007
+#   
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 3 of the License, or
+# (at your option) any later version.
+#   
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+# GNU General Public License for more details.
+#   
+# You should have received a copy of the GNU General Public License
+# along with this program.  If not, see <http://www.gnu.org/licenses/>.
+#
+
+import unittest
+from samba.dcerpc import misc
+
+text1 = "76f53846-a7c2-476a-ae2c-20e2b80d7b34"
+text2 = "344edffa-330a-4b39-b96e-2c34da52e8b1"
+
+class GUIDTests(unittest.TestCase):
+    def test_str(self):
+        guid = misc.GUID(text1)
+        self.assertEquals(text1, str(guid))
+
+    def test_repr(self):
+        guid = misc.GUID(text1)
+        self.assertEquals("GUID('%s')" % text1, repr(guid))
+
+    def test_compare_different(self):
+        guid1 = misc.GUID(text1)
+        guid2 = misc.GUID(text2)
+        self.assertTrue(cmp(guid1, guid2) > 0)
+
+    def test_compare_same(self):
+        guid1 = misc.GUID(text1)
+        guid2 = misc.GUID(text1)
+        self.assertEquals(0, cmp(guid1, guid2))
+        self.assertEquals(guid1, guid2)
+
+
+         
+        
diff --git a/source4/selftest/tests.sh b/source4/selftest/tests.sh
index d18fffa..97aae84 100755
--- a/source4/selftest/tests.sh
+++ b/source4/selftest/tests.sh
@@ -406,6 +406,7 @@ plantest "registry.python" none PYTHONPATH="$PYTHONPATH:$samba4srcdir/lib/regist
 plantest "tdb.python" none PYTHONPATH="$PYTHONPATH:../lib/tdb/python/tests" $SUBUNITRUN simple
 plantest "auth.python" none PYTHONPATH="$PYTHONPATH:$samba4srcdir/auth/tests/" $SUBUNITRUN bindings
 plantest "security.python" none PYTHONPATH="$PYTHONPATH:$samba4srcdir/libcli/security/tests" $SUBUNITRUN bindings
+plantest "misc.python" none $SUBUNITRUN samba.tests.dcerpc.misc
 plantest "param.python" none PYTHONPATH="$PYTHONPATH:$samba4srcdir/param/tests" $SUBUNITRUN bindings
 plantest "upgrade.python" none $SUBUNITRUN samba.tests.upgrade
 plantest "samba.python" none $SUBUNITRUN samba.tests


-- 
Samba Shared Repository


More information about the samba-cvs mailing list