summaryrefslogtreecommitdiffstats
path: root/module/utils
diff options
context:
space:
mode:
authorGravatar RaNaN <Mast3rRaNaN@hotmail.de> 2012-08-10 22:12:10 +0200
committerGravatar RaNaN <Mast3rRaNaN@hotmail.de> 2012-08-10 22:12:10 +0200
commita8f763fb85756f69899f7b3b71c01bb01461ee3c (patch)
tree725e9915e5d94cc65c158929b20f096d0f7b97b0 /module/utils
parentfixed import (diff)
downloadpyload-a8f763fb85756f69899f7b3b71c01bb01461ee3c.tar.xz
beginning new pyload web-ui from scratch
Diffstat (limited to 'module/utils')
-rw-r--r--module/utils/__init__.py12
1 files changed, 9 insertions, 3 deletions
diff --git a/module/utils/__init__.py b/module/utils/__init__.py
index 28d734bb5..4ecc53a12 100644
--- a/module/utils/__init__.py
+++ b/module/utils/__init__.py
@@ -185,12 +185,18 @@ def accumulate(it, inv_map=None):
def to_string(value):
return str(value) if not isinstance(value, basestring) else value
-def to_int(string):
- """ return int from string or 0 """
+def to_int(string, default=0):
+ """ return int from string or default """
try:
return int(string)
except ValueError:
- return 0
+ return default
+
+def to_dict(obj):
+ ret = {"class" : obj.__class__.__name__}
+ for att in obj.__slots__:
+ ret[att] = getattr(obj, att)
+ return ret
def from_string(value, typ=None):
""" cast value to given type, unicode for strings """