[SCM] Samba Shared Repository - branch master updated

Stefan Metzmacher metze at samba.org
Thu Nov 5 20:12:04 UTC 2015


The branch, master has been updated
       via  8a40da8 ldb: version 1.1.23
       via  0d36d6d pyldb: Improve test coverage
       via  dd7baa2 pyldb: Fixes and Python3 compat for Dn component accessors
       via  a4d9c87 pyldb: Prevent segfault when first module is NULL
       via  2a29e36 ldb: Build for two Python versions at once
       via  e958385 pyldb: Adapt tests to Python 3
       via  d584d5e pyldb: Split text/byte strings for compatibility with Python 3
       via  0b384f6 pyldb: Modernize test suite
       via  b509cbd pyldb: Add Python 3 compatibility (except strings)
       via  a04cfaa pyldb: DECREF old debug function when resetting it
       via  2e298c1 pyldb: Don't use the internal macro PyObject_REPR
       via  7935796c4 pyldb: Properly increase refcount of returned values
       via  c54fc3f ldb: Run the Python testsuite
       via  9884a8f tevent: version 0.9.26
       via  68077c6 lib: tevent: docs: Add tutorial on thread usage.
       via  a132320 lib: tevent: tests: Add a second thread test that does request/reply.
       via  187aebb lib: tevent: Initial test of tevent threaded context code.
       via  49bddd8 lib: tevent: Initial checkin of threaded tevent context calling code.
       via  bb0050a tdb: version 1.3.8
       via  4f6eb58 talloc: version 2.1.5
      from  fae40ec uwrap: Bump version to 1.2.0

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


- Log -----------------------------------------------------------------
commit 8a40da8184c7b441af3cb3de8253f57704c23c2e
Author: Stefan Metzmacher <metze at samba.org>
Date:   Thu Aug 6 22:59:26 2015 +0200

    ldb: version 1.1.23
    
    * Test improvements
    * Improved python3 bindings
    * Minor build fixes
    
    Signed-off-by: Stefan Metzmacher <metze at samba.org>
    
    Autobuild-User(master): Stefan Metzmacher <metze at samba.org>
    Autobuild-Date(master): Thu Nov  5 21:11:35 CET 2015 on sn-devel-104

commit 0d36d6d84271f97df82a1f0c9c6c6412833575be
Author: Petr Viktorin <pviktori at redhat.com>
Date:   Fri Aug 21 10:22:22 2015 +0200

    pyldb: Improve test coverage
    
    Add tests for:
     - ldb.Dn.{get,set}_{extended_,}component_{name,value}
     - ldb.Dn.{get,set}_rdn_{name,value}
     - ldb.Dn.get_casefold
     - ldb.Dn.get_linearized
     - ldb.Dn.canonical_str
    
    Add negative test for Dn.__contains__
    
    Add a helper function to register a dummy DN extension for testing.
    
    Signed-off-by: Petr Viktorin <pviktori at redhat.com>
    Reviewed-by: Andrew Bartlett <abartlet at samba.org>
    Reviewed-by: Stefan Metzmacher <metze at samba.org>

commit dd7baa2ae2f98d5c1e82fa97f223925025da5ca0
Author: Petr Viktorin <pviktori at redhat.com>
Date:   Fri Aug 21 10:10:28 2015 +0200

    pyldb: Fixes and Python3 compat for Dn component accessors
    
    Use "s#"/"z#" argument specifiers in set_component and
    set_extended_component instead of converting strings manually.
    (Under Python 3, This means both text strings and bytes are accepted.)
    
    Raise error on set_component(None), instead of crashing.
    
    Return text strings from get_{extended}_component under Python 3.
    
    Signed-off-by: Petr Viktorin <pviktori at redhat.com>
    Reviewed-by: Andrew Bartlett <abartlet at samba.org>
    Reviewed-by: Stefan Metzmacher <metze at samba.org>

commit a4d9c87cedeacbf3b4bbb5214a5b76e0def03540
Author: Petr Viktorin <pviktori at redhat.com>
Date:   Fri Aug 21 10:07:17 2015 +0200

    pyldb: Prevent segfault when first module is NULL
    
    Signed-off-by: Petr Viktorin <pviktori at redhat.com>
    Reviewed-by: Andrew Bartlett <abartlet at samba.org>
    Reviewed-by: Stefan Metzmacher <metze at samba.org>

