Beispiel #1
0
 def list(self, key, valtype, default=None, sep=","):
     attr = self.str(key, default)
     if isinstance(attr, list):
         attr = [valtype(x) for x in attr]
         return attr
     else:
         return StrTo.list(attr, valtype, sep)
Beispiel #2
0
 def bool(self, key, default=None):
     attr = self.str(key, default)
     if isinstance(attr, str):
         if attr.isdigit():
             return bool(int(attr))
         return StrTo.bool(attr)
     else:
         return attr
Beispiel #3
0
 def tuple(self, key, valtype=str, default=None):
     attr = self.str(key, default)
     if attr is None:
         return default
     if isinstance(attr, str):
         if (not '(' in attr and not ')' in attr) and (not '[' in attr and not ']' in attr):
             return (valtype(attr),)
         if (not attr) or (not attr[1:-1].split(',')[0]):
             return tuple([valtype(x) for x in default])
         return StrTo.tuple(valtype, attr)
     else:
         return tuple([valtype(x) for x in attr])