def setValue(self, name, *value): """Value passed in may be a single value, several values, or a single sequence. For example: ent.setValue('name', 'value') ent.setValue('name', 'value1', 'value2', ..., 'valueN') ent.setValue('name', ['value1', 'value2', ..., 'valueN']) 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) < 1): return if (len(value) == 1): self.data[name] = ipautil.utf8_encode_values(value[0]) else: self.data[name] = ipautil.utf8_encode_values(value)
def setValue(self,name,*value): """Value passed in may be a single value, several values, or a single sequence. For example: ent.setValue('name', 'value') ent.setValue('name', 'value1', 'value2', ..., 'valueN') ent.setValue('name', ['value1', 'value2', ..., 'valueN']) 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) < 1): return if (len(value) == 1): self.data[name] = ipautil.utf8_encode_values(value[0]) else: self.data[name] = ipautil.utf8_encode_values(value)
def toDict(self): """Convert the attrs and values to a dict. The dict is keyed on the attribute name. The value is either single value or a list of values.""" assert isinstance(self.dn, DN) result = ipautil.CIDict(self.data) for i in result.keys(): result[i] = ipautil.utf8_encode_values(result[i]) result['dn'] = self.dn return result
def toTupleList(self): """Convert the attrs and values to a list of 2-tuples. The first element of the tuple is the attribute name. The second element is either a single value or a list of values.""" r = [] for i in self.data.iteritems(): n = ipautil.utf8_encode_values(i[1]) r.append((i[0], n)) return r