commit 2a29e36e4fc72e7ac460aafbbcf88e0106fb0cf6
Author: Petr Viktorin <pviktori at redhat.com>
Date:   Fri Aug 14 12:43:41 2015 +0200

    ldb: Build for two Python versions at once
    
    Signed-off-by: Petr Viktorin <pviktori at redhat.com>
    Reviewed-by: Andrew Bartlett <abartlet at samba.org>
    Reviewed-by: Stefan Metzmacher <metze at samba.org>

commit e95838591b7d5f66ffde248022136f23eed5bc33
Author: Petr Viktorin <pviktori at redhat.com>
Date:   Wed Jul 29 12:45:43 2015 +0200

    pyldb: Adapt tests to Python 3
    
    Signed-off-by: Petr Viktorin <pviktori at redhat.com>
    Reviewed-by: Andrew Bartlett <abartlet at samba.org>
    Reviewed-by: Stefan Metzmacher <metze at samba.org>

commit d584d5ee2af98cb4874d1a91e3bc092c5941d34b
Author: Petr Viktorin <pviktori at redhat.com>
Date:   Tue Jun 9 17:44:40 2015 +0200

    pyldb: Split text/byte strings for compatibility with Python 3
    
    Compatibility with Python 2, and backwards compatibility on Python 2,
    is kept.
    
    Under Python 3, DNs, attribute names, filters, controls are always text
    (unicode) strings, encoded to/from UTF-8 for storage.
    Attribute values are byte strings.
    
    When creating DNs and attribute values, both text and bytes are accepted.
    This allows creating messages from homogeneous dicts.
    
    LDB Messages and MessageElements have a .text attribute, which offers
    a text view on the contents: any value retrieved from it will be a text
    string. The wrapper is implemented in a new Python module.
    
    Thanks to Stefan Metzmacher for const warning fixes
    
    Signed-off-by: Petr Viktorin <pviktori at redhat.com>
    Signed-off-by: Stefan Metzmacher <metze at samba.org>
    Reviewed-by: Andrew Bartlett <abartlet at samba.org>

commit 0b384f60ddc0d1844f5953a974eb9266ebbdd7bb
Author: Petr Viktorin <pviktori at redhat.com>
Date:   Wed Jun 10 10:21:24 2015 +0200

    pyldb: Modernize test suite
    
    This gets rid of deprecation warnings for the old method names.
    
    Signed-off-by: Petr Viktorin <pviktori at redhat.com>
    Reviewed-by: Andrew Bartlett <abartlet at samba.org>
    Reviewed-by: Stefan Metzmacher <metze at samba.org>

commit b509cbd8fcc7faedf8b66305d68b1cf58c834396
Author: Petr Viktorin <pviktori at redhat.com>
Date:   Tue Jun 9 10:36:26 2015 +0200

    pyldb: Add Python 3 compatibility (except strings)
    
    - Use a macro for adding constants to module
    (This also ensures that the Python constants have the same
    name as the C ones. One existing misspelling is retained.)
    
    - Use new module initialization for Python 3
    
    - Use rich comparison for ldb objects
    
    - Prepare tests for Python 3
    
    Signed-off-by: Petr Viktorin <pviktori at redhat.com>
    Reviewed-by: Andrew Bartlett <abartlet at samba.org>
    Reviewed-by: Stefan Metzmacher <metze at samba.org>

commit a04cfaa179248f4483d4201acb05f02f75130047
Author: Petr Viktorin <pviktori at redhat.com>
Date:   Wed Jun 10 15:40:34 2015 +0200

    pyldb: DECREF old debug function when resetting it
    
    Signed-off-by: Petr Viktorin <pviktori at redhat.com>
    Reviewed-by: Andrew Bartlett <abartlet at samba.org>
    Reviewed-by: Stefan Metzmacher <metze at samba.org>

commit 2e298c131ec3b9e2b4f17fb21536b1d1f7eece73
Author: Petr Viktorin <pviktori at redhat.com>
Date:   Wed Jun 10 15:41:57 2015 +0200

    pyldb: Don't use the internal macro PyObject_REPR
    
    Signed-off-by: Petr Viktorin <pviktori at redhat.com>
    Reviewed-by: Andrew Bartlett <abartlet at samba.org>
    Reviewed-by: Stefan Metzmacher <metze at samba.org>

commit 7935796c4849568948be31d0c00cb0c68828b017
Author: Petr Viktorin <pviktori at redhat.com>
Date:   Thu Jun 11 10:16:48 2015 +0200

    pyldb: Properly increase refcount of returned values
    
    Signed-off-by: Petr Viktorin <pviktori at redhat.com>
    Reviewed-by: Andrew Bartlett <abartlet at samba.org>
    Reviewed-by: Stefan Metzmacher <metze at samba.org>

