Friday, April 25, 2014

How To: Python LDIF package stops parsing upon error - how to get around this

Python LDIF package stops when user dn does not meet internal regex for dn. While this is great, the problem is when you just want to get the record - good or bad for other purposes than to push it into LDAP etc.
It is simple to override the 'is_dn' method used by the ldif package by setting the package method like so:
import ldif

def is_dn(s):
    return 1

ldif.is_dn=is_dn
 
That is it. From this point on ldif package will use the new is_dn() method and will not fail on invalid dns.

No comments:

Post a Comment