diff options
author | Jan Cholasta <jcholast@redhat.com> | 2013-12-10 11:38:12 +0100 |
---|---|---|
committer | Petr Viktorin <pviktori@redhat.com> | 2014-01-10 14:41:39 +0100 |
commit | c98cff25ab30b4c033876bad5eee048ee569bae4 (patch) | |
tree | f8ef9d2bec94b3386800cae52a86a590a4933b3a | |
parent | 24d85f15ee886d8704438045cb0e3568f59a831a (diff) | |
download | freeipa-c98cff25ab30b4c033876bad5eee048ee569bae4.tar.gz freeipa-c98cff25ab30b4c033876bad5eee048ee569bae4.tar.xz freeipa-c98cff25ab30b4c033876bad5eee048ee569bae4.zip |
Move LDAPClient method get_single_value to IPASimpleLDAPObject.
Refactor IPASimpleLDAPObject methods get_syntax and get_single_value.
https://fedorahosted.org/freeipa/ticket/3488
-rw-r--r-- | ipapython/ipaldap.py | 48 |
1 files changed, 30 insertions, 18 deletions
diff --git a/ipapython/ipaldap.py b/ipapython/ipaldap.py index 44b49ecf8..2ec5baa7a 100644 --- a/ipapython/ipaldap.py +++ b/ipapython/ipaldap.py @@ -323,21 +323,23 @@ class IPASimpleLDAPObject(object): self._schema = None def get_syntax(self, attr): + if isinstance(attr, unicode): + attr = attr.encode('utf-8') + # Is this a special case attribute? - syntax = self._SCHEMA_OVERRIDE.get(attr) - if syntax is not None: - return syntax + if attr in self._SCHEMA_OVERRIDE: + return self._SCHEMA_OVERRIDE[attr] if self.schema is None: return None # Try to lookup the syntax in the schema returned by the server obj = self.schema.get_obj(ldap.schema.AttributeType, attr) - if obj is not None: - return obj.syntax - else: + if obj is None: return None + return obj.syntax + def has_dn_syntax(self, attr): """ Check the schema to see if the attribute uses DN syntax. @@ -347,6 +349,27 @@ class IPASimpleLDAPObject(object): syntax = self.get_syntax(attr) return syntax == DN_SYNTAX_OID + def get_single_value(self, attr): + """ + Check the schema to see if the attribute is single-valued. + + If the attribute is in the schema then returns True/False + + If there is a problem loading the schema or the attribute is + not in the schema return None + """ + if isinstance(attr, unicode): + attr = attr.encode('utf-8') + + if self.schema is None: + return None + + obj = self.schema.get_obj(ldap.schema.AttributeType, attr) + if obj is None: + return None + + return obj.single_value + def encode(self, val): """ @@ -1186,18 +1209,7 @@ class LDAPClient(object): return [unicode(a).lower() for a in list(set(allowed_attributes))] def get_single_value(self, attr): - """ - Check the schema to see if the attribute is single-valued. - - If the attribute is in the schema then returns True/False - - If there is a problem loading the schema or the attribute is - not in the schema return None - """ - if self.schema is None: - return None - obj = self.schema.get_obj(ldap.schema.AttributeType, attr) - return obj and obj.single_value + return self.conn.get_single_value(attr) def make_dn_from_attr(self, attr, value, parent_dn=None): """ |