summaryrefslogtreecommitdiffstats
path: root/ipa-python/user.py
diff options
context:
space:
mode:
authorKevin McCarthy <kmccarth@redhat.com>2007-08-20 10:50:11 -0700
committerKevin McCarthy <kmccarth@redhat.com>2007-08-20 10:50:11 -0700
commit66d3f1e730ed5e1bc80264b2a5d7f4fb16c1d22c (patch)
tree2d929adc00cad0701e87d96afc282733e7e6f0ef /ipa-python/user.py
parent5f0f192ae3c8aa44868b7b3b86e71523fc55515b (diff)
downloadfreeipa-66d3f1e730ed5e1bc80264b2a5d7f4fb16c1d22c.tar.gz
freeipa-66d3f1e730ed5e1bc80264b2a5d7f4fb16c1d22c.tar.xz
freeipa-66d3f1e730ed5e1bc80264b2a5d7f4fb16c1d22c.zip
Embed origiginal values inside user, and have update_user pass in a user
object. Based on rcrit's original patch. Push scalar to list value conversion inside funcs.py.
Diffstat (limited to 'ipa-python/user.py')
-rw-r--r--ipa-python/user.py25
1 files changed, 22 insertions, 3 deletions
diff --git a/ipa-python/user.py b/ipa-python/user.py
index ecbd2845c..38a634725 100644
--- a/ipa-python/user.py
+++ b/ipa-python/user.py
@@ -11,7 +11,8 @@ class User:
In python-ldap, entries are returned as a list of 2-tuples.
Instance variables:
dn - string - the string DN of the entry
- data - cidict - case insensitive dict of the attributes and values"""
+ data - cidict - case insensitive dict of the attributes and values
+ orig_data - cidict - case insentiive dict of the original attributes and values"""
def __init__(self,entrydata):
"""data is the raw data returned from the python-ldap result method,
@@ -32,6 +33,8 @@ class User:
self.dn = ''
self.data = ldap.cidict.cidict()
+ self.orig_data = dict(self.data)
+
def __nonzero__(self):
"""This allows us to do tests like if entry: returns false if there is no data,
true otherwise"""
@@ -41,6 +44,14 @@ class User:
"""Return True if this entry has an attribute named name, False otherwise"""
return self.data and self.data.has_key(name)
+ def __setattr__(self,name,value):
+ """One should use setValue() or setValues() to set values except for
+ dn and data which are special."""
+ if name != 'dn' and name != 'data' and name != 'orig_data':
+ raise KeyError, 'use setValue() or setValues()'
+ else:
+ self.__dict__[name] = value
+
def __getattr__(self,name):
"""If name is the name of an LDAP attribute, return the first value for that
attribute - equivalent to getValue - this allows the use of
@@ -72,9 +83,9 @@ class User:
ent.setValue('name', ('value1', 'value2', ..., 'valueN'))
Since *value is a tuple, we may have to extract a list or tuple from that
tuple as in the last two examples above"""
- if (len(value[0]) < 1):
+ if (len(value) < 1):
return
- if isinstance(value[0],list) or isinstance(value[0],tuple):
+ if (len(value) == 1):
self.data[name] = value[0]
else:
self.data[name] = value
@@ -100,6 +111,14 @@ class User:
"""Return a list of all attributes in the entry"""
return self.data.keys()
+ def origDataDict(self):
+ """Returns a dict of the original values of the user. Used for updates."""
+ result = {}
+ for k in self.orig_data.keys():
+ result[k] = self.orig_data[k]
+ result['dn'] = self.dn
+ return result
+
# def __str__(self):
# """Convert the Entry to its LDIF representation"""
# return self.__repr__()