summaryrefslogtreecommitdiffstats
path: root/ipalib/config.py
diff options
context:
space:
mode:
authorJason Gerard DeRose <jderose@redhat.com>2008-12-30 15:02:15 -0700
committerJason Gerard DeRose <jderose@redhat.com>2008-12-30 15:02:15 -0700
commit379c549fc16fbb2eed6685f5e189da26f021abe9 (patch)
treef0b04bfaf2d0a968faa7253ae7b6bdc3cddaadf0 /ipalib/config.py
parentbc2395724708abc80c7c13c5474cefcfb6f3579c (diff)
downloadfreeipa-379c549fc16fbb2eed6685f5e189da26f021abe9.tar.gz
freeipa-379c549fc16fbb2eed6685f5e189da26f021abe9.tar.xz
freeipa-379c549fc16fbb2eed6685f5e189da26f021abe9.zip
Env now supports float values
Diffstat (limited to 'ipalib/config.py')
-rw-r--r--ipalib/config.py21
1 files changed, 15 insertions, 6 deletions
diff --git a/ipalib/config.py b/ipalib/config.py
index 59e531e96..c19474338 100644
--- a/ipalib/config.py
+++ b/ipalib/config.py
@@ -65,10 +65,10 @@ class Env(object):
>>> env.item # Also retrieve as an attribute
'I was set as a dictionary item.'
- The variable values can be ``str`` or ``int`` instances, or the ``True``,
- ``False``, or ``None`` constants. When the value provided is an ``str``
- instance, some limited automatic type conversion is performed, which allows
- values of specific types to be set easily from configuration files or
+ The variable values can be ``str``, ``int``, or ``float`` instances, or the
+ ``True``, ``False``, or ``None`` constants. When the value provided is an
+ ``str`` instance, some limited automatic type conversion is performed, which
+ allows values of specific types to be set easily from configuration files or
command-line options.
So in addition to their actual values, the ``True``, ``False``, and ``None``
@@ -89,11 +89,15 @@ class Env(object):
'false'
If an ``str`` value looks like an integer, it's automatically converted to
- the ``int`` type. For example:
+ the ``int`` type. Likewise, if an ``str`` value looks like a floating-point
+ number, it's automatically converted to the ``float`` type. For example:
>>> env.lucky = '7'
>>> env.lucky
7
+ >>> env.three_halves = '1.5'
+ >>> env.three_halves
+ 1.5
Leading and trailing white-space is automatically stripped from ``str``
values. For example:
@@ -232,7 +236,12 @@ class Env(object):
value = m[value]
elif value.isdigit():
value = int(value)
- assert type(value) in (str, int, bool, NoneType)
+ else:
+ try:
+ value = float(value)
+ except (TypeError, ValueError):
+ pass
+ assert type(value) in (str, int, float, bool, NoneType)
object.__setattr__(self, key, value)
self.__d[key] = value