Core

This is core of pyldap_orm.

class pyldap_orm.core.LDAPModelList(session=None)

Manages a list of LDAPObject instances.

Parameters:session (LDAPSession) – An optional instance of LDAPSession.
by_attr(attr, value, attributes=None, serverctrls=None)

Search an object of class cls by adding a LDAP filter (&(..)(attr=value))

Parameters:
  • attr – Attribute to search
  • value – Attribute value
  • attributes – An optional array of the expected attributes returned by the search
  • serverctrls – An optional array with attributes to request server side sorting
Returns:

A list of self.children

Return type:

list

class pyldap_orm.core.LDAPObject(session)

LDAPObject is one of the core class of the ORM. It represent an LDAP object.

Parameters:session (LDAPSession) – an optional LDAPSession instance used to perform operations on a LDAP server.
attributes()

Return the list of attributes existing for the current instance

Returns:List of attributes
Return type:list
by_attr(attr, value, attributes=None)

Search an object by adding a LDAP filter (&(..)(attr=value), where (..) is the search attribute model filter, like ‘(objectClass=inetOrgPerson)’ for a user.

Parameters:
  • attr – Attribute to search, like uid, givenName, etc.
  • value – Attribute value
  • attributes – Optional array of attributes to returned, if none, all standard attributes are returned.
Returns:

an instance of class cls

by_dn(dn, attributes=None)

Request an object by its DN.

Parameters:
  • dn – DN of the LDAP object to query
  • attributes – Optional array of attributes to returned, if none, all standard attributes are returned.
Returns:

An instance of current LDAPObject inheritance

check()

Override this method to perform post operations like remove unwanted values or perform some business checks.

For example, if you want to remove groups that doesn’t belong to your LDAPGroup.base you can use the following code:

for group in getattr(self, self.membership_attribute):
    if LDAPGroup.base not in group:
    getattr(self, self.membership_attribute).remove(group)
classmethod filter()

Compute the filter regarding given required_attributes and required_objectclasses class attributes.

Returns:A string that hold the LDAP filter.
parse(entry)

This method fill attributes and dn of current instance.

Then, the _check function is called to make some tests, like test if each required_attributes are present.

Parameters:entry – a LDAP entry
parse_single(entries)

Parse the first entry of entries by calling parse instance method.

Parameters:entries (list) –
Returns:
save()

This method is a little magic. Depending on the object state you called it, it can create or update an existing object.

There is even more magic when you create a new object. If the _dn attribute is not set (None), it will be computed from the name_attribute, and the base.

If there is no objectClass defined, the required_objectclasses will be used.

Last, verify that all attributes from required_attributes exists.