summaryrefslogtreecommitdiff
path: root/pykolab/utils.py
diff options
context:
space:
mode:
authorJeroen van Meeuwen (Kolab Systems) <vanmeeuwen@kolabsys.com>2011-11-16 00:51:17 (GMT)
committerJeroen van Meeuwen (Kolab Systems) <vanmeeuwen@kolabsys.com>2011-11-16 00:51:17 (GMT)
commit31405a32477129f1f8a1a916ffb90b790aaf8949 (patch)
tree6c95830b1003290fb00d3b02201f4325a493b0f6 /pykolab/utils.py
parentf82c7350cd4f0257ab22cbcf0cb6523ba500ff81 (diff)
downloadpykolab-31405a32477129f1f8a1a916ffb90b790aaf8949.tar.gz
Add utils.parse_ldap_uri(uri) to parse memberUrl and other LDAP references with
Diffstat (limited to 'pykolab/utils.py')
-rw-r--r--pykolab/utils.py40
1 files changed, 40 insertions, 0 deletions
diff --git a/pykolab/utils.py b/pykolab/utils.py
index 64be4b8..d787eab 100644
--- a/pykolab/utils.py
+++ b/pykolab/utils.py
@@ -157,6 +157,46 @@ def parse_input(_input, splitchars= [ ' ' ]):
return _output_list
+def parse_ldap_uri(uri):
+ """
+ Parse an LDAP URI and return it's components.
+
+ Returns a tuple containing;
+
+ - protocol (ldap, ldaps),
+ - server (address or None),
+ - base_dn,
+ - attrs (list of attributes length 1, or empty),
+ - scope,
+ - filter
+
+ or None on failure
+ """
+
+ try:
+ _protocol = uri.split(':')[0]
+ _ldap_uri, _attr, _scope, _filter = uri.split('?')
+ _server = _ldap_uri.split('//')[1].split('/')[0]
+ _base_dn = _ldap_uri.split('//')[1].split('/')[1]
+
+ if _server == '':
+ _server = None
+ if _attr == '':
+ _attrs = []
+ else:
+ _attrs = [ _attr ]
+
+ if _scope == '':
+ _scope = 'sub'
+
+ if _filter == '':
+ _filter = "(objectclass=*)"
+
+ return (_protocol, _server, _base_dn, _attr, _scope, _filter)
+
+ except:
+ return None
+
def pop_empty_from_list(_input_list):
_output_list = []