We are using python-ldap to talk to a Windows Active
Directory server, and trying to query for the
This attribute contains binary data, but that data is
not escaped by ldap.filter.escape_filter_chars.
The existing code takes RFC2254 quite literally.
However, the RFC also states "Other characters besides
the ones listed above may be escaped using this
mechanism, for example, non-printing characters."
The following implementation of escape_filter_chars
seems to solve this problem and still conform to the RFC.
Replace all special characters found in assertion_value
by quoted notation
r = 
for c in assertion_value:
if c < '0' or c > 'z' or c in "\\*()":
c = "\\%02x" % ord(c)