diff options
author | RaNaN <Mast3rRaNaN@hotmail.de> | 2011-12-19 23:10:49 +0100 |
---|---|---|
committer | RaNaN <Mast3rRaNaN@hotmail.de> | 2011-12-19 23:10:49 +0100 |
commit | 6eae782f13953dd0ba2bbe1b582cf33fd4d7d90a (patch) | |
tree | a7e80bc89b1a523854e1f3e3d9ec945023193212 /module/config/converter.py | |
parent | pluginmanager cleanup (diff) | |
download | pyload-6eae782f13953dd0ba2bbe1b582cf33fd4d7d90a.tar.xz |
configparser v2, warning CONFIG will be DELETED.
Diffstat (limited to 'module/config/converter.py')
-rw-r--r-- | module/config/converter.py | 26 |
1 files changed, 26 insertions, 0 deletions
diff --git a/module/config/converter.py b/module/config/converter.py new file mode 100644 index 000000000..f3b4dc327 --- /dev/null +++ b/module/config/converter.py @@ -0,0 +1,26 @@ +# -*- coding: utf-8 -*- + +from module.utils import decode + +def to_string(value): + return str(value) if not isinstance(value, basestring) else value + +# cast value to given type, unicode for strings +def from_string(value, typ=None): + + # value is no string + if not isinstance(value, basestring): + return value + + value = decode(value) + + if typ == "int": + return int(value) + elif typ == "bool": + return True if value.lower() in ("1", "true", "on", "an", "yes") else False + elif typ == "time": + if not value: value = "0:00" + if not ":" in value: value += ":00" + return value + else: + return value
\ No newline at end of file |