This patch adds proper xs:boolean reading and writing to generateDS.
"true" and "false" values in the XML will become True and False in
Python, and will be written back out as "true" and "false",
respectively.
--- generateDS-1.13a.py 2008-05-27 14:45:28.000000000 -0400
+++ generateDS.py 2008-05-27 15:37:56.000000000 -0400
@@ -784,6 +784,26 @@
def getName(self): return self.name
def setData_type(self, data_type): self.data_type = data_type
def getData_type(self): return self.data_type
+ def getType(self):
+ returnType = self.data_type
+ if SimpleElementDict.has_key(self.data_type):
+ typeObj = SimpleElementDict[self.data_type]
+ typeObjType = typeObj.getRawType()
+ if typeObjType in StringType or \
+ typeObjType == TokenType or \
+ typeObjType == DateTimeType or \
+ typeObjType == DateType or \
+ typeObjType in IntegerType or \
+ typeObjType == DecimalType or \
+ typeObjType == PositiveIntegerType or \
+ typeObjType == NegativeIntegerType or \
+ typeObjType == NonPositiveIntegerType or \
+ typeObjType == NonNegativeIntegerType or \
+ typeObjType == BooleanType or \
+ typeObjType == FloatType or \
+ typeObjType == DoubleType:
+ returnType = typeObjType
+ return returnType
def setUse(self, use): self.use = use
def getUse(self): return self.use
def setDefault(self, default): self.default = default
@@ -1103,7 +1123,6 @@
(fill, namespace, name, namespace, name, make_gs_name(cleanName))
outfile.write(s1)
elif child.getType() in IntegerType or \
- child.getType() == BooleanType or \
child.getType() == PositiveIntegerType or \
child.getType() == NonPositiveIntegerType or \
child.getType() == NegativeIntegerType or \
@@ -1113,6 +1132,12 @@
s1 = "%s outfile.write('<%s%s>%%d</%s%s>\\n' %% self.get%s())\n" % \
(fill, namespace, name, namespace, name, make_gs_name(cleanName))
outfile.write(s1)
+ elif child.getType() == BooleanType:
+ s1 = '%s showIndent(outfile, level)\n' % fill
+ outfile.write(s1)
+ s1 = "%s outfile.write('<%s%s>%%s</%s%s>\\n' %% lower(str(self.get%s())))\n" % \
+ (fill, namespace, name, namespace, name, make_gs_name(cleanName))
+ outfile.write(s1)
elif child.getType() == FloatType or \
child.getType() == DecimalType:
s1 = '%s showIndent(outfile, level)\n' % fill
@@ -1153,7 +1178,6 @@
(fill, namespace, name, namespace, name, cleanName,)
outfile.write(s1)
elif child.getType() in IntegerType or \
- child.getType() == BooleanType or \
child.getType() == PositiveIntegerType or \
child.getType() == NonPositiveIntegerType or \
child.getType() == NegativeIntegerType or \
@@ -1163,6 +1187,12 @@
s1 = "%s outfile.write('<%s%s>%%d</%s%s>\\n' %% %s_)\n" % \
(fill, namespace, name, namespace, name, cleanName, )
outfile.write(s1)
+ elif child.getType() == BooleanType:
+ s1 = '%s showIndent(outfile, level)\n' % fill
+ outfile.write(s1)
+ s1 = "%s outfile.write('<%s%s>%%s</%s%s>\\n' %% lower(str(%s_)))\n" % \
+ (fill, namespace, name, namespace, name, cleanName, )
+ outfile.write(s1)
elif child.getType() == FloatType or \
child.getType() == DecimalType:
s1 = '%s showIndent(outfile, level)\n' % fill
@@ -1204,7 +1234,6 @@
(fill, namespace, name, namespace, name, make_gs_name(cleanName))
outfile.write(s1)
elif child.getType() in IntegerType or \
- child.getType() == BooleanType or \
child.getType() == PositiveIntegerType or \
child.getType() == NonPositiveIntegerType or \
child.getType() == NegativeIntegerType or \
@@ -1214,6 +1243,12 @@
s1 = "%s outfile.write('<%s%s>%%d</%s%s>\\n' %% self.get%s())\n" % \
(fill, namespace, name, namespace, name, make_gs_name(cleanName))
outfile.write(s1)
+ elif child.getType() == BooleanType:
+ s1 = '%s showIndent(outfile, level)\n' % fill
+ outfile.write(s1)
+ s1 = "%s outfile.write('<%s%s>%%s</%s%s>\\n' %% lower(str(self.get%s())))\n" % \
+ (fill, namespace, name, namespace, name, make_gs_name(cleanName))
+ outfile.write(s1)
elif child.getType() == FloatType or \
child.getType() == DecimalType:
s1 = '%s showIndent(outfile, level)\n' % fill
@@ -1251,13 +1286,32 @@
if attrDef.getUse() == 'optional':
s1 = " if self.get%s() is not None:\n" % (capName, )
outfile.write(s1)
- s1 = " outfile.write(' %s=\"%%s\"' %% (quote_attrib(self.get%s()), ))\n" % \
- (name, capName, )
- outfile.write(s1)
+ indent = " "
else:
- s1 = " outfile.write(' %s=\"%%s\"' %% (quote_attrib(self.get%s()), ))\n" % \
- (name, capName, )
- outfile.write(s1)
+ indent = ""
+ if attrDef.getType() in StringType or \
+ attrDef.getType() == TokenType or \
+ attrDef.getType() == DateTimeType or \
+ attrDef.getType() == DateType:
+ s1 = '''%s outfile.write(' %s="%%s"' %% (quote_attrib(self.get%s()), ))\n''' % \
+ (indent, name, cleanName)
+ elif attrDef.getType() in IntegerType or \
+ attrDef.getType() == PositiveIntegerType or \
+ attrDef.getType() == NonPositiveIntegerType or \
+ attrDef.getType() == NegativeIntegerType or \
+ attrDef.getType() == NonNegativeIntegerType:
+ s1 = '''%s outfile.write(' %s="%%d"' %% self.get%s())\n''' % (indent, name, cleanName)
+ elif attrDef.getType() == BooleanType:
+ s1 = '''%s outfile.write(' %s="%%s"' %% lower(str(self.get%s())))\n''' % (indent, name, cleanName)
+ elif attrDef.getType() == FloatType or \
+ attrDef.getType() == DecimalType:
+ s1 = '''%s outfile.write(' %s="%%f"' %% self.get%s())\n''' % (indent, name, cleanName)
+ elif attrDef.getType() == DoubleType:
+ s1 = '''%s outfile.write(' %s="%%e"' %% self.get%s())\n''' % (indent, name, cleanName)
+ else:
+ s1 = '''%s outfile.write(' %s="%%s"' %% str(self.get%s()))\n''' % \
+ (indent, name, cleanName, )
+ outfile.write(s1)
if element.getAnyAttribute():
s1 = ' for name, value in self.anyAttributes_.items():\n'
outfile.write(s1)
@@ -1308,25 +1362,15 @@
outfile.write(s1)
s1 = ' showIndent(outfile, level)\n'
outfile.write(s1)
- if len(element.getAttributeDefs()) > 0 or element.getAnyAttribute():
- s1 = " outfile.write('<%s%s' % (namespace_, name_))\n"
- outfile.write(s1)
-
- s1 = " self.exportAttributes(outfile, level, name_='%s', namespace_='%s')\n" % \
- (element.getName(), namespace)
- outfile.write(s1)
- if element.isMixed() or childCount == 0:
- s1 = " outfile.write('>')\n"
- else:
- s1 = " outfile.write('>\\n')\n"
- outfile.write(s1)
+ s1 = " outfile.write('<%s%s' % (namespace_, name_))\n"
+ outfile.write(s1)
+ s1 = " self.exportAttributes(outfile, level, name_='%s', namespace_='%s')\n" % \
+ (element.getName(), namespace)
+ outfile.write(s1)
+ if element.isMixed():
+ s1 = " outfile.write('>')\n"
else:
- if element.isMixed() or childCount == 0:
- s1 = " outfile.write('<%s%s>' % (namespace_, name_))\n"
- else:
- s1 = " outfile.write('<%s%s>\\n' % (namespace_, name_))\n"
- outfile.write(s1)
-
+ s1 = " outfile.write('>\\n')\n"
s1 = " self.exportChildren(outfile, level + 1, name_, namespace_)\n"
outfile.write(s1)
if element.isMixed() or childCount == 0:
@@ -1385,7 +1429,6 @@
(fill, mappedName, make_gs_name(name))
outfile.write(s1)
elif child.getType() in IntegerType or \
- child.getType() == BooleanType or \
child.getType() == PositiveIntegerType or \
child.getType() == NonPositiveIntegerType or \
child.getType() == NegativeIntegerType or \
@@ -1395,6 +1438,12 @@
s1 = "%s outfile.write('%s=%%d,\\n' %% self.get%s())\n" % \
(fill, mappedName, make_gs_name(name))
outfile.write(s1)
+ elif child.getType() == BooleanType:
+ s1 = '%s showIndent(outfile, level)\n' % fill
+ outfile.write(s1)
+ s1 = "%s outfile.write('%s=%%s,\\n' %% self.get%s())\n" % \
+ (fill, mappedName, make_gs_name(name))
+ outfile.write(s1)
elif child.getType() == FloatType or \
child.getType() == DecimalType:
s1 = '%s showIndent(outfile, level)\n' % fill
@@ -1440,7 +1489,6 @@
(fill, name)
outfile.write(s1)
elif child.getType() in IntegerType or \
- child.getType() == BooleanType or \
child.getType() == PositiveIntegerType or \
child.getType() == NonPositiveIntegerType or \
child.getType() == NegativeIntegerType or \
@@ -1450,6 +1498,12 @@
s1 = "%s outfile.write('%%d,\\n' %% %s)\n" % \
(fill, name)
outfile.write(s1)
+ elif child.getType() == BooleanType:
+ s1 = '%s showIndent(outfile, level)\n' % fill
+ outfile.write(s1)
+ s1 = "%s outfile.write('%%s,\\n' %% %s)\n" % \
+ (fill, name)
+ outfile.write(s1)
elif child.getType() == FloatType or \
child.getType() == DecimalType:
s1 = '%s showIndent(outfile, level)\n' % fill
@@ -1641,12 +1695,12 @@
s1 = " if attrs.get('%s').value in ('true', '1'):\n" % \
(name, )
outfile.write(s1)
- s1 = " self.%s = 1\n" % (mappedName, )
+ s1 = " self.%s = True\n" % mappedName
outfile.write(s1)
s1 = " elif attrs.get('%s').value in ('false', '0'):\n" % \
(name, )
outfile.write(s1)
- s1 = " self.%s = 0\n" % (mappedName, )
+ s1 = " self.%s = False\n" % mappedName
outfile.write(s1)
s1 = ' else:\n'
outfile.write(s1)
@@ -1807,11 +1861,11 @@
outfile.write(s1)
s1 = " if sval_ in ('true', '1'):\n"
outfile.write(s1)
- s1 = " ival_ = 1\n"
+ s1 = " ival_ = True\n"
outfile.write(s1)
s1 = " elif sval_ in ('false', '0'):\n"
outfile.write(s1)
- s1 = " ival_ = 0\n"
+ s1 = " ival_ = False\n"
outfile.write(s1)
s1 = " else:\n"
outfile.write(s1)
@@ -1998,11 +2052,11 @@
outfile.write(s1)
s1 = " if sval_ in ('true', '1'):\n"
outfile.write(s1)
- s1 = " ival_ = 1\n"
+ s1 = " ival_ = True\n"
outfile.write(s1)
s1 = " elif sval_ in ('false', '0'):\n"
outfile.write(s1)
- s1 = " ival_ = 0\n"
+ s1 = " ival_ = False\n"
outfile.write(s1)
s1 = " else:\n"
outfile.write(s1)
@@ -2244,7 +2298,7 @@
add(', %s=%s' % (mappedName, default))
elif atype == BooleanType:
if default is None:
- add(', %s=0' % mappedName)
+ add(', %s=False' % mappedName)
else:
if default in ('false', '0'):
add(', %s=%s' % (mappedName, "False"))
@@ -2305,7 +2359,7 @@
add(', %s=%s' % (cleanName, default, ))
elif childType == BooleanType:
if default is None:
- add(', %s=0' % cleanName)
+ add(', %s=False' % cleanName)
else:
if default in ('false', '0'):
add(', %s=%s' % (cleanName, "False", ))
@@ -3023,6 +3077,7 @@
import sys
import getopt
+from string import lower
from xml.dom import minidom
from xml.dom import Node
@@ -3517,6 +3572,7 @@
#
import sys
+from string import lower
from xml.dom import minidom
from xml.sax import handler, make_parser
-------------------------------------------------------------------------
This SF.net email is sponsored by: Microsoft
Defy all challenges. Microsoft(R) Visual Studio 2008.
http://clk.atdmt.com/MRT/go/vse0120000070mrt/direct/01/
_______________________________________________
generateds-users mailing list
generateds-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/generateds-users