[python-ldap] LDIF corner-cases (was: ANN: python-ldap 2.4.26)

Michael Ströder michael at stroeder.com
Wed Jul 27 05:37:18 EDT 2016


Michael Ströder wrote:
> Benjamin Dauvergne wrote:
>> I have a problem with the new LDIF parser, the following LDIF fixture (it's part
>> of tests of an LDAP connector) used to be parsed correctly:
>>
>> '''dn: uid=john.doe,o=orga
>> objectClass: inetOrgPerson
>> cn: John Doe
>> sn: Doe
>> mail: john.doe at example.com
>> uid: john.doe
>> uid: john.doe at entrouvert.com
>> '''
>>
>> now I need to feed this, i.e. I need two new lines at the end of the file:
>>
>> '''dn: uid=john.doe,o=orga
>> objectClass: inetOrgPerson
>> cn: John Doe
>> sn: Doe
>> mail: john.doe at example.com
>> uid: john.doe
>> uid: john.doe at entrouvert.com
>>
>> '''
> 
> Which exact error do you get?
> 
>> Was my fixture already not conformant or is the modified parser in 2.4.26 broken
> 
> Hmm, not sure about that. If I produce LDIF I always add the trailing empty line
> to please all the LDIF parsers out there. But I couldn't find language in RFC
> 2849 which makes that mandatory.
> 
> I'm currently looking into this and I'm not sure about the use of
> 
> textwrap.dedent(ldif_string).lstrip() + '\n'
> 
> in TestLDIFParser.check_records(). For sake of readability it seems to be too
> magic missing some of those corner-cases.

I've added a test-case to Tests/t_ldif.py for this and removed the new-line
magic in TestLDIFParser.check_records().

Note sure about all that. Someone could also argue that the parser should be
liberal enough to accept a single record like this:

'''dn: uid=john.doe,o=orga
objectClass: inetOrgPerson
cn: John Doe
sn: Doe
mail: john.doe at example.com
uid: john.doe
uid: john.doe at entrouvert.com'''

Ummpf! My spare time is very limited and I already spent too much time pleasing
broken LDIF generators. Also handling all these corner-cases makes the parser
slower...

Ciao, Michael.


-------------- next part --------------
A non-text attachment was scrubbed...
Name: smime.p7s
Type: application/pkcs7-signature
Size: 4245 bytes
Desc: S/MIME Cryptographic Signature
URL: <http://mail.python.org/pipermail/python-ldap/attachments/20160727/f764b3dc/attachment.bin>


More information about the python-ldap mailing list