Changeset View
Changeset View
Standalone View
Standalone View
pykolab/utils.py
Show First 20 Lines • Show All 347 Lines • ▼ Show 20 Lines | def normalize(_object): | ||||
if type(_object) == list: | if type(_object) == list: | ||||
for item in _object: | for item in _object: | ||||
result.append(item.lower()) | result.append(item.lower()) | ||||
result = list(set(result)) | result = list(set(result)) | ||||
return result | return result | ||||
elif type(_object) == dict: | elif type(_object) == dict: | ||||
for key in _object.keys(): | def _strip(value): | ||||
try: | |||||
return value.strip() | |||||
except: | |||||
return value | |||||
for key in _object: | |||||
if type(_object[key]) == list: | if type(_object[key]) == list: | ||||
if _object[key] == None: | if _object[key] is None: | ||||
continue | continue | ||||
if len(_object[key]) == 1: | val = map(_strip, _object[key]) | ||||
result[key.lower()] = ''.join(_object[key]) | |||||
if len(val) == 1: | |||||
result[key.lower()] = ''.join(val) | |||||
else: | else: | ||||
result[key.lower()] = _object[key] | result[key.lower()] = val | ||||
else: | else: | ||||
if _object[key] == None: | if _object[key] is None: | ||||
continue | continue | ||||
# What the heck? | result[key.lower()] = _strip(_object[key]) | ||||
result[key.lower()] = _object[key] | |||||
if result.has_key('objectsid') and not result['objectsid'][0] == "S": | if result.has_key('objectsid') and not result['objectsid'][0] == "S": | ||||
result['objectsid'] = sid_to_string(result['objectsid']) | result['objectsid'] = sid_to_string(result['objectsid']) | ||||
if result.has_key('sn'): | if result.has_key('sn'): | ||||
result['surname'] = result['sn'].replace(' ', '') | result['surname'] = result['sn'].replace(' ', '') | ||||
if result.has_key('mail'): | if result.has_key('mail'): | ||||
▲ Show 20 Lines • Show All 206 Lines • Show Last 20 Lines |