commit c54fc3f2b6479a5c48d801626fb01f68da6894c7
Author: Petr Viktorin <pviktori at redhat.com>
Date:   Mon Jun 8 14:17:12 2015 +0200

    ldb: Run the Python testsuite
    
    Signed-off-by: Petr Viktorin <pviktori at redhat.com>
    Reviewed-by: Andrew Bartlett <abartlet at samba.org>
    Reviewed-by: Stefan Metzmacher <metze at samba.org>

commit 9884a8fa58ffc8ddff0977c069aedda3beb6415f
Author: Stefan Metzmacher <metze at samba.org>
Date:   Mon Aug 24 15:47:51 2015 +0200

    tevent: version 0.9.26
    
    * New tevent_thread_proxy API
    * Minor build fixes
    
    Signed-off-by: Stefan Metzmacher <metze at samba.org>

commit 68077c617b0a456baea56349fbf502307318c487
Author: Jeremy Allison <jra at samba.org>
Date:   Wed Jul 22 11:52:06 2015 -0700

    lib: tevent: docs: Add tutorial on thread usage.
    
    Signed-off-by: Jeremy Allison <jra at samba.org>
    Signed-off-by: Ralph Boehme <slow at samba.org>

commit a132320b4c434ae9c2188377951d092f7309e63c
Author: Jeremy Allison <jra at samba.org>
Date:   Fri Jul 24 09:27:21 2015 -0700

    lib: tevent: tests: Add a second thread test that does request/reply.
    
    Both tests run cleanly with valgrind --tool=drd and
    valgrind --tool=helgrind
    
    Signed-off-by: Jeremy Allison <jra at samba.org>
    Signed-off-by: Ralph Boehme <slow at samba.org>

commit 187aebb25b970a3679a72109def8e8b85622722e
Author: Jeremy Allison <jra at samba.org>
Date:   Fri Jul 24 08:50:31 2015 -0700

    lib: tevent: Initial test of tevent threaded context code.
    
    Signed-off-by: Jeremy Allison <jra at samba.org>
    Signed-off-by: Ralph Boehme <slow at samba.org>

commit 49bddd8e4756ef52b05b850aec4864749fcf31cb
Author: Jeremy Allison <jra at samba.org>
Date:   Thu Jul 23 15:23:50 2015 -0700

    lib: tevent: Initial checkin of threaded tevent context calling code.
    
    Adds 2 new functions:
    
    struct tevent_thread_proxy *tevent_thread_proxy_create(
                    struct tevent_context *dest_ev_ctx);
    
    void tevent_thread_proxy_schedule(struct tevent_thread_proxy *tp,
    		struct tevent_immediate **pp_im,
    		tevent_immediate_handler_t handler,
    		void *pp_private_data);
    
    Brief doc included. Tests, docs and tutorial to follow.
    
    Signed-off-by: Jeremy Allison <jra at samba.org>
    Signed-off-by: Ralph Boehme <slow at samba.org>
    Reviewed-by: Stefan Metzmacher <metze at samba.org>

commit bb0050a332ceb77382c276d2c8bc3638369c16d0
Author: Stefan Metzmacher <metze at samba.org>
Date:   Mon Aug 24 15:41:33 2015 +0200

    tdb: version 1.3.8
    
    * Fix broken build with --disable-python
    * Minor build fixes
    
    Signed-off-by: Stefan Metzmacher <metze at samba.org>

commit 4f6eb583812adbf6e262d061a4d2bc97e759cc7a
Author: Stefan Metzmacher <metze at samba.org>
Date:   Mon Aug 24 15:47:18 2015 +0200

    talloc: version 2.1.5
    
    * Minor build fixes
    
    Signed-off-by: Stefan Metzmacher <metze at samba.org>

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

