diff --git a/CHANGES b/CHANGES index 9084485..4ebc8ce 100644 --- a/CHANGES +++ b/CHANGES @@ -10,6 +10,8 @@ Lib/ * LDAPObject.unbind_ext() now removes class attribute LDAPObject._l to completely invalidate C wrapper object * LDAPObject.unbind_ext() now flushes trace file +* ldap.ldapobject.SimpleLDAPObject: + added convenience methods read_rootdse_s() and get_naming_contexts() * added functions ldap.strf_secs() and ldap.strp_secs() * added function ldap.filter.time_span_filter() * Refactored ldif.LDIFParser @@ -1270,4 +1272,4 @@ Released 2.0.0pre02 2002-02-01 ---------------------------------------------------------------- Released 1.10alpha3 2000-09-19 -$Id: CHANGES,v 1.385 2016/07/24 16:05:28 stroeder Exp $ +$Id: CHANGES,v 1.386 2016/07/24 16:24:44 stroeder Exp $ diff --git a/Lib/ldap/ldapobject.py b/Lib/ldap/ldapobject.py index 94b7a90..13ea9e5 100644 --- a/Lib/ldap/ldapobject.py +++ b/Lib/ldap/ldapobject.py @@ -3,7 +3,7 @@ See http://www.python-ldap.org/ for details. -\$Id: ldapobject.py,v 1.155 2016/07/17 14:49:22 stroeder Exp $ +\$Id: ldapobject.py,v 1.156 2016/07/24 16:22:32 stroeder Exp $ Compability: - Tested with Python 2.0+ but should work with Python 1.5.x @@ -745,6 +745,26 @@ def find_unique_entry(self,base,scope=ldap.SCOPE_SUBTREE,filterstr='(objectClass raise NO_UNIQUE_ENTRY('No or non-unique search result for %s' % (repr(filterstr))) return r[0] + def read_rootdse_s(self, filterstr='(objectClass=*)', attrlist=None): + """ + convenience wrapper around read_s() for reading rootDSE + """ + ldap_rootdse = self.read_s( + '', + filterstr=filterstr, + attrlist=attrlist or ['*', '+'], + ) + return ldap_rootdse # read_rootdse_s() + + def get_naming_contexts(self): + """ + returns all attribute values of namingContexts in rootDSE + if namingContexts is not present (not readable) then empty list is returned + """ + return self.read_rootdse_s( + attrlist=['namingContexts'] + ).get('namingContexts', []) + class NonblockingLDAPObject(SimpleLDAPObject):