[python-ldap] LDAPError exceptions

Ondřej Kuzník ondra at mistotebe.net
Thu May 2 12:38:14 EDT 2019


On Tue, Apr 30, 2019 at 01:56:15PM +0200, Ondřej Kuzník wrote:
> Hi,
> I've opened the issue #278 at
> https://github.com/python-ldap/python-ldap/issues/278
> and would like to discuss how/whether to go about doing this.
> 
> I've found some discussions on the list about this[0] but nothing seems
> to have been done in the end?
> 
> The way I see it, the major issue is coming from the fact that each
> exception seems to be a single singleton raised directly from the C
> module. I wonder whether for operation responses, it's not better to
> return the actual message and raise the exception in the Python code
> (with the view of making it optional) which might make it easier to
> actually attach the correct information (msgid, controls, description)
> as well.
> 
> This would really help me progress with an asyncio wrapper I've started
> working on (which might eventually help making the syncrepl consumer a
> better citizen as well).
> 
> Any thoughts?

I've now gone ahead and created a preliminary series of patches to
support this: https://github.com/mistotebe/python-ldap/tree/exceptions

Most of the work should be uncontroversial but the last commit, where
I've made it possible to avoid exceptions if the user wants to deal with
the requests on their own. The main problem there is twofold:
1. result4 has no way to pass the result code back to the caller
2. The module doesn't currently provide names for the result codes, as
  they are used by the exceptions.

For the latter, a fix might either be to expose the return codes in a
separate module or just let the exception types also have numeric
values associated with them.

The former is a bit tricky and I'd like to avoid things like result5(),
since at some point we might need result6() and so on. One option is to
make a result-like function that returns a dictionary/namedtuple or
something else that's easy to extend in the future?

Regards,

-- 
Ondřej Kuzník
Senior Software Engineer
Symas Corporation                              https://www.symas.com/
Packaged, certified, and supported LDAP solutions powered by OpenLDAP


More information about the python-ldap mailing list