+ if not isinstance(objargs, list):
+ objargs = [objargs]
+
+ 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 saxutils.unescape(objargs[0]).encode()
+ except:
+ return "?"
+ else:
+ return ""
+
+ 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, exclude=None):
+ if (value == None):
+ return "None"
+## elif (isinstance(value, ObjectType) and hasattr(value, "__dict__")):
+## if (exclude == None):
+## exclude = []
+## s = "%s(%s)" % (type(value), toDiffableString(value.__dict__, exclude))
+ elif (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, "__str__")):
+ s = str(value)
+ elif (hasattr(value, "__dict__")):
+ s = "%s(%s)" % (type(value), toDiffableString(value.__dict__, exclude))
+ 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, exclude))
+ s = "[" + ", ".join(items) + "]"
+ elif (isinstance(value, dict)):
+ if (exclude == None):
+ exclude = []
+ items = []
+ for key, val in value.iteritems():
+ if (isinstance(val, UnicodeType)):
+ items.append("'%s': u'%s'" % (key, toDiffableString(val, exclude)))
+ elif (isinstance(val, basestring)):
+ items.append("'%s': '%s'" % (key, toDiffableString(val, exclude)))
+ else:
+ items.append("'%s': %s" % (key, toDiffableString(val, exclude)))
+ s = "{" + ", ".join(items) + "}"
+ else:
+ s = str(value)
+ return s
+
+def toDiffableString(value, exclude=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)