+ if className == "None":
+ return None
+ elif className == "bool":
+ if ((len(objargs) < 1) or (objargs[0].lower() == "false") or (not objargs[0])):
+ return False
+ return True
+ if className == "str" or className == "unicode": # don't strip: blanks are significant
+ if len(objargs) > 0:
+ try:
+ return utillang.unescape(objargs[0]).encode()
+ except:
+ return "?"
+ else:
+ return ""
+
+ if className == "date":
+ return datetimeparser.parse(objargs[0], asdate=True)
+ if className == "datetime":
+ return datetimeparser.parse(objargs[0])
+ if className == "time":
+ return datetimeparser.parse(objargs[0], astime=True)
+
+ classtype = classForName(className)
+ if (classtype == None):
+ raise Exception("Could not find class %s" % className)
+
+ if (len(objargs) > 0):
+ return classtype(*objargs)
+ else:
+ return classtype()
+
+def getClassProperty(classType, propertyName):
+ return getattr(classType, propertyName)
+
+def toDiffableRepr(value, maxLevel=None):
+ if (value == None):
+ return "None"
+ if (maxLevel == None):
+ maxLevel = 8
+ maxLevel -= 1
+ if (maxLevel < 0):
+ return typeToString(value, PRINT_OBJ_DIFFABLE)
+## if ((exclude != None) and not isinstance(value, (basestring, int))):
+## for v in exclude:
+## if (v is value):
+## return "<recursive reference>"
+## exclude.append(value)
+## elif (isinstance(value, ObjectType) and hasattr(value, "__dict__")):
+## if (exclude == None):
+## exclude = []
+## s = "%s(%s)" % (type(value), toDiffableString(value.__dict__, exclude))
+ if (not isinstance(value, (BooleanType, ClassType, ComplexType, DictType, DictionaryType,
+ FloatType, IntType, ListType, LongType, StringType, TupleType,
+ UnicodeType, BufferType, BuiltinFunctionType, BuiltinMethodType,
+ CodeType, FrameType, FunctionType, GeneratorType, InstanceType,
+ LambdaType, MethodType, ModuleType, SliceType, TracebackType,
+ TypeType, XRangeType))):
+ if (hasattr(value, "_toDiffableString")):
+ s = value._toDiffableString(maxLevel)
+ elif (hasattr(value, "__str__")):
+ s = str(value)
+ elif (hasattr(value, "__dict__")):
+ s = "%s(%s)" % (type(value), toDiffableString(value.__dict__, maxLevel))
+ else:
+ s = str(type(value))
+ ix2 = s.find(" object at 0x")
+ if (ix2 > 0):
+ ix = s.rfind(".")
+ if (ix > 0):
+ s = "<class %s>" %s[ix+1:ix2]
+ elif (isinstance(value, bool)):
+ if (value):
+ return "True"
+ else:
+ return "False"
+ elif (isinstance(value, (tuple, list))):
+ items = []
+ for v in value:
+ if (isinstance(v, basestring)):
+ if (v.find("'") >= 0):
+ items.append('"%s"' % v)
+ else:
+ items.append("'%s'" % v)
+ else:
+ items.append(toDiffableString(v, maxLevel))
+ s = "[" + ", ".join(items) + "]"
+ elif (isinstance(value, dict)):
+ items = []
+ for key, val in value.iteritems():
+ if (isinstance(val, UnicodeType)):
+ items.append("'%s': u'%s'" % (key, toDiffableString(val, maxLevel)))
+ elif (isinstance(val, basestring)):
+ items.append("'%s': '%s'" % (key, toDiffableString(val, maxLevel)))
+ else:
+ items.append("'%s': %s" % (key, toDiffableString(val, maxLevel)))
+ s = "{" + ", ".join(items) + "}"
+ else:
+ s = str(value)
+ return s
+
+def toDiffableString(value, maxLevel=None):
+## if (value == None):
+## return "None"
+## if ((exclude != None) and not isinstance(value, (basestring, int))):
+## for v in exclude:
+## if (v is value):
+## return "<recursive reference>"
+## exclude.append(value)
+ s = toDiffableRepr(value, maxLevel)