> From: Shahaf Abileah
>Sent: Monday, August 19, 2013 8:42 AM
>
Shahaf -
Attached is a patch file with the fix for the problem with naming
anonymous types. The patch file shows the difference against
v. 2.11a.
You can also find the patched version at Bitbucket:
https://bitbucket.org/dkuhlman/generateds
I'll likely wait a bit to see whether there are other changes needed
before I release a new version.
Again, thanks for your help with this.
- Dave
--
Dave Kuhlman
http://www.rexx.com/~dkuhlman
=== modified file 'Generateds/Generateds/process_includes.py'
--- Generateds/Generateds/process_includes.py 2013-08-14 20:59:17 +0000
+++ Generateds/Generateds/process_includes.py 2013-08-19 18:14:23 +0000
@@ -30,7 +30,7 @@
# Do not modify the following VERSION comments.
# Used by updateversion.py.
##VERSION##
-VERSION = '2.11a'
+VERSION = '2.11b'
##VERSION##
Namespaces = {'xs': 'http://www.w3.org/2001/XMLSchema'}
@@ -297,19 +297,8 @@
""" Raise each anonymous complexType to top level and give it a name.
Rename if necessary to prevent duplicates.
"""
- element_tag = '{%s}element' % (Xsd_namespace_uri, )
- def_names = {}
+ def_names = collect_type_names(root)
def_count = 0
- # Collect top level complexTypes.
- defs = root.xpath('./xs:complexType', namespaces=Namespaces)
- for node in defs:
- type_name = node.get('name')
- def_names[type_name] = node
- # Collect top level simpleTypes.
- defs = root.xpath('./xs:simpleType', namespaces=Namespaces)
- for node in defs:
- type_name = node.get('name')
- def_names[type_name] = node
# Find all complexTypes below top level.
# Raise them to top level and name them.
# Re-name if there is a duplicate (simpleType, complexType, or
@@ -320,7 +309,15 @@
el = etree.Comment(text="Raised anonymous complexType definitions")
el.tail = "\n\n"
root.append(el)
- defs = root.xpath('./*/*//xs:complexType', namespaces=Namespaces)
+ prefix = root.prefix
+ if prefix:
+ pattern = './*/*//%s:complexType|./*/*//%s:simpleType' % (
+ prefix, prefix, )
+ element_tag = '{%s}element' % (root.nsmap[prefix], )
+ else:
+ pattern = './*/*//complexType|./*/*//simpleType'
+ element_tag = 'element'
+ defs = root.xpath(pattern, namespaces=Namespaces)
for node in defs:
parent = node.getparent()
if parent.tag != element_tag:
@@ -330,19 +327,38 @@
continue
type_name = '%sType' % (name, )
type_name, def_count = unique_name(type_name, def_names, def_count)
- def_names[type_name] = node
+ def_names.add(type_name)
parent.set('type', type_name)
node.set('name', type_name)
# Move the complexType node to top level.
root.append(node)
+#
+# Collect the names of all currently defined types (complexType,
+# simpleType, element).
+def collect_type_names(node):
+ prefix = node.prefix
+ if prefix:
+ pattern = './/%s:complexType|.//%s:simpleType|.//%s:element' % (
+ prefix, prefix, prefix)
+ else:
+ pattern = './/complexType|.//simpleType|.//element'
+ elements = node.xpath(pattern, namespaces=node.nsmap)
+ names = [
+ el.attrib['name'] for el in elements if
+ 'name' in el.attrib and el.getchildren()
+ ]
+ names = set(names)
+ return names
+
+
def unique_name(type_name, def_names, def_count):
orig_type_name = type_name
while True:
- def_count += 1
if type_name not in def_names:
return type_name, def_count
+ def_count += 1
type_name = '%s%d' % (orig_type_name, def_count, )
------------------------------------------------------------------------------
Introducing Performance Central, a new site from SourceForge and
AppDynamics. Performance Central is your source for news, insights,
analysis and resources for efficient Application Performance Management.
Visit us today!
http://pubads.g.doubleclick.net/gampad/clk?id=48897511&iu=/4140/ostg.clktrk
_______________________________________________
generateds-users mailing list
generateds-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/generateds-users