Built-In Extensions¶
Description Attributes¶
Support for structured description fields.
This implements the common pattern of storing arbitrary key=value data in description fields, but presents an attribute-like interface to access and change them.
Example:
from laurelin.ldap import LDAP
LDAP.activate_extension('laurelin.extensions.descattrs')
with LDAP() as ldap:
result = ldap.base.get_child('cn=someObject')
result.add_desc_attrs({'foo':['one', 'two']})
print(result.format_ldif())
# ...
# description: foo=one
# description: foo=two
# ...
attr_vals = result.desc_attrs().get_attr('foo')
print(attr_vals)
# ['one', 'two']
result.replace_desc_attrs({'foo':['one','two','three']})
result.delete_desc_attrs({'foo':['two']})
attr_vals = result.desc_attrs().get_attr('foo')
print(attr_vals)
# ['one', 'three']
print(result.format_ldif())
# ...
# description: foo=one
# description: foo=three
# ...
-
class
laurelin.ldap.
LDAPObject
[source] The following new methods get bound to
laurelin.ldap.LDAPObject
upon extension activation:-
desc_attrs
()¶ Query the description attribute if unknown and return an
AttrsDict
representing the data stored in the description.Returns: An AttrsDict
representing the data stored in the description.Return type: AttrsDict
-
add_desc_attrs
(attrs_dict)¶ Add new description attributes.
Parameters: attrs_dict (dict(str, list[str]) or AttrsDict) – Dictionary of description attributes to add Return type: None
-
NIS Netgroups¶
-
class
laurelin.ldap.
LDAP
[source] The following new methods get bound to
laurelin.ldap.LDAP
upon extension activation:
-
class
laurelin.ldap.
LDAPObject
[source] The following new methods get bound to
laurelin.ldap.LDAPObject
upon extension activation:
Paged Results¶
RFC 2696 Simple Paged Results Manipulation
This adds a control to support paging results. Use the control keyword paged
with search methods. Returns a cookie
on the page_cookie
response attribute which can be found on the results handle after all paged results have been
received. See example below.
Note: Do not use this extension to simply limit the total number of results. The search methods accept a limit
keyword out of the box for this purpose.
Example usage:
from laurelin.ldap import LDAP
LDAP.activate_extension('laurelin.extensions.pagedresults')
with LDAP() as ldap:
search = ldap.base.search(paged=10)
page1_results = list(search)
search = ldap.base.search(paged=(10, search.page_cookie))
page2_results = list(search)
# ...
if not search.page_cookie:
print('Got all pages')
Note: When getting pages in a loop, you may set the cookie value to an empty string on the first iteration, e.g.:
ldap.base.search(paged=(10, ''))