Move utf-8 conversion inside user.py (for updates).

This commit is contained in:
Kevin McCarthy 2007-08-20 11:39:04 -07:00
parent 66d3f1e730
commit c113d932b1
2 changed files with 17 additions and 6 deletions

View File

@ -3,6 +3,17 @@ import ldif
import re
import cStringIO
def utf8_encode_value(value):
if isinstance(value,unicode):
return value.encode('utf-8')
return value
def utf8_encode_values(values):
if isinstance(values,list) or isinstance(values,tuple):
return map(utf8_encode_value, values)
else:
return utf8_encode_value(values)
class User:
"""This class represents an IPA user. An LDAP entry consists of a DN
and a list of attributes. Each attribute consists of a name and a list of
@ -86,9 +97,9 @@ class User:
if (len(value) < 1):
return
if (len(value) == 1):
self.data[name] = value[0]
self.data[name] = utf8_encode_values(value[0])
else:
self.data[name] = value
self.data[name] = utf8_encode_values(value)
setValues = setValue

View File

@ -115,10 +115,10 @@ class Root(controllers.RootController):
orig_user_dict = loads(b64decode(kw.get('user_orig')))
new_user = ipa.user.User(orig_user_dict)
new_user.setValue('givenname', utf8_encode(kw.get('givenname')))
new_user.setValue('sn', utf8_encode(kw.get('sn')))
new_user.setValue('mail', utf8_encode(kw.get('mail')))
new_user.setValue('telephonenumber', utf8_encode(kw.get('telephonenumber')))
new_user.setValue('givenname', kw.get('givenname'))
new_user.setValue('sn', kw.get('sn'))
new_user.setValue('mail', kw.get('mail'))
new_user.setValue('telephonenumber', kw.get('telephonenumber'))
#
# this is a hack until we decide on the policy for names/cn/sn/givenName
#