Summary of changes:
 buildtools/wafsamba/samba_utils.py                 |   5 +-
 lib/ldb/ABI/{ldb-1.1.22.sigs => ldb-1.1.23.sigs}   |   0
 ...ldb-util-1.1.10.sigs => pyldb-util-1.1.23.sigs} |   0
 ...util-1.1.10.sigs => pyldb-util.py3-1.1.23.sigs} |   0
 lib/ldb/_ldb_text.py                               | 148 +++++
 lib/ldb/pyldb.c                                    | 648 +++++++++++++------
 lib/ldb/pyldb_util.c                               |  21 +-
 lib/ldb/tests/python/api.py                        | 693 ++++++++++++++++-----
 lib/ldb/tests/test-tdb.sh                          |   7 -
 lib/ldb/wscript                                    |  58 +-
 ...oc-util-2.0.6.sigs => pytalloc-util-2.1.5.sigs} |   0
 ...til-2.0.6.sigs => pytalloc-util.py3-2.1.5.sigs} |   1 -
 .../ABI/{talloc-2.1.4.sigs => talloc-2.1.5.sigs}   |   0
 lib/talloc/wscript                                 |   2 +-
 lib/tdb/ABI/{tdb-1.3.5.sigs => tdb-1.3.8.sigs}     |   0
 lib/tdb/wscript                                    |   2 +-
 .../ABI/{tevent-0.9.24.sigs => tevent-0.9.26.sigs} |   2 +
 lib/tevent/doc/tevent_thread.dox                   | 322 ++++++++++
 lib/tevent/doc/tevent_tutorial.dox                 |   2 +
 lib/tevent/testsuite.c                             | 330 ++++++++++
 lib/tevent/tevent.h                                |  52 ++
 lib/tevent/tevent_threads.c                        | 370 +++++++++++
 lib/tevent/wscript                                 |   4 +-
 23 files changed, 2251 insertions(+), 416 deletions(-)
 copy lib/ldb/ABI/{ldb-1.1.22.sigs => ldb-1.1.23.sigs} (100%)
 copy lib/ldb/ABI/{pyldb-util-1.1.10.sigs => pyldb-util-1.1.23.sigs} (100%)
 copy lib/ldb/ABI/{pyldb-util-1.1.10.sigs => pyldb-util.py3-1.1.23.sigs} (100%)
 create mode 100644 lib/ldb/_ldb_text.py
 copy lib/talloc/ABI/{pytalloc-util-2.0.6.sigs => pytalloc-util-2.1.5.sigs} (100%)
 copy lib/talloc/ABI/{pytalloc-util-2.0.6.sigs => pytalloc-util.py3-2.1.5.sigs} (84%)
 copy lib/talloc/ABI/{talloc-2.1.4.sigs => talloc-2.1.5.sigs} (100%)
 copy lib/tdb/ABI/{tdb-1.3.5.sigs => tdb-1.3.8.sigs} (100%)
 copy lib/tevent/ABI/{tevent-0.9.24.sigs => tevent-0.9.26.sigs} (97%)
 create mode 100644 lib/tevent/doc/tevent_thread.dox
 create mode 100644 lib/tevent/tevent_threads.c


Changeset truncated at 500 lines:

