[Modeling-users] Patch for handling boolean values in xml model for python 2.3
Status: Abandoned
Brought to you by:
sbigaret
From: John G. <ig...@do...> - 2003-11-28 10:44:03
|
Hi, This is a patch to handle the differences between python 2.2 & 2.3 regarding converting boolean values. It uses the bool() built-in, so I think it won't work for versions of python < 2.2.1 Boolean values such as isClassProperty & isAbstract are written as 0/1 in 2.2 and True/False in 2.3. The model loads fine with either 2.2/2.3 regardless of the version of python it was generated from. I'm not familiar with the code base, so let me know if this breaks something else. cheers john diff -urN Modeling.orig/Attribute.py Modeling/Attribute.py --- Modeling.orig/Attribute.py 2003-09-14 11:35:07.000000000 +0300 +++ Modeling/Attribute.py 2003-11-28 12:18:52.000000000 +0200 @@ -572,6 +572,13 @@ attrType=self.xmlAttributeType(attributeName) set=self.xmlSetAttribute(attributeName) if attrType=='string': value=unicodeToStr(value, encoding) + elif attrType=='number': value=int(value) + elif attrType=='bool': + if value=='False': value=False + else: + try: value=bool(int(value)) + except ValueError: value=bool(value) + set(value) def getXMLDOM(self, doc=None, parentNode=None, encoding='iso-8859-1'): @@ -634,10 +641,10 @@ 'externalType' : ('string', self.setExternalType, self.externalType), - 'isClassProperty' : ('string', + 'isClassProperty' : ('bool', self.setIsClassProperty, self.isClassProperty), - 'isRequired' : ('string', + 'isRequired' : ('bool', self.setIsRequired, self.isRequired), # defaultValue must be loaded AFTER type is set, or we will get the diff -urN Modeling.orig/Entity.py Modeling/Entity.py --- Modeling.orig/Entity.py 2003-11-24 14:12:32.000000000 +0200 +++ Modeling/Entity.py 2003-11-28 12:15:11.000000000 +0200 @@ -1278,6 +1278,12 @@ attrType=self.xmlAttributeType(attributeName) set=self.xmlSetAttribute(attributeName) if attrType=='string': value=unicodeToStr(value, encoding) + elif attrType=='number': value=int(value) + elif attrType=='bool': + if value=='False': value=False + else: + try: value=bool(int(value)) + except ValueError: value=bool(value) set(value) if phase==1: @@ -1405,10 +1411,10 @@ 'externalName': ( 'string', self.setExternalName, self.externalName ), - 'isReadOnly': ( 'string', + 'isReadOnly': ( 'bool', self.setReadOnly, self.isReadOnly ), - 'isAbstract': ( 'string', + 'isAbstract': ( 'bool', self.setIsAbstract, self.isAbstract ), 'moduleName': ( 'string', diff -urN Modeling.orig/Relationship.py Modeling/Relationship.py --- Modeling.orig/Relationship.py 2003-07-28 10:18:59.000000000 +0300 +++ Modeling/Relationship.py 2003-11-28 12:15:37.000000000 +0200 @@ -251,7 +251,12 @@ attrType=self.xmlAttributeType(attributeName) set=self.xmlSetAttribute(attributeName) if attrType=='string': value=unicodeToStr(value, encoding) - if attrType=='number': value=int(value) + elif attrType=='number': value=int(value) + elif attrType=='bool': + if value=='False': value=False + else: + try: value=bool(int(value)) + except ValueError: value=bool(value) set(value) return @@ -303,7 +308,7 @@ 'displayLabel' : ('string', self.setDisplayLabel, self.displayLabel), - 'isClassProperty' : ('number', + 'isClassProperty' : ('bool', self.setIsClassProperty, self.isClassProperty), 'multiplicityLowerBound': ('number', diff -urN Modeling.orig/utils.py Modeling/utils.py --- Modeling.orig/utils.py 2003-11-24 14:12:38.000000000 +0200 +++ Modeling/utils.py 2003-11-27 21:36:56.000000000 +0200 @@ -81,11 +81,11 @@ def toBoolean(param): """ - If param is a string (or unicode) and equals to 0, returns 0 ; otherwise + If param is a string (or unicode) and equals to 0, returns False ; otherwise returns 'not not param'. """ if type(param) in (types.StringType, types.UnicodeType): - if param=='0': return 0 + if param=='0': return False return not not param if sys.version_info < (2, 2): |