summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJason Gerard DeRose <jderose@redhat.com>2008-08-26 16:52:46 +0000
committerJason Gerard DeRose <jderose@redhat.com>2008-08-26 16:52:46 +0000
commit0755c218ffdedafbeb9b0a19750704205b4f0b65 (patch)
treeba8e2e1c4d98dbcf87f8208048fc0d93fbce5c30
parent87fabaa7177140cf0a934e0f05a6a4b4295fc1d0 (diff)
downloadfreeipa-0755c218ffdedafbeb9b0a19750704205b4f0b65.tar.gz
freeipa-0755c218ffdedafbeb9b0a19750704205b4f0b65.tar.xz
freeipa-0755c218ffdedafbeb9b0a19750704205b4f0b65.zip
196: DefaultFrom.__call__() now returns values from callback even if not basestring; small work on DefaultFrom docstrings
-rw-r--r--ipalib/public.py13
1 files changed, 8 insertions, 5 deletions
diff --git a/ipalib/public.py b/ipalib/public.py
index edb4641f9..bb592d2f0 100644
--- a/ipalib/public.py
+++ b/ipalib/public.py
@@ -44,7 +44,8 @@ class DefaultFrom(plugable.ReadOnly):
"""
Derives a default for one value using other supplied values.
- Here is an example:
+ Here is an example that constructs a user's initials from his first
+ and last name:
>>> df = DefaultFrom(lambda f, l: f[0] + l[0], 'first', 'last')
>>> df(first='John', last='Doe') # Both keys
@@ -68,16 +69,18 @@ class DefaultFrom(plugable.ReadOnly):
lock(self)
def __call__(self, **kw):
+ """
+ If all keys are present, calls the callback; otherwise returns None.
+
+ :param kw: The keyword arguments.
+ """
vals = tuple(kw.get(k, None) for k in self.keys)
if None in vals:
return None
try:
- ret = self.callback(*vals)
+ return self.callback(*vals)
except Exception:
return None
- if isinstance(ret, basestring):
- return ret
- return None
class Option(plugable.Plugin):