diff --git a/buildtools/wafsamba/samba_utils.py b/buildtools/wafsamba/samba_utils.py
index 36d3929..fb1355c 100644
--- a/buildtools/wafsamba/samba_utils.py
+++ b/buildtools/wafsamba/samba_utils.py
@@ -385,7 +385,7 @@ def RUN_COMMAND(cmd,
     return -1
 
 
-def RUN_PYTHON_TESTS(testfiles, pythonpath=None):
+def RUN_PYTHON_TESTS(testfiles, pythonpath=None, extra_env=None):
     env = LOAD_ENVIRONMENT()
     if pythonpath is None:
         pythonpath = os.path.join(Utils.g_module.blddir, 'python')
@@ -393,6 +393,9 @@ def RUN_PYTHON_TESTS(testfiles, pythonpath=None):
     for interp in env.python_interpreters:
         for testfile in testfiles:
             cmd = "PYTHONPATH=%s %s %s" % (pythonpath, interp, testfile)
+            if extra_env:
+                for key, value in extra_env.items():
+                    cmd = "%s=%s %s" % (key, value, cmd)
             print('Running Python test with %s: %s' % (interp, testfile))
             ret = RUN_COMMAND(cmd)
             if ret:
diff --git a/lib/ldb/ABI/ldb-1.1.22.sigs b/lib/ldb/ABI/ldb-1.1.23.sigs
similarity index 100%
copy from lib/ldb/ABI/ldb-1.1.22.sigs
copy to lib/ldb/ABI/ldb-1.1.23.sigs
diff --git a/lib/ldb/ABI/pyldb-util-1.1.10.sigs b/lib/ldb/ABI/pyldb-util-1.1.23.sigs
similarity index 100%
copy from lib/ldb/ABI/pyldb-util-1.1.10.sigs
copy to lib/ldb/ABI/pyldb-util-1.1.23.sigs
diff --git a/lib/ldb/ABI/pyldb-util-1.1.10.sigs b/lib/ldb/ABI/pyldb-util.py3-1.1.23.sigs
similarity index 100%
copy from lib/ldb/ABI/pyldb-util-1.1.10.sigs
copy to lib/ldb/ABI/pyldb-util.py3-1.1.23.sigs
diff --git a/lib/ldb/_ldb_text.py b/lib/ldb/_ldb_text.py
new file mode 100644
index 0000000..f6f1ac0
--- /dev/null
+++ b/lib/ldb/_ldb_text.py
@@ -0,0 +1,148 @@
+# Text wrapper for ldb bindings
+#
+# Copyright (C) 2015 Petr Viktorin <pviktori at redhat.com>
+# Published under the GNU LGPLv3 or later
+
+import sys
+import functools
+
+import ldb
+
+
+def _recursive_encode(obj):
+    if isinstance(obj, bytes):
+        return obj
+    elif isinstance(obj, str):
+        return obj.encode('utf-8')
+    else:
+        return [_recursive_encode(o) for o in obj]
+
+
+class _WrapBase(object):
+
+    @classmethod
+    def _wrap(cls, wrapped):
+        self = cls.__new__(cls)
+        self._wrapped = wrapped
+        return self
+
+    def __len__(self):
+        return len(self._wrapped)
+
+    def __eq__(self, other):
+        if hasattr(other, '_wrapped'):
+            return self._wrapped == other._wrapped
+        else:
+            return self._wrapped == other
+
+    def __ne__(self, other):
+        if hasattr(other, '_wrapped'):
+            return self._wrapped != other._wrapped
+        else:
+            return self._wrapped != other
+
+    def __lt__(self, other):
+        if hasattr(other, '_wrapped'):
+            return self._wrapped < other._wrapped
+        else:
+            return self._wrapped < other
+
+    def __le__(self, other):
+        if hasattr(other, '_wrapped'):
+            return self._wrapped >= other._wrapped
+        else:
+            return self._wrapped >= other
+
+    def __gt__(self, other):
+        if hasattr(other, '_wrapped'):
+            return self._wrapped > other._wrapped
+        else:
+            return self._wrapped > other
+
+    def __ge__(self, other):
+        if hasattr(other, '_wrapped'):
+            return self._wrapped >= other._wrapped
+        else:
+            return self._wrapped >= other
+
+    def __repr__(self):
+        return '%s.text' % repr(self._wrapped)
+
+
+class MessageElementTextWrapper(_WrapBase):
+
+    """Text interface for a LDB message element"""
+
+    def __iter__(self):
+        for item in self._wrapped:
+            yield item.decode('utf-8')
+
+    def __getitem__(self, key):
+        result = self._wrapped[key]
+        if result is None:
+            return None
+        else:
+            return result.decode('utf-8')
+
+    @property
+    def flags(self):
+        return self._wrapped.flags
+
+    @property
+    def set_flags(self):
+        return self._wrapped.set_flags
+
+_wrap_element = MessageElementTextWrapper._wrap
+
+
+class MessageTextWrapper(_WrapBase):
+
+    """Text interface for a LDB message"""
+
+    def __getitem__(self, key):
+        result = self._wrapped[key]
+        if result is None:
+            return None
+        else:
+            return _wrap_element(result)
+
+    def get(self, *args, **kwargs):
+        result = self._wrapped.get(*args, **kwargs)
+        if isinstance(result, ldb.MessageElement):
+            return _wrap_element(result)
+        elif isinstance(result, bytes):
+            return result.decode('utf-8')
+        else:
+            return result
+
+    def __setitem__(self, key, item):
+        self._wrapped[key] = _recursive_encode(item)
+
+    def __delitem__(self, key):
+        del self._wrapped[key]
+
+    def elements(self):
+        return [_wrap_element(el) for el in self._wrapped.elements()]
+
+    def items(self):
+        return [(attr, _wrap_element(el)) for attr, el in self._wrapped.items()]
+
+    @property
+    def keys(self):
+        return self._wrapped.keys
+
+    @property
+    def remove(self):
+        return self._wrapped.remove
+
+    @property
+    def add(self):
+        return self._wrapped.add
+
+    @property
+    def dn(self):
+        return self._wrapped.dn
+
+    @dn.setter
+    def dn(self, new_value):
+        self._wrapped.dn = new_value
diff --git a/lib/ldb/pyldb.c b/lib/ldb/pyldb.c
index 307f426..fff1fee 100644
--- a/lib/ldb/pyldb.c
+++ b/lib/ldb/pyldb.c
@@ -30,6 +30,7 @@
 
 #include <Python.h>
 #include "ldb_private.h"
+#include "ldb_handlers.h"
 #include "pyldb.h"
 
 void initldb(void);
@@ -57,15 +58,51 @@ static struct ldb_message_element *PyObject_AsMessageElement(
 						      unsigned int flags,
 						      const char *attr_name);
 
-/* There's no Py_ssize_t in 2.4, apparently */
-#if PY_MAJOR_VERSION == 2 && PY_MINOR_VERSION < 5
-typedef int Py_ssize_t;
-typedef inquiry lenfunc;
-typedef intargfunc ssizeargfunc;
+#if PY_MAJOR_VERSION >= 3
+#define PyStr_Check PyUnicode_Check
+#define PyStr_FromString PyUnicode_FromString
+#define PyStr_FromStringAndSize PyUnicode_FromStringAndSize
+#define PyStr_FromFormat PyUnicode_FromFormat
+#define PyStr_FromFormatV PyUnicode_FromFormatV
+#define PyStr_AsUTF8 PyUnicode_AsUTF8
+#define PyStr_AsUTF8AndSize PyUnicode_AsUTF8AndSize
+#define PyInt_FromLong PyLong_FromLong
+#else
+#define PyStr_Check PyString_Check
+#define PyStr_FromString PyString_FromString
+#define PyStr_FromStringAndSize PyString_FromStringAndSize
+#define PyStr_FromFormat PyString_FromFormat
+#define PyStr_FromFormatV PyString_FromFormatV
+#define PyStr_AsUTF8 PyString_AsString
+
+const char *PyStr_AsUTF8AndSize(PyObject *pystr, Py_ssize_t *sizeptr);
+const char *
+PyStr_AsUTF8AndSize(PyObject *pystr, Py_ssize_t *sizeptr)
+{
+	const char * ret = PyString_AsString(pystr);
+	if (ret == NULL)
+		return NULL;
+	*sizeptr = PyString_Size(pystr);
+	return ret;
+}
 #endif
 
-#define SIGN(a) (((a) == 0)?0:((a) < 0?-1:1))
-
+static PyObject *richcmp(int cmp_val, int op)
+{
+	int ret;
+	switch (op) {
+		case Py_LT: ret = cmp_val < 0;  break;
+		case Py_LE: ret = cmp_val <= 0; break;
+		case Py_EQ: ret = cmp_val == 0; break;
+		case Py_NE: ret = cmp_val != 0; break;
+		case Py_GT: ret = cmp_val > 0;  break;
+		case Py_GE: ret = cmp_val >= 0; break;
+		default:
+			Py_INCREF(Py_NotImplemented);
+			return Py_NotImplemented;
+	}
+	return PyBool_FromLong(ret);
+}
 
 
 static PyObject *py_ldb_control_str(PyLdbControlObject *self)
@@ -76,9 +113,9 @@ static PyObject *py_ldb_control_str(PyLdbControlObject *self)
 			PyErr_NoMemory();
 			return NULL;
 		}
-		return PyString_FromString(control);
+		return PyStr_FromString(control);
 	} else {
-		return PyString_FromFormat("ldb control");
+		return PyStr_FromString("ldb control");
 	}
 }
 
@@ -91,9 +128,32 @@ static void py_ldb_control_dealloc(PyLdbControlObject *self)
 	Py_TYPE(self)->tp_free(self);
 }
 
+/* Create a text (rather than bytes) interface for a LDB result object */
+static PyObject *wrap_text(const char *type, PyObject *wrapped)
+{
+	PyObject *mod, *cls, *constructor, *inst;
+	mod = PyImport_ImportModule("_ldb_text");
+	if (mod == NULL)
+		return NULL;
+	cls = PyObject_GetAttrString(mod, type);
+	Py_DECREF(mod);
+	if (cls == NULL) {
+		Py_DECREF(mod);
+		return NULL;
+	}
+	constructor = PyObject_GetAttrString(cls, "_wrap");
+	Py_DECREF(cls);
+	if (constructor == NULL) {
+		return NULL;
+	}
+	inst = PyObject_CallFunction(constructor, discard_const_p(char, "O"), wrapped);
+	Py_DECREF(constructor);
+	return inst;
+}
+
 static PyObject *py_ldb_control_get_oid(PyLdbControlObject *self)
 {
-	return PyString_FromString(self->data->oid);
+	return PyStr_FromString(self->data->oid);
 }
 
 static PyObject *py_ldb_control_get_critical(PyLdbControlObject *self)
@@ -191,7 +251,12 @@ static void PyErr_SetLdbError(PyObject *error, int ret, struct ldb_context *ldb_
 
 static PyObject *PyObject_FromLdbValue(const struct ldb_val *val)
 {
-	return PyString_FromStringAndSize((const char *)val->data, val->length);
+	return PyBytes_FromStringAndSize((const char *)val->data, val->length);
+}
+
+static PyObject *PyStr_FromLdbValue(const struct ldb_val *val)
+{
+	return PyStr_FromStringAndSize((const char *)val->data, val->length);
 }
 
 /**
@@ -317,7 +382,7 @@ static PyObject *PyLdbResult_FromResult(struct ldb_result *result)
 	}
 
 	for (i = 0;result->refs && result->refs[i]; i++) {
-		PyList_SetItem(referals, i, PyString_FromString(result->refs[i]));
+		PyList_SetItem(referals, i, PyStr_FromString(result->refs[i]));
 	}
 	ret->referals = referals;
 	return (PyObject *)ret;
@@ -375,22 +440,22 @@ static PyObject *py_ldb_dn_is_null(PyLdbDnObject *self)
  
 static PyObject *py_ldb_dn_get_casefold(PyLdbDnObject *self)
 {
-	return PyString_FromString(ldb_dn_get_casefold(self->dn));
+	return PyStr_FromString(ldb_dn_get_casefold(self->dn));
 }
 
 static PyObject *py_ldb_dn_get_linearized(PyLdbDnObject *self)
 {
-	return PyString_FromString(ldb_dn_get_linearized(self->dn));
+	return PyStr_FromString(ldb_dn_get_linearized(self->dn));
 }
 
 static PyObject *py_ldb_dn_canonical_str(PyLdbDnObject *self)
 {
-	return PyString_FromString(ldb_dn_canonical_string(self->dn, self->dn));
+	return PyStr_FromString(ldb_dn_canonical_string(self->dn, self->dn));
 }
 
 static PyObject *py_ldb_dn_canonical_ex_str(PyLdbDnObject *self)
 {
-	return PyString_FromString(ldb_dn_canonical_ex_string(self->dn, self->dn));
+	return PyStr_FromString(ldb_dn_canonical_ex_string(self->dn, self->dn));
 }
 
 static PyObject *py_ldb_dn_extended_str(PyLdbDnObject *self, PyObject *args, PyObject *kwargs)
@@ -401,7 +466,7 @@ static PyObject *py_ldb_dn_extended_str(PyLdbDnObject *self, PyObject *args, PyO
 					 discard_const_p(char *, kwnames),
 					 &mode))
 		return NULL;
-	return PyString_FromString(ldb_dn_get_extended_linearized(self->dn, self->dn, mode));
+	return PyStr_FromString(ldb_dn_get_extended_linearized(self->dn, self->dn, mode));
 }
 
 static PyObject *py_ldb_dn_get_extended_component(PyLdbDnObject *self, PyObject *args)
@@ -416,28 +481,25 @@ static PyObject *py_ldb_dn_get_extended_component(PyLdbDnObject *self, PyObject
 		Py_RETURN_NONE;
 	}
 
-	return PyString_FromStringAndSize((const char *)val->data, val->length);
+	return PyBytes_FromStringAndSize((const char *)val->data, val->length);
 }
 
 static PyObject *py_ldb_dn_set_extended_component(PyLdbDnObject *self, PyObject *args)
 {
 	char *name;
-	PyObject *value;
 	int err;
+	uint8_t *value;
+	int size = 0;
 
-	if (!PyArg_ParseTuple(args, "sO", &name, &value))
+	if (!PyArg_ParseTuple(args, "sz#", &name, (const char**)&value, &size))
 		return NULL;
 
-	if (value == Py_None) {
+	if (value == NULL) {
 		err = ldb_dn_set_extended_component(self->dn, name, NULL);
 	} else {
 		struct ldb_val val;
-		if (!PyString_Check(value)) {
-			PyErr_SetString(PyExc_TypeError, "Expected a string argument");
-			return NULL;
-		}
-		val.data = (uint8_t *)PyString_AsString(value);
-		val.length = PyString_Size(value);
+		val.data = (uint8_t *)value;
+		val.length = size;
 		err = ldb_dn_set_extended_component(self->dn, name, &val);
 	}
 
@@ -451,7 +513,19 @@ static PyObject *py_ldb_dn_set_extended_component(PyLdbDnObject *self, PyObject
 
 static PyObject *py_ldb_dn_repr(PyLdbDnObject *self)
 {
-	return PyString_FromFormat("Dn(%s)", PyObject_REPR(PyString_FromString(ldb_dn_get_linearized(self->dn))));
+	PyObject *str = PyStr_FromString(ldb_dn_get_linearized(self->dn));
+	PyObject *repr, *result;
+	if (str == NULL)
+		return NULL;
+	repr = PyObject_Repr(str);
+	if (repr == NULL) {
+		Py_DECREF(str);
+		return NULL;
+	}
+	result = PyStr_FromFormat("Dn(%s)", PyStr_AsUTF8(repr));
+	Py_DECREF(str);
+	Py_DECREF(repr);
+	return result;
 }
 
 static PyObject *py_ldb_dn_check_special(PyLdbDnObject *self, PyObject *args)
@@ -464,13 +538,15 @@ static PyObject *py_ldb_dn_check_special(PyLdbDnObject *self, PyObject *args)
 	return PyBool_FromLong(ldb_dn_check_special(self->dn, name));
 }
 
-static int py_ldb_dn_compare(PyLdbDnObject *dn1, PyLdbDnObject *dn2)
+static PyObject *py_ldb_dn_richcmp(PyObject *dn1, PyObject *dn2, int op)
 {
 	int ret;
-	ret = ldb_dn_compare(dn1->dn, dn2->dn);
-	if (ret < 0) ret = -1;
-	if (ret > 0) ret = 1;
-	return ret;
+	if (!pyldb_Dn_Check(dn2)) {
+		Py_INCREF(Py_NotImplemented);
+		return Py_NotImplemented;
+	}
+	ret = ldb_dn_compare(pyldb_Dn_AsDn(dn1), pyldb_Dn_AsDn(dn2));
+	return richcmp(ret, op);
 }
 
 static PyObject *py_ldb_dn_get_parent(PyLdbDnObject *self)
@@ -570,7 +646,7 @@ static PyObject *py_ldb_dn_get_component_name(PyLdbDnObject *self, PyObject *arg
 		Py_RETURN_NONE;
 	}
 
-	return PyString_FromString(name);
+	return PyStr_FromString(name);
 }
 
 static PyObject *py_ldb_dn_get_component_value(PyLdbDnObject *self, PyObject *args)
@@ -589,28 +665,22 @@ static PyObject *py_ldb_dn_get_component_value(PyLdbDnObject *self, PyObject *ar
 		Py_RETURN_NONE;
 	}
 
-	return PyObject_FromLdbValue(val);
+	return PyStr_FromLdbValue(val);
 }
 
 static PyObject *py_ldb_dn_set_component(PyLdbDnObject *self, PyObject *args)
 {
 	unsigned int num = 0;
-	char *name = NULL;
-	PyObject *value = Py_None;
+	char *name = NULL, *value = NULL;
 	struct ldb_val val = { NULL, };
 	int err;
+	Py_ssize_t size = 0;
 
-	if (!PyArg_ParseTuple(args, "IsO", &num, &name, &value))
+	if (!PyArg_ParseTuple(args, "Iss#", &num, &name, &value, &size))
 		return NULL;
 
-	if (value != Py_None) {
-		if (!PyString_Check(value)) {
-			PyErr_SetString(PyExc_TypeError, "Expected a string argument");
-			return NULL;
-		}
-		val.data = (uint8_t *)PyString_AsString(value);
-		val.length = PyString_Size(value);
-	}
+	val.data = (unsigned char*) value;
+	val.length = size;
 
 	err = ldb_dn_set_component(self->dn, num, name, val);
 	if (err != LDB_SUCCESS) {
@@ -633,7 +703,7 @@ static PyObject *py_ldb_dn_get_rdn_name(PyLdbDnObject *self)
 		Py_RETURN_NONE;
 	}
 
-	return PyString_FromString(name);
+	return PyStr_FromString(name);
 }
 
 static PyObject *py_ldb_dn_get_rdn_value(PyLdbDnObject *self)
@@ -648,7 +718,7 @@ static PyObject *py_ldb_dn_get_rdn_value(PyLdbDnObject *self)
 		Py_RETURN_NONE;
 	}
 


-- 
Samba Shared Repository



More information about the samba-cvs mailing list