Merge branch 'master' of ssh://git.samba.org/data/git/samba into abartlet-devel
authorAndrew Bartlett <abartlet@samba.org>
Tue, 21 Apr 2009 10:20:37 +0000 (12:20 +0200)
committerAndrew Bartlett <abartlet@samba.org>
Tue, 21 Apr 2009 10:20:37 +0000 (12:20 +0200)
source4/librpc/ndr/py_misc.c
source4/scripting/python/samba/tests/dcerpc/misc.py

index 4e2556614846d8d76d0fecc0b992254b837a9232..5d5b881b3885a274c573900b49c190f04b44705b 100644 (file)
@@ -90,3 +90,51 @@ static void py_GUID_patch(PyTypeObject *type)
 
 #define PY_GUID_PATCH py_GUID_patch
 
+static int py_policy_handle_init(PyObject *self, PyObject *args, PyObject *kwargs)
+{
+       char *str = NULL;
+       NTSTATUS status;
+       struct policy_handle *handle = py_talloc_get_ptr(self);
+       const char *kwnames[] = { "uuid", "type", NULL };
+
+       if (!PyArg_ParseTupleAndKeywords(args, kwargs, "|si", discard_const_p(char *, kwnames), &str, &handle->handle_type))
+               return -1;
+
+       if (str != NULL) {
+               status = GUID_from_string(str, &handle->uuid);
+               if (!NT_STATUS_IS_OK(status)) {
+                       PyErr_SetNTSTATUS(status);
+                       return -1;
+               }
+       }
+
+       return 0;
+}
+
+static PyObject *py_policy_handle_repr(PyObject *py_self)
+{
+       struct policy_handle *self = py_talloc_get_ptr(py_self);
+       char *uuid_str = GUID_string(NULL, &self->uuid);
+       PyObject *ret = PyString_FromFormat("policy_handle(%d, '%s')", self->handle_type, uuid_str);
+       talloc_free(uuid_str);
+       return ret;
+}
+
+static PyObject *py_policy_handle_str(PyObject *py_self)
+{
+       struct policy_handle *self = py_talloc_get_ptr(py_self);
+       char *uuid_str = GUID_string(NULL, &self->uuid);
+       PyObject *ret = PyString_FromFormat("%d, %s", self->handle_type, uuid_str);
+       talloc_free(uuid_str);
+       return ret;
+}
+
+static void py_policy_handle_patch(PyTypeObject *type)
+{
+       type->tp_init = py_policy_handle_init;
+       type->tp_repr = py_policy_handle_repr;
+       type->tp_str = py_policy_handle_str;
+}
+
+#define PY_POLICY_HANDLE_PATCH py_policy_handle_patch
+
index d9a5573980ca5e8fcd9ca98f61fc0cc885f63f99..e9b5127a5af167bdc635086a508bbc95d281f932 100644 (file)
@@ -24,6 +24,7 @@ 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))
@@ -46,3 +47,18 @@ class GUIDTests(unittest.TestCase):
 
          
         
+class PolicyHandleTests(unittest.TestCase):
+
+    def test_init(self):
+        x = misc.policy_handle(text1, 1)
+        self.assertEquals(1, x.handle_type)
+        self.assertEquals(text1, str(x.uuid))
+
+    def test_repr(self):
+        x = misc.policy_handle(text1, 42)
+        self.assertEquals("policy_handle(%d, '%s')" % (42, text1), repr(x))
+
+    def test_str(self):
+        x = misc.policy_handle(text1, 42)
+        self.assertEquals("%d, %s" % (42, text1), str(x))
+