aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPjotr Prins2018-03-29 11:00:41 +0000
committerPjotr Prins2018-03-29 11:00:41 +0000
commitb9ada0431b880e632b830a6e2169279ae1ecdd36 (patch)
treed4c6b6437d30dbcd02b4cb5c4070a4e2956e5d77
parentd215602d89ec6d929d489cd7f3507cbe3e8c29bf (diff)
downloadgenenetwork2-b9ada0431b880e632b830a6e2169279ae1ecdd36.tar.gz
Type checking in its own file
-rw-r--r--wqflask/utility/type_checking.py42
1 files changed, 42 insertions, 0 deletions
diff --git a/wqflask/utility/type_checking.py b/wqflask/utility/type_checking.py
new file mode 100644
index 00000000..220e5f62
--- /dev/null
+++ b/wqflask/utility/type_checking.py
@@ -0,0 +1,42 @@
+# Type checking functions
+
+def is_float(value):
+ try:
+ float(value)
+ return True
+ except:
+ return False
+
+def is_int(value):
+ try:
+ int(value)
+ return True
+ except:
+ return False
+
+def is_str(value):
+ if value is None:
+ return False
+ try:
+ str(value)
+ return True
+ except:
+ return False
+
+def get_float(vars,name,default=None):
+ if name in vars:
+ if is_float(vars[name]):
+ return float(vars[name])
+ return None
+
+def get_int(vars,name,default=None):
+ if name in vars:
+ if is_int(vars[name]):
+ return float(vars[name])
+ return default
+
+def get_string(vars,name,default=None):
+ if name in vars:
+ if not vars[name] is None:
+ return str(vars[name])
+ return default