mirror of
https://salsa.debian.org/freeipa-team/freeipa.git
synced 2025-02-25 18:55:28 -06:00
Replace get_syntax method of IPASimpleObject with new get_type method.
get_type returns the Python type for an LDAP attribute. Reviewed-By: Tomas Babej <tbabej@redhat.com>
This commit is contained in:
parent
8b6dc819d5
commit
b4860d09b4
@ -252,9 +252,9 @@ class IPASimpleLDAPObject(object):
|
|||||||
# FWIW, many entries under cn=config are undefined :-(
|
# FWIW, many entries under cn=config are undefined :-(
|
||||||
|
|
||||||
_SYNTAX_OVERRIDE = CIDict({
|
_SYNTAX_OVERRIDE = CIDict({
|
||||||
'managedtemplate': DN_SYNTAX_OID, # DN
|
'managedtemplate': DN,
|
||||||
'managedbase': DN_SYNTAX_OID, # DN
|
'managedbase': DN,
|
||||||
'originscope': DN_SYNTAX_OID, # DN
|
'originscope': DN,
|
||||||
})
|
})
|
||||||
_SINGLE_VALUE_OVERRIDE = CIDict({
|
_SINGLE_VALUE_OVERRIDE = CIDict({
|
||||||
'nsslapd-ssl-check-hostname': True,
|
'nsslapd-ssl-check-hostname': True,
|
||||||
@ -334,7 +334,7 @@ class IPASimpleLDAPObject(object):
|
|||||||
self._has_schema = False
|
self._has_schema = False
|
||||||
self._schema = None
|
self._schema = None
|
||||||
|
|
||||||
def get_syntax(self, attr):
|
def get_type(self, attr):
|
||||||
if isinstance(attr, unicode):
|
if isinstance(attr, unicode):
|
||||||
attr = attr.encode('utf-8')
|
attr = attr.encode('utf-8')
|
||||||
|
|
||||||
@ -343,14 +343,14 @@ class IPASimpleLDAPObject(object):
|
|||||||
return self._SYNTAX_OVERRIDE[attr]
|
return self._SYNTAX_OVERRIDE[attr]
|
||||||
|
|
||||||
if self.schema is None:
|
if self.schema is None:
|
||||||
return None
|
return unicode
|
||||||
|
|
||||||
# Try to lookup the syntax in the schema returned by the server
|
# Try to lookup the syntax in the schema returned by the server
|
||||||
obj = self.schema.get_obj(ldap.schema.AttributeType, attr)
|
obj = self.schema.get_obj(ldap.schema.AttributeType, attr)
|
||||||
if obj is None:
|
if obj is None:
|
||||||
return None
|
return unicode
|
||||||
|
|
||||||
return obj.syntax
|
return self._SYNTAX_MAPPING.get(obj.syntax, unicode)
|
||||||
|
|
||||||
def has_dn_syntax(self, attr):
|
def has_dn_syntax(self, attr):
|
||||||
"""
|
"""
|
||||||
@ -358,8 +358,7 @@ class IPASimpleLDAPObject(object):
|
|||||||
|
|
||||||
Returns True/False
|
Returns True/False
|
||||||
"""
|
"""
|
||||||
syntax = self.get_syntax(attr)
|
return self.get_type(attr) is DN
|
||||||
return syntax == DN_SYNTAX_OID
|
|
||||||
|
|
||||||
def get_single_value(self, attr):
|
def get_single_value(self, attr):
|
||||||
"""
|
"""
|
||||||
@ -421,10 +420,13 @@ class IPASimpleLDAPObject(object):
|
|||||||
if isinstance(val, str):
|
if isinstance(val, str):
|
||||||
if not self._decode_attrs:
|
if not self._decode_attrs:
|
||||||
return val
|
return val
|
||||||
target_type = self._SYNTAX_MAPPING.get(self.get_syntax(attr), unicode_from_utf8)
|
target_type = self.get_type(attr)
|
||||||
|
try:
|
||||||
if target_type is str:
|
if target_type is str:
|
||||||
return val
|
return val
|
||||||
try:
|
elif target_type is unicode:
|
||||||
|
return val.decode('utf-8')
|
||||||
|
else:
|
||||||
return target_type(val)
|
return target_type(val)
|
||||||
except Exception, e:
|
except Exception, e:
|
||||||
msg = 'unable to convert the attribute %r value %r to type %s' % (attr, val, target_type)
|
msg = 'unable to convert the attribute %r value %r to type %s' % (attr, val, target_type)
|
||||||
|
Loading…
Reference in New Issue
Block a user