def fromStr(self, attrs): obj = None if AIUtils.isStr(attrs): attrs = AIUtils.str2dict(attrs) obj = self if AIUtils.isDict(attrs): for key in attrs: func = getattr(obj, 'set' + AIStrUtils.toUpperF(key)) if AIUtils.isFunc(func): apply(func, [attrs[key]]) else: raise Exception('input parameter type not correct!') return obj
def toStr(self, obj): result = None if not AIUtils.isEmpty(obj): attrs = dir(obj) result = [] for attr in attrs: if attr.startswith('get'): prop = AIStrUtils.toLowerF(attr[3:]) func = getattr(obj, attr) value = apply(func, []) # 判断类型,不同的字符串转换方式 propValue = AIUtils.list2str(value) if AIUtils.isList(value) \ else AIUtils.dict2str(value) if AIUtils.isDict(value) \ else ('\'' + AIUtils.toStr(value) + '\'') if AIUtils.isStr(value) \ else AIUtils.toStr(value) result.append('\'' + prop + '\':' + propValue + '') result = '{' + ','.join(result) + '}' else: raise Exception('input parameter type not correct!') return result
def trim(v): return None if not AIUtils.isStr(v) else v.strip()
def toLowerF(v): return None if not AIUtils.isStr(v) else (v[0].lower() + v[1:])
def toUpperF(v): return None if not AIUtils.isStr(v) else (v[0].upper() + v[1:])
def toLower(v): return None if not AIUtils.isStr(v) else v.lower()
def toUpper(v): return None if not AIUtils.isStr(v) else v.upper()