Package ldaptor :: Package protocols :: Package ldap :: Module fetchschema
[hide private]
[frames] | no frames]

Source Code for Module ldaptor.protocols.ldap.fetchschema

 1  from ldaptor.protocols.ldap import ldaperrors, ldapsyntax 
 2  from ldaptor.protocols import pureldap 
 3  from ldaptor import schema 
 4   
5 -def _fetchCb(subschemaSubentry, client):
6 o=ldapsyntax.LDAPEntry(client=client, 7 dn=subschemaSubentry) 8 d=o.search(scope=pureldap.LDAP_SCOPE_baseObject, 9 sizeLimit=1, 10 attributes=["attributeTypes", "objectClasses"]) 11 def handleSearchResults(l): 12 if len(l)==0: 13 raise ldaperrors.LDAPOther, "No such DN" 14 elif len(l)==1: 15 o=l[0] 16 17 attributeTypes = [] 18 objectClasses = [] 19 for text in o.get("attributeTypes", []): 20 attributeTypes.append(schema.AttributeTypeDescription(str(text))) 21 for text in o.get("objectClasses", []): 22 objectClasses.append(schema.ObjectClassDescription(str(text))) 23 assert attributeTypes, "LDAP server doesn't give attributeTypes for subschemaSubentry dn=%s"%o.dn 24 return (attributeTypes, objectClasses) 25 else: 26 raise ldaperrors.LDAPOther, "DN matched multiple entries"
27 d.addCallback(handleSearchResults) 28 return d 29
30 -def fetch(client, baseObject):
31 o=ldapsyntax.LDAPEntry(client=client, 32 dn=baseObject) 33 d=o.search(scope=pureldap.LDAP_SCOPE_baseObject, 34 sizeLimit=1, 35 attributes=["subschemaSubentry"]) 36 37 def handleSearchResults(l): 38 if len(l)==0: 39 raise ldaperrors.LDAPOther, "No such DN" 40 elif len(l)==1: 41 o=l[0] 42 assert "subschemaSubentry" in o, "No subschemaSubentry. TODO" 43 subSchemas = o["subschemaSubentry"] 44 assert len(subSchemas)==1, "More than one subschemaSubentry is not support yet. TODO" 45 for s in subSchemas: 46 return s 47 else: 48 raise ldaperrors.LDAPOther, "DN matched multiple entries"
49 50 d.addCallback(handleSearchResults) 51 d.addCallback(_fetchCb, client) 52 return d 53