From 086e68976bf420b9e93a63c5c1986543b219844f Mon Sep 17 00:00:00 2001 From: stroeder Date: Mon, 22 Jun 2015 11:51:07 +0000 Subject: [PATCH] New mix-in class ldap.controls.openldap.SearchNoOpMixIn adds convience method noop_search_st() to LDAPObject class --- CHANGES | 4 +++- Lib/ldap/controls/openldap.py | 35 ++++++++++++++++++++++++++++++++++- 2 files changed, 37 insertions(+), 2 deletions(-) diff --git a/CHANGES b/CHANGES index f258e7e..7d2886c 100644 --- a/CHANGES +++ b/CHANGES @@ -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 @@ -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 $ diff --git a/Lib/ldap/controls/openldap.py b/Lib/ldap/controls/openldap.py index a8ed001..62b6a5d 100644 --- a/Lib/ldap/controls/openldap.py +++ b/Lib/ldap/controls/openldap.py @@ -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 @@ -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)