diff --git a/odml/dtypes.py b/odml/dtypes.py index 374cb2af..f3dd4c8a 100644 --- a/odml/dtypes.py +++ b/odml/dtypes.py @@ -131,6 +131,8 @@ def float_get(string): def str_get(string): + if not string: + return default_values("string") if sys.version_info < (3, 0): return unicode(string) return str(string) @@ -145,7 +147,7 @@ def str_get(string): def time_get(string): if not string: - return None + return default_values("time") if type(string) is datetime.time: return datetime.datetime.strptime(string.strftime('%H:%M:%S'), '%H:%M:%S').time() @@ -155,7 +157,7 @@ def time_get(string): def time_set(value): if not value: - return None + return default_values("time") if type(value) is datetime.time: return value.strftime("%H:%M:%S") return value.isoformat() @@ -163,7 +165,7 @@ def time_set(value): def date_get(string): if not string: - return None + return default_values("date") if type(string) is datetime.date: return datetime.datetime.strptime(string.isoformat(), '%Y-%m-%d').date() @@ -176,7 +178,7 @@ def date_get(string): def datetime_get(string): if not string: - return None + return default_values("datetime") if type(string) is datetime.datetime: return datetime.datetime.strptime(string.strftime('%Y-%m-%d %H:%M:%S'), '%Y-%m-%d %H:%M:%S') @@ -186,7 +188,7 @@ def datetime_get(string): def datetime_set(value): if not value: - return None + return default_values("datetime") if type(value) is datetime.datetime: return value.strftime('%Y-%m-%d %H:%M:%S') else: @@ -194,8 +196,8 @@ def datetime_set(value): def boolean_get(string): - if string is None: - return None + if not string: + return default_values("boolean") if type(string) in (unicode, str): string = string.lower() truth = ["true", "1", True, "t"] # be kind, spec only accepts True / False @@ -209,6 +211,7 @@ def boolean_get(string): # Alias boolean_set to boolean_get. Both perform same function. + boolean_set = boolean_get bool_get = boolean_get bool_set = boolean_set