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)
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
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])