[Zope-CVS] SVN: ldapadapter/trunk/utility.py Partial checkin.
Florent Guillaume
fg at nuxeo.com
Sat Oct 9 09:46:57 EDT 2004
Log message for revision 27827:
Partial checkin.
Changed:
U ldapadapter/trunk/utility.py
-=-
Modified: ldapadapter/trunk/utility.py
===================================================================
--- ldapadapter/trunk/utility.py 2004-10-09 13:39:27 UTC (rev 27826)
+++ ldapadapter/trunk/utility.py 2004-10-09 13:46:57 UTC (rev 27827)
@@ -19,6 +19,9 @@
import ldap
from ldap import OPT_PROTOCOL_VERSION
from ldap import VERSION3
+from ldap import SCOPE_BASE
+from ldap import SCOPE_ONELEVEL
+from ldap import SCOPE_SUBTREE
from persistent import Persistent
@@ -28,6 +31,12 @@
from interfaces import ILDAPAdapter
from interfaces import ILDAPConnection
+SCOPES = {'base': SCOPE_BASE,
+ 'one': SCOPE_ONELEVEL,
+ 'sub': SCOPE_SUBTREE,
+ }
+def convertScope(scope):
+ return SCOPES[scope]
class LDAPAdapter(object):
implements(ILDAPAdapter)
@@ -62,19 +71,36 @@
def __init__(self, conn):
self.conn = conn
- def search(self, base, scope='one', filter='(objectclass=*)',
+ def add(self, dn, entry):
+ attrs_list = entry.items()
+ dn = dn.encode('utf-8')
+ self.conn.add_s(dn, attrs_list)
+
+ def delete(self, dn):
+ dn = dn.encode('utf-8')
+ self.conn.del_s(dn)
+
+ def modify(self, dn, entry):
+ # Get current entry
+ pass
+
+ def search(self, base, scope='sub', filter='(objectClass=*)',
attrs=None):
- # XXX convert from unicode to utf-8
- ldap_entries = conn.search_s(base, scope, filter, attrs)
+ # Convert from unicode to utf-8.
+ base = base.encode('utf-8')
+ scope = convertScope(scope)
+ # XXX convert filter
+ ldap_entries = self.conn.search_s(base, scope, filter, attrs)
# May raise NO_SUCH_OBJECT, SERVER_DOWN, SIZELIMIT_EXCEEDED
- # Convert returned values from utf-8 to unicode
+ # Convert returned values from utf-8 to unicode.
results = []
for dn, entry in ldap_entries:
dn = unicode(dn, 'utf-8')
- for key, values in entry:
+ for key, values in entry.items():
# TODO: Can key be non-ascii? Check LDAP spec.
# FIXME: there may be non-textual binary values.
values[:] = [unicode(v, 'utf-8') for v in values]
results.append((dn, entry))
return results
+
More information about the Zope-CVS
mailing list