From 9af90933edc9f10429c728d91fc9d06391443d64 Mon Sep 17 00:00:00 2001
From: dkuhlman <none@none>
Date: Fri, 15 Feb 2013 14:02:46 -0800
Subject: [PATCH] Fix for attributeGroup reference with namespace prefix

---
 README                              | 12 ++++++--
 generateDS.html                     | 39 ++++++++++++++++++++++++-
 generateDS.py                       | 45 ++++++++++++++---------------
 generateDS.txt                      | 42 ++++++++++++++++++++++++++-
 gui/generateds_gui.py               |  2 +-
 libgenerateDS/gui/generateds_gui.py |  2 +-
 librarytemplate_howto.txt           |  2 +-
 process_includes.py                 |  2 +-
 setup.py                            |  2 +-
 tutorial/generateds_tutorial.txt    |  2 +-
 10 files changed, 117 insertions(+), 33 deletions(-)

diff --git a/README b/README
index fa09f06..9623182 100644
--- a/README
+++ b/README
@@ -141,7 +141,7 @@ SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
 Change history
 --------------
 
-Version 2.9a (02/10/2013)
+Version 2.9a (02/18/2013)
 - Added support for exporting to an Lxml element tree.  The element
   tree can then be serialized to XML, e.g. using Lxml
   etree.tostring().  This innovation is by Logan Owen, who also did
@@ -153,7 +153,15 @@ Version 2.9a (02/10/2013)
   export, export to etree (lxml element tree), or export to literal
   python code.  This will enable users to reduce bulk in their
   generated files when any or all of these are not needed.  The
-  default is "write", i.e. normal export methods.
+  default is "write literal", i.e. the normal export methods that we
+  are used to.  Use the --help command line option or read the doc
+  for a description of this option.
+- Fixed a bug that occurs when a schema has an attributeGroup
+  referenced with a name that includes a namespace prefix but the
+  attributeGroup is defined with a name that does *not* have the
+  namespace prefix.  Thanks to Mike Detecca for reporting this and
+  for nudging me in the right direction when I, initially, made the
+  wrong fix.
 
 Version 2.8c (provisional) (01/30/2013)
 - Changed generated check for attributes that are already_processed
diff --git a/generateDS.html b/generateDS.html
index 2c56439..fe174c0 100644
--- a/generateDS.html
+++ b/generateDS.html
@@ -225,7 +225,7 @@ They are used by updateversion.py. -->
 <col class="field-name" />
 <col class="field-body" />
 <tbody valign="top">
-<tr class="field"><th class="field-name">date:</th><td class="field-body">January 31, 2013</td>
+<tr class="field"><th class="field-name">date:</th><td class="field-body">February 15, 2013</td>
 </tr>
 </tbody>
 </table>
@@ -553,6 +553,18 @@ Options:
                              MemberSpec_ containing member name, type,
                              and array or not.  Allowed values are
                              &quot;list&quot; or &quot;dict&quot;.  Default: None.
+    --export=&lt;export-list&gt;   Specifies export functions to be generated.
+                             Value is a whitespace separated list of
+                             any of the following:
+                                 write -- write XML to file
+                                 literal -- write out python code
+                                 etree -- build element tree (can serialize
+                                     to XML)
+                             Examples: --export=&quot;write etree&quot;
+                                       --export=&quot;write&quot;
+                             Default: --export=&quot;write literal&quot;
+    -q, --no-questions       Do not ask questions, for example,
+                             force overwrite.
     --session=mysession.session
                              Load and use options from session file. You can
                              create session file in generateds_gui.py.
@@ -697,6 +709,31 @@ member name, type, and array or not.  See <a class="reference internal" href="#u
 section for more information about <tt class="docutils literal">MemberSpec_</tt>.  Allowed
 values are &quot;list&quot; or &quot;dict&quot;.  Default: do <em>not</em> generate member
 specifications (unless --user-methods specified).</dd>
