Skip to content

Commit

Permalink
New mix-in class ldap.controls.openldap.SearchNoOpMixIn adds convienc…
Browse files Browse the repository at this point in the history
…e method noop_search_st() to LDAPObject class
  • Loading branch information
stroeder committed Jun 22, 2015
1 parent e5f5fb7 commit 086e689
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 2 deletions.
4 changes: 3 additions & 1 deletion CHANGES
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@ Lib/
and parse_change_records()
- Stricter order checking of dn:, changetype:, etc.
- Removed non-existent 'AttrTypeandValueLDIF' from ldif.__all__
* New mix-in class ldap.controls.openldap.SearchNoOpMixIn
adds convience method noop_search_st() to LDAPObject class

----------------------------------------------------------------
Released 2.4.19 2015-01-10
Expand Down Expand Up @@ -1168,4 +1170,4 @@ Released 2.0.0pre02 2002-02-01
----------------------------------------------------------------
Released 1.10alpha3 2000-09-19

$Id: CHANGES,v 1.345 2015/06/21 19:08:16 stroeder Exp $
$Id: CHANGES,v 1.346 2015/06/22 11:51:07 stroeder Exp $
35 changes: 34 additions & 1 deletion Lib/ldap/controls/openldap.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
See http://www.python-ldap.org/ for project details.
$Id: openldap.py,v 1.1 2013/07/05 16:57:25 stroeder Exp $
$Id: openldap.py,v 1.2 2015/06/22 11:51:07 stroeder Exp $
"""

import ldap.controls
Expand Down Expand Up @@ -42,3 +42,36 @@ def decodeControlValue(self,encodedControlValue):

ldap.controls.KNOWN_RESPONSE_CONTROLS[SearchNoOpControl.controlType] = SearchNoOpControl


class SearchNoOpMixIn:
"""
Mix-in class to be used with class LDAPObject and friends.
It adds a convenience method noop_search_st() to LDAPObject
for easily using the no-op search control.
"""

def noop_search_st(self,base,scope=ldap.SCOPE_SUBTREE,filterstr='(objectClass=*)',timeout=-1):
try:
msg_id = self.search_ext(
base,
scope,
filterstr=filterstr,
attrlist=['1.1'],
timeout=timeout,
serverctrls=[SearchNoOpControl(criticality=True)],
)
_,_,_,search_response_ctrls = self.result3(msg_id,all=1,timeout=timeout)
except LDAPLimitErrors,e:
self.abandon(msg_id)
raise e
else:
noop_srch_ctrl = [
c
for c in search_response_ctrls
if c.controlType==SearchNoOpControl.controlType
]
if noop_srch_ctrl:
return noop_srch_ctrl[0].numSearchResults,noop_srch_ctrl[0].numSearchContinuations
else:
return (None,None)

0 comments on commit 086e689

Please sign in to comment.