예제 #1
0
 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
예제 #2
0
 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
예제 #3
0
 def trim(v):
     return None if not AIUtils.isStr(v) else v.strip()
예제 #4
0
 def toLowerF(v):
     return None if not AIUtils.isStr(v) else (v[0].lower() + v[1:])
예제 #5
0
 def toUpperF(v):
     return None if not AIUtils.isStr(v) else (v[0].upper() + v[1:])
예제 #6
0
 def toLower(v):
     return None if not AIUtils.isStr(v) else v.lower()
예제 #7
0
 def toUpper(v):
     return None if not AIUtils.isStr(v) else v.upper()