+<dt>export</dt>
+<dd><p class="first">Specify which of the export related member methods are to be
+generated.  The value is a whitespace separated list of any of the following:</p>
+<ul class="simple">
+<li>write -- Generate methods <tt class="docutils literal">export</tt>, <tt class="docutils literal">exportAttributes</tt>,
+and <tt class="docutils literal">exportChildren</tt>.  These methods write XML to a file.</li>
+<li>literal -- Generate methods <tt class="docutils literal">exportLiteral</tt>,
+<tt class="docutils literal">exportLiteralAttributes</tt> and <tt class="docutils literal">exportLiteralChildren</tt>.
+These methods write out python code.</li>
+<li>etree -- Generate method <tt class="docutils literal">to_etree</tt>.  This method builds an
+lxml element tree, which can, for example, be serialized to
+XML using lxml's <tt class="docutils literal">tostring</tt> function and searched with the
+lxml xpath capability.  You can also iterate over nodes in the
+tree with the node's <tt class="docutils literal">getiterator</tt>, <tt class="docutils literal">iterchildren</tt>, etc,
+and use any of lxml's other capabilities.</li>
+</ul>
+<p class="last">For example: <tt class="docutils literal"><span class="pre">--export=&quot;write</span> etree&quot;</tt> and <tt class="docutils literal"><span class="pre">--export=&quot;write&quot;</span></tt>.  The
+default is: <tt class="docutils literal"><span class="pre">--export=&quot;write</span> literal&quot;</tt>.</p>
+</dd>
+<dt>q, no-questions</dt>
+<dd>Do not ask questions.  For example, if the &quot;-f&quot; command line
+option is omitted and the ouput file exists, then generateDS.py
+will not ask whether the file should be overwritten.  (In this
+case, when &quot;-q&quot; is used, the &quot;-f&quot; must be used to force the
+output file to be written.</dd>
 <dt>session=mysession.session</dt>
 <dd>Load and use options from session file. You can create a
 session file in generateds_gui.py, the graphical front-end for
diff --git a/generateDS.py b/generateDS.py
index 6cd65c2..d2a56f3 100755
--- a/generateDS.py
+++ b/generateDS.py
@@ -164,7 +164,7 @@ logging.disable(logging.INFO)
 # Do not modify the following VERSION comments.
 # Used by updateversion.py.
 ##VERSION##
-VERSION = '2.8c'
+VERSION = '2.9a'
 ##VERSION##
 
 GenerateProperties = 0
@@ -217,7 +217,7 @@ CurrentNamespacePrefix = 'xs:'
 AnyTypeIdentifier = '__ANY__'
 ExportWrite = True
 ExportEtree = False
-ExportLiteral = False
+ExportLiteral = True
 
 SchemaToPythonTypeMap = {}
 
@@ -1091,27 +1091,26 @@ class XschemaElement(XschemaElementBase):
             self.replace_attributeGroup_names_1(groupName)
 
     def replace_attributeGroup_names_1(self, groupName):
-            key = None
-            if groupName in AttributeGroups:
-                key = groupName
-            else:
-                # Looking for name space prefix
-                keyList = groupName.split(':')
-                if len(keyList) > 1:
-                    key1 = keyList[1]
-                    if key1 in AttributeGroups:
-                        key = key1
-            if key is not None:
-                attrGroup = AttributeGroups[key]
-                for name in attrGroup.getKeys():
-                    if name in AttributeGroups:
-                        self.replace_attributeGroup_names_1(name)
-                    else:
-                        attr = attrGroup.get(name)
-                        self.attributeDefs[name] = attr
-            else:
-                err_msg('*** Error. attributeGroup %s not defined.\n' % (
-                    groupName, ))
+        key = None
+        if groupName in AttributeGroups:
+            key = groupName
+        else:
+            # Looking for name space prefix
+            key1 = strip_namespace(groupName)
+            if key1 != groupName and key1 in AttributeGroups:
+                key = key1
+        if key is not None:
+            attrGroup = AttributeGroups[key]
+            for name in attrGroup.getKeys():
+                if (name in AttributeGroups or
+                    strip_namespace(name) in AttributeGroups):
+                    self.replace_attributeGroup_names_1(name)
+                else:
+                    attr = attrGroup.get(name)
+                    self.attributeDefs[name] = attr
+        else:
+            err_msg('*** Error. attributeGroup %s not defined.\n' % (
+                groupName, ))
 
     def __str__(self):
         s1 = '<XschemaElement name: "%s" type: "%s">' % \
diff --git a/generateDS.txt b/generateDS.txt
index f52a60f..964aa12 100644
--- a/generateDS.txt
+++ b/generateDS.txt
@@ -11,7 +11,7 @@ generateDS -- Generate Data Structures from XML Schema
 
 .. version
 
-:revision: 2.8c
+:revision: 2.9a
 
 .. version
 
@@ -261,6 +261,18 @@ Here is the usage message displayed by ``generateDS.py``::
                                  MemberSpec_ containing member name, type,
                                  and array or not.  Allowed values are
                                  "list" or "dict".  Default: None.
+        --export=<export-list>   Specifies export functions to be generated.
+                                 Value is a whitespace separated list of
+                                 any of the following:
+                                     write -- write XML to file
+                                     literal -- write out python code
+                                     etree -- build element tree (can serialize
+                                         to XML)
+                                 Examples: --export="write etree"
+                                           --export="write"
+                                 Default: --export="write literal"
+        -q, --no-questions       Do not ask questions, for example,
+                                 force overwrite.
         --session=mysession.session
                                  Load and use options from session file. You can
                                  create session file in generateds_gui.py.
@@ -422,6 +434,34 @@ member-specs
     values are "list" or "dict".  Default: do *not* generate member
     specifications (unless --user-methods specified).
 
+export
+    Specify which of the export related member methods are to be
+    generated.  The value is a whitespace separated list of any of the following:
+
+    - write -- Generate methods ``export``, ``exportAttributes``,
+      and ``exportChildren``.  These methods write XML to a file.
+
+    - literal -- Generate methods ``exportLiteral``,
+      ``exportLiteralAttributes`` and ``exportLiteralChildren``.
+      These methods write out python code.
+
+    - etree -- Generate method ``to_etree``.  This method builds an
+      lxml element tree, which can, for example, be serialized to
+      XML using lxml's ``tostring`` function and searched with the
+      lxml xpath capability.  You can also iterate over nodes in the
+      tree with the node's ``getiterator``, ``iterchildren``, etc,
+      and use any of lxml's other capabilities.
+
+    For example: ``--export="write etree"`` and ``--export="write"``.  The
+    default is: ``--export="write literal"``.
+
+q, no-questions
+    Do not ask questions.  For example, if the "-f" command line
+    option is omitted and the ouput file exists, then generateDS.py
+    will not ask whether the file should be overwritten.  (In this
+    case, when "-q" is used, the "-f" must be used to force the
+    output file to be written.
+
 session=mysession.session
     Load and use options from session file. You can create a
     session file in generateds_gui.py, the graphical front-end for
diff --git a/gui/generateds_gui.py b/gui/generateds_gui.py
index c05f07b..d144613 100755
--- a/gui/generateds_gui.py
+++ b/gui/generateds_gui.py
@@ -31,7 +31,7 @@ from libgenerateDS.gui import generateds_gui_session
 # Do not modify the following VERSION comments.
 # Used by updateversion.py.
 ##VERSION##
-VERSION = '2.8c'
+VERSION = '2.9a'
 ##VERSION##
 
 
diff --git a/libgenerateDS/gui/generateds_gui.py b/libgenerateDS/gui/generateds_gui.py
index c05f07b..d144613 100755
--- a/libgenerateDS/gui/generateds_gui.py
+++ b/libgenerateDS/gui/generateds_gui.py
@@ -31,7 +31,7 @@ from libgenerateDS.gui import generateds_gui_session
 # Do not modify the following VERSION comments.
 # Used by updateversion.py.
 ##VERSION##
-VERSION = '2.8c'
+VERSION = '2.9a'
 ##VERSION##
 
 
diff --git a/librarytemplate_howto.txt b/librarytemplate_howto.txt
index abc5fb0..80cc4a4 100644
--- a/librarytemplate_howto.txt
+++ b/librarytemplate_howto.txt
@@ -8,7 +8,7 @@ How to package a generateDS.py generated library
 
 .. version
 
-:revision: 2.8c
+:revision: 2.9a
 
 .. version
 
diff --git a/process_includes.py b/process_includes.py
index ad2c052..26ce763 100755
--- a/process_includes.py
+++ b/process_includes.py
@@ -30,7 +30,7 @@ from lxml import etree
 # Do not modify the following VERSION comments.
 # Used by updateversion.py.
 ##VERSION##
-VERSION = '2.8c'
+VERSION = '2.9a'
 ##VERSION##
 
 Namespaces = {'xs': 'http://www.w3.org/2001/XMLSchema'}
diff --git a/setup.py b/setup.py
index f6e72db..c9161c0 100644
--- a/setup.py
+++ b/setup.py
@@ -7,7 +7,7 @@ setup(name="generateDS",
 # Do not modify the following VERSION comments.
 # Used by updateversion.py.
 ##VERSION##
-    version="2.8c",
+    version="2.9a",
 ##VERSION##
     author="Dave Kuhlman",
     author_email="dkuhlman@rexx.com",
diff --git a/tutorial/generateds_tutorial.txt b/tutorial/generateds_tutorial.txt
index 1f50f31..19746c1 100644
--- a/tutorial/generateds_tutorial.txt
+++ b/tutorial/generateds_tutorial.txt
@@ -11,7 +11,7 @@ generateDS -- Introduction and Tutorial
 
 .. version
 
-:revision: 2.8c
+:revision: 2.9a
 
 .. version
 
-- 
GitLab