LDAP/LDIF Parsing

Cruelemort ian.inglis at gmail.com
Fri Feb 2 04:34:42 EST 2007


On Feb 1, 11:08 pm, "aspineux" <aspin... at gmail.com> wrote:
> The tree hierarchy is defined by the DN of each object, the types of
> the object is specified by its objectClass.
> Just collect all items (or do it dynamically by tunning the scope and
> the base of your search request)
>
> On 1 fév, 18:22, "Cruelemort" <ian.ing... at gmail.com> wrote:
>
>
>
> > All,
>
> > I am hoping someone would be able to help me with a problem. I have an
> > LDAP server running on a linux box, this LDAP server contains a
> > telephone list in various groupings, the ldif file of which is -
>
> > dn: dc=example,dc=com
> > objectClass: top
> > objectClass: dcObject
> > objectClass: organization
> > dc: example
> > o: Example Organisation
>
> > dn: ou=groupa,dc=example,dc=com
> > ou: groupa
> > objectClass: top
> > objectClass: organizationalUnit
> > description: Group A
>
> > dn: cn=johnsmith,ou=groupa,dc=example,dc=com
> > cn: johnsmith
> > objectClass: top
> > objectClass: person
> > sn: Smith
> > telephoneNumber: 112
>
> > dn: cn=davesteel,ou=groupa,dc=example,dc=com
> > cn: davesteel
> > objectClass: top
> > objectClass: person
> > sn: Steel
> > telephoneNumber: 113
>
> > dn: ou=groupb,dc=example,dc=com
> > ou: groupb
> > objectClass: top
> > objectClass: organizationalUnit
> > description: Group B
>
> > dn: cn=williamdavis,ou=groupb,dc=example,dc=com
> > cn: williamdavis
> > objectClass: top
> > objectClass: person
> > sn: Davis
> > telephoneNumber: 122
>
> > dn: cn=jamesjarvis,ou=groupb,dc=example,dc=com
> > cn: jamesjarvis
> > objectClass: top
> > objectClass: person
> > sn: Jarvis
> > telephoneNumber: 123
>
> > I am creating a python client program that will display the telephone
> > list in the same directory structure as is on the LDAP server (i.e. it
> > starts with buttons of all the groups, when you click on a group it
> > comes up with buttons of all the numbers or groups available, and you
> > can continually drill down).
>
> > I was wondering the best way to do this? I have installed and used the
> > python-ldap libraries and these allow me to access and search the
> > server, but the searches always return a horrible nesting of lists,
> > tuples and dictionaries, below is an example of returning just one
> > record -
>
> > ('dc=example,dc=com', {'objectClass': ['top', 'dcObject',
> > 'organization'], 'dc': ['example'], 'o': ['Example Organisation']})
>
> > Basically i think i need to parse the search results to create objects
> > and build the python buttons around this, but i was hoping someone
> > would be able to point me in the correct direction of how to do this?
> > Is there a parser available? (there is an ldif library available but
> > it is not obvious how this works, i cannot see much documentation, and
> > it seems to be deprecated...).
>
> > Many thanks.
>
> > Ian- Hide quoted text -
>
> - Show quoted text -

Thanks for the replies all - it was a higher level wrapper like Bruno
mentioned that i was looking for (with objects and attributes based on
each objectClass), but the code posted above will work fine.

Many thanks all.

Ian




More information about the Python-list mailing list