From 9b6aabb9586994c70597a12fff6518023dc65f2d Mon Sep 17 00:00:00 2001 From: KOVACS Krisztian Date: Fri, 5 Jun 2020 18:44:50 +0200 Subject: [PATCH 1/2] Tests and documentation for msgid for exceptions raised from result4() --- Doc/reference/ldap.rst | 8 ++++++++ Tests/t_ldapobject.py | 14 ++++++++++++++ 2 files changed, 22 insertions(+) diff --git a/Doc/reference/ldap.rst b/Doc/reference/ldap.rst index f4381212..ce30ed95 100644 --- a/Doc/reference/ldap.rst +++ b/Doc/reference/ldap.rst @@ -329,6 +329,14 @@ The module defines the following exceptions: is set to a truncated form of the name provided or alias dereferenced for the lowest entry (object or alias) that was matched. + For use in asynchronous operations an optional field :py:const:`msg_id` is + also set in the dictionary in cases where the exception can be associated + with a request. This can be used in asynchronous code where + :py:meth:`result()` returns an exception that is effectively the result of a + previously started asynchronous operation. For example, this is the case for + asynchronous (:py:meth:`compare()`), where the boolean result is always + raised as an exception (:py:exc:`COMPARE_TRUE` or :py:exc:`COMPARE_FALSE`). + Most exceptions from protocol results also carry the :py:attr:`errnum` attribute. diff --git a/Tests/t_ldapobject.py b/Tests/t_ldapobject.py index a64b5f0c..24711b21 100644 --- a/Tests/t_ldapobject.py +++ b/Tests/t_ldapobject.py @@ -673,6 +673,20 @@ def test_compare_s_invalidattr(self): with self.assertRaises(ldap.UNDEFINED_TYPE): result = l.compare_s('cn=Foo1,%s' % base, 'invalidattr', b'invalid') + def test_compare_true_exception_contains_message_id(self): + base = self.server.suffix + l = self._ldap_conn + msgid = l.compare('cn=Foo1,%s' % base, 'cn', b'Foo1') + with self.assertRaises(ldap.COMPARE_TRUE) as cm: + l.result() + self.assertEqual(cm.exception.args[0]["msgid"], msgid) + + def test_async_search_no_such_object_exception_contains_message_id(self): + msgid = self._ldap_conn.search("CN=XXX", ldap.SCOPE_SUBTREE) + with self.assertRaises(ldap.NO_SUCH_OBJECT) as cm: + self._ldap_conn.result() + self.assertEqual(cm.exception.args[0]["msgid"], msgid) + class Test01_ReconnectLDAPObject(Test00_SimpleLDAPObject): """ From e2bcd627830f0eb4a2900045b84375d32fa04868 Mon Sep 17 00:00:00 2001 From: Petr Viktorin Date: Fri, 5 Jun 2020 18:47:42 +0200 Subject: [PATCH 2/2] Reword the msgid documentation to make it terser --- Doc/reference/ldap.rst | 13 ++++++------- 1 file changed, 6 insertions(+), 7 deletions(-) diff --git a/Doc/reference/ldap.rst b/Doc/reference/ldap.rst index ce30ed95..799afe14 100644 --- a/Doc/reference/ldap.rst +++ b/Doc/reference/ldap.rst @@ -329,13 +329,12 @@ The module defines the following exceptions: is set to a truncated form of the name provided or alias dereferenced for the lowest entry (object or alias) that was matched. - For use in asynchronous operations an optional field :py:const:`msg_id` is - also set in the dictionary in cases where the exception can be associated - with a request. This can be used in asynchronous code where - :py:meth:`result()` returns an exception that is effectively the result of a - previously started asynchronous operation. For example, this is the case for - asynchronous (:py:meth:`compare()`), where the boolean result is always - raised as an exception (:py:exc:`COMPARE_TRUE` or :py:exc:`COMPARE_FALSE`). + The field :py:const:`msgid` is set in the dictionary where the + exception can be associated with an asynchronous request. + This can be used in asynchronous code where :py:meth:`result()` raises the + result of an operation as an exception. For example, this is the case for + :py:meth:`compare()`, always raises the boolean result as an exception + (:py:exc:`COMPARE_TRUE` or :py:exc:`COMPARE_FALSE`). Most exceptions from protocol results also carry the :py:attr:`errnum` attribute.