diff options
author | RaNaN <Mast3rRaNaN@hotmail.de> | 2013-07-17 11:50:15 +0200 |
---|---|---|
committer | RaNaN <Mast3rRaNaN@hotmail.de> | 2013-07-17 11:50:15 +0200 |
commit | a3dfd09a8d560f6e6591de2e1de95e82ed2ddce3 (patch) | |
tree | c3ebfd206a532a91300e69ac04c6229abf615ba5 /pyload/utils | |
parent | fixed last commit (diff) | |
download | pyload-a3dfd09a8d560f6e6591de2e1de95e82ed2ddce3.tar.xz |
improved inputTypes, config api
Diffstat (limited to 'pyload/utils')
-rw-r--r-- | pyload/utils/__init__.py | 28 |
1 files changed, 6 insertions, 22 deletions
diff --git a/pyload/utils/__init__.py b/pyload/utils/__init__.py index da7b81af7..c9c24ac40 100644 --- a/pyload/utils/__init__.py +++ b/pyload/utils/__init__.py @@ -42,13 +42,13 @@ def remove_chars(string, repl): def get_console_encoding(enc): - if os.name == "nt": + if os.name == "nt": if enc == "cp65001": # aka UTF-8 print "WARNING: Windows codepage 65001 is not supported." enc = "cp850" else: enc = "utf8" - + return enc def compare_time(start, end): @@ -199,6 +199,10 @@ def accumulate(it, inv_map=None): def to_string(value): return str(value) if not isinstance(value, basestring) else value +def to_bool(value): + if not isinstance(value, basestring): return value + return True if value.lower() in ("1", "true", "on", "an", "yes") else False + def to_int(string, default=0): """ return int from string or default """ try: @@ -206,26 +210,6 @@ def to_int(string, default=0): except ValueError: return default -def from_string(value, typ=None): - """ cast value to given type, unicode for strings """ - - # 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 - def get_index(l, value): """ .index method that also works on tuple and python 2.5 """ for pos, t in enumerate(l): |