diff --git a/README.rst b/README.rst index f352ecfcb8fab295c2fba3bf4a91e174a15a5812..17b81104cd3eb3403e91b0b4519d2763a235d955 100644 --- a/README.rst +++ b/README.rst @@ -141,6 +141,40 @@ SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. Change history -------------- +Version 2.27a (06/01/2017) + +- Fixed bug in gends_extract_simple_types.py that caused an + exception when the simpleType name has a namespace prefix. + Thanks to Rémy Gibault for reporting this. +- Added two utilities that can be used to replace the capability + invoked by the --one-file-per-xsd command line option. + utils/collect_schema_locations.py can be used to collect and write + out the top level schema locations. batch_generate.py can be used + to (read the output from collect_schema_locations.py and generate + modules. Use --help to obtain more information from each of + these. For instructions on this, see the docs and also the README + in the utils/ subdirectory. +- Various fixes for the generation of namespace prefix definitions + when the generated export functions are called. Thanks to Eugene + Petkevich for reporting and working with me on this. +- Added command line option --no-namespace-defs to force export + functions to not added namespace prefix defintions. +- Added ability for generated modules to import a module + (generatedsnamespaces.py) containing a dictionary + (GenerateDSNamespaceDefs) that maps element type names to the + namespace prefix definitions (or any XML attributes, actually) + that are to be added to specific elements during export. See the + docs and also notes near where generatedsnamespaces.py is imported + in a generated module. +- Fixed an error in gends_run_gen_django.py which caused it to fail + when generateDS.py produced a warning message. Thanks to Rémy + Gibault for catching and reporting this. +- Added a utility to help with analyzing complex schemas. + utils/show_schema_hierarchy.py can by used to show an indented + hierarchy of schemas that are pulled in by xs:include and + xs:import elements. Type `utils/show_schema_hierarchy.py --help` + for more info. Also see the docs. + Version 2.26a (05/09/2017) - Added command line options --no-collect-includes and diff --git a/django/gends_extract_simple_types.py b/django/gends_extract_simple_types.py index 07865cb9aeba2138bacc01192f023e71cc1ec128..a210580a46a858d89e47dde6eba8e86936f851dd 100755 --- a/django/gends_extract_simple_types.py +++ b/django/gends_extract_simple_types.py @@ -274,9 +274,16 @@ def resolve_1_simple_type(descriptor, resolved, unresolved): resolved[descriptor.name] = descriptor return type_obj else: - #import pdb; pdb.set_trace() + type_name = descriptor.type_name + if type_name not in unresolved: + # If we can't find it, try after stripping off namespace prefix. + type_name = type_name.split(':')[-1] + if type_name not in unresolved: + raise XmlSchemaError( + "Can't find simple type (%s) in unresolved types." % ( + type_name)) type_obj = resolve_1_simple_type( - unresolved[descriptor.type_name], + unresolved[type_name], resolved, unresolved) descriptor.type_obj = type_obj resolved[descriptor.name] = descriptor diff --git a/django/gends_run_gen_django.py b/django/gends_run_gen_django.py index 2786368b40bba8b2d3f0cf75ce8b1c1722b019e8..51ed73ff1b66107a314212e0788b677d39899a3b 100755 --- a/django/gends_run_gen_django.py +++ b/django/gends_run_gen_django.py @@ -32,6 +32,7 @@ import sys import getopt import os from subprocess import Popen, PIPE +from glob import glob # @@ -61,7 +62,16 @@ def generate(options, schema_file_name): admin_file_name = 'admin.py' dbg_msg(options, 'schema_name_stem: %s\n' % (schema_name_stem, )) dbg_msg(options, 'bindings_file_name: %s\n' % (bindings_file_name, )) - if not options['force']: + if options['force']: + file_names = ( + glob(bindings_file_name) + + glob('%s.pyc' % bindings_file_stem) + + glob('__pycache__/%s.*.pyc' % bindings_file_stem) + ) + for file_name in file_names: + dbg_msg(options, 'removing: %s\n' % file_name) + os.remove(file_name) + else: flag1 = exists(bindings_file_name) flag2 = exists(model_file_name) flag3 = exists(form_file_name) @@ -101,14 +111,12 @@ def run_cmd(options, args): content2 = process.stdout.read() if content1: sys.stderr.write('*** error ***\n') - sys.stderr.write(content1) + sys.stderr.write(content1.decode('utf-8')) sys.stderr.write('*** error ***\n') - return False if content2: dbg_msg(options, '*** message ***\n') - dbg_msg(options, content2) + dbg_msg(options, content2.decode('utf-8')) dbg_msg(options, '*** message ***\n') - return True return True diff --git a/generateDS.html b/generateDS.html index cd00184dbc45e790e32604e215a32360b28910d0..14696493bde5693e88d0fc34cbd5dd049ac49935 100644 --- a/generateDS.html +++ b/generateDS.html @@ -220,7 +220,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">revision:</th><td class="field-body">2.26a</td> +<tr class="field"><th class="field-name">revision:</th><td class="field-body">2.27a</td> </tr> </tbody> </table> @@ -229,7 +229,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">May 09, 2017</td> +<tr class="field"><th class="field-name">date:</th><td class="field-body">June 01, 2017</td> </tr> </tbody> </table> @@ -357,35 +357,40 @@ to process the contents of an XML document.</td> <li><a class="reference internal" href="#id4" id="id78">12.7 Mixed content</a></li> <li><a class="reference internal" href="#id6" id="id79">12.8 anyAttribute</a></li> <li><a class="reference internal" href="#user-methods" id="id80">12.9 User Methods</a></li> -<li><a class="reference internal" href="#overridable-methods" id="id81">12.10 Overridable methods</a></li> +<li><a class="reference internal" href="#overridable-methods-generatedssuper-py" id="id81">12.10 Overridable methods -- generatedssuper.py</a></li> <li><a class="reference internal" href="#the-element-name-to-class-name-dictionary" id="id82">12.11 The element name to class name dictionary</a></li> +<li><a class="reference internal" href="#adding-custom-exported-attributes-and-namespace-prefix-definitions" id="id83">12.12 Adding custom exported attributes and namespace prefix definitions</a></li> </ul> </li> -<li><a class="reference internal" href="#one-per-generating-separate-files-from-imported-included-schemas" id="id83">13 "One Per" -- generating separate files from imported/included schemas</a></li> -<li><a class="reference internal" href="#how-to-modify-the-generated-code" id="id84">14 How to modify the generated code</a><ul class="auto-toc"> -<li><a class="reference internal" href="#adding-features-to-class-definitions" id="id85">14.1 Adding features to class definitions</a></li> +<li><a class="reference internal" href="#one-per-generating-separate-files-from-imported-included-schemas" id="id84">13 "One Per" -- generating separate files from imported/included schemas</a><ul class="auto-toc"> +<li><a class="reference internal" href="#approach-1-command-line-option-one-file-per-xsd" id="id85">13.1 Approach 1 -- Command line option --one-file-per-xsd</a></li> +<li><a class="reference internal" href="#approach-2-extraction-and-generation-utilities" id="id86">13.2 Approach 2 -- Extraction and generation utilities</a></li> </ul> </li> -<li><a class="reference internal" href="#examples-and-demonstrations" id="id86">15 Examples and demonstrations</a><ul class="auto-toc"> -<li><a class="reference internal" href="#django-generating-models-and-forms" id="id87">15.1 Django -- Generating Models and Forms</a><ul class="auto-toc"> -<li><a class="reference internal" href="#how-to-generate-django-models-and-forms" id="id88">15.1.1 How to generate Django models and forms</a></li> -<li><a class="reference internal" href="#how-it-works" id="id89">15.1.2 How it works</a></li> +<li><a class="reference internal" href="#how-to-modify-the-generated-code" id="id87">14 How to modify the generated code</a><ul class="auto-toc"> +<li><a class="reference internal" href="#adding-features-to-class-definitions" id="id88">14.1 Adding features to class definitions</a></li> </ul> </li> +<li><a class="reference internal" href="#examples-and-demonstrations" id="id89">15 Examples and demonstrations</a><ul class="auto-toc"> +<li><a class="reference internal" href="#django-generating-models-and-forms" id="id90">15.1 Django -- Generating Models and Forms</a><ul class="auto-toc"> +<li><a class="reference internal" href="#how-to-generate-django-models-and-forms" id="id91">15.1.1 How to generate Django models and forms</a></li> +<li><a class="reference internal" href="#how-it-works" id="id92">15.1.2 How it works</a></li> </ul> </li> -<li><a class="reference internal" href="#sample-code-and-extensions" id="id90">16 Sample code and extensions</a><ul class="auto-toc"> -<li><a class="reference internal" href="#capturing-xs-date-elements-as-dates" id="id91">16.1 Capturing xs:date elements as dates</a></li> </ul> </li> -<li><a class="reference internal" href="#limitations-of-generateds" id="id92">17 Limitations of generateDS</a><ul class="auto-toc"> -<li><a class="reference internal" href="#xml-schema-limitations" id="id93">17.1 XML Schema limitations</a></li> +<li><a class="reference internal" href="#sample-code-and-extensions" id="id93">16 Sample code and extensions</a><ul class="auto-toc"> +<li><a class="reference internal" href="#capturing-xs-date-elements-as-dates" id="id94">16.1 Capturing xs:date elements as dates</a></li> </ul> </li> -<li><a class="reference internal" href="#includes-the-xml-schema-xs-include-and-xs-import-elements" id="id94">18 Includes -- The XML schema xs:include and xs:import elements</a></li> -<li><a class="reference internal" href="#processing-relaxng-schemas" id="id95">19 Processing RelaxNG schemas</a></li> -<li><a class="reference internal" href="#acknowledgments" id="id96">20 Acknowledgments</a></li> -<li><a class="reference internal" href="#see-also" id="id97">21 See also</a></li> +<li><a class="reference internal" href="#limitations-of-generateds" id="id95">17 Limitations of generateDS</a><ul class="auto-toc"> +<li><a class="reference internal" href="#xml-schema-limitations" id="id96">17.1 XML Schema limitations</a></li> +</ul> +</li> +<li><a class="reference internal" href="#includes-the-xml-schema-xs-include-and-xs-import-elements" id="id97">18 Includes -- The XML schema xs:include and xs:import elements</a></li> +<li><a class="reference internal" href="#processing-relaxng-schemas" id="id98">19 Processing RelaxNG schemas</a></li> +<li><a class="reference internal" href="#acknowledgments" id="id99">20 Acknowledgments</a></li> +<li><a class="reference internal" href="#see-also" id="id100">21 See also</a></li> </ul> </div> <div class="section" id="introduction"> @@ -610,6 +615,10 @@ Options: the export() method by the generated parse() and parseString() functions. Default=''. + --no-namespace-defs Do not pass namespace definitions as the value + for the namespacedef_ parameter of the export + method, even if it can be extraced from the + schema. --external-encoding=<encoding> Encode output written by the generated export methods using this encoding. Default, if omitted, @@ -850,6 +859,14 @@ specified, then the export function will insert a namespace prefix definition attribute in the top-most (outer-most) element. (Actually, you can insert any attribute.) The default is an empty string.</dd> +<dt>no-namespace-defs</dt> +<dd>Do not pass namespace definitions as the value for the +<tt class="docutils literal">namespacedef_</tt> parameter of the export method, even if it can +be extraced from the schema. The default is off. You might +want to consider using this in combination with the ability to +attach namespace prefix definitions to specific element types +during export, as described here: <a class="reference internal" href="#adding-custom-exported-attributes-and-namespace-prefix-definitions">Adding custom exported +attributes and namespace prefix definitions</a>.</dd> <dt>external-encoding=<encoding></dt> <dd>If an XML instance document contains character data or attribute values that are not in the ASCII character set, then @@ -887,7 +904,7 @@ tree with the node's <tt class="docutils literal">getiterator</tt>, <tt class="d and use any of lxml's other capabilities.</li> </ul> <p class="last">For example: <tt class="docutils literal"><span class="pre">--export="write</span> etree"</tt> and <tt class="docutils literal"><span class="pre">--export="write"</span></tt>. The -default is: <tt class="docutils literal"><span class="pre">--export="write</span> literal"</tt>.</p> +default is: <tt class="docutils literal"><span class="pre">--export="write"</span></tt>.</p> </dd> <dt>preserve-cdata-tags</dt> <dd>Preserve CDATA tags. Normally, CDATA tags ("<![CDATA[ ... ]]>") @@ -1387,8 +1404,8 @@ off validation.</li> generated validation code calls <tt class="docutils literal">gds_validate_xxx</tt>, where "xxx" is a base, simple type. In some cases, you will be able to add additional code to that method to perform custom checking. See -section <a class="reference internal" href="#overridable-methods">Overridable methods</a> for information on how to use and -override that class.</li> +section <a class="reference internal" href="#overridable-methods-generatedssuper-py">Overridable methods -- generatedssuper.py</a> for +information on how to use and override that class.</li> <li>When validation finds data that fails to validate, it generates a warning (using the <tt class="docutils literal">warnings</tt> module from the Python standard library), not an exception, so that processing continues.</li> @@ -2050,9 +2067,9 @@ instance document, it generates a call to a method <tt class="docutils literal"> in the <tt class="docutils literal">GeneratedsSuper</tt> class. This method has a default implementation in the generated code. If your XML schema uses <tt class="docutils literal">xs:any</tt>, you may need to add some code to that default -implementation of <tt class="docutils literal">gds_build_any</tt>. See section <a class="reference internal" href="#overridable-methods">Overridable -methods</a> for guidance on how to provide an implementation of that -method.</p> +implementation of <tt class="docutils literal">gds_build_any</tt>. See section <a class="reference internal" href="#overridable-methods-generatedssuper-py">Overridable +methods -- generatedssuper.py</a> for guidance on how to provide an +implementation of that method.</p> <p>For more help with this, look at the code generated from an XML schema that uses <tt class="docutils literal">xs:any</tt>. In particular, look at the code generated in the Python class corresponding to the @@ -2688,8 +2705,8 @@ source code and the class_name pattern in each specification.</li> <li>Repeat as necessary.</li> </ol> </div> -<div class="section" id="overridable-methods"> -<h2><a class="toc-backref" href="#id81">12.10 Overridable methods</a></h2> +<div class="section" id="overridable-methods-generatedssuper-py"> +<h2><a class="toc-backref" href="#id81">12.10 Overridable methods -- generatedssuper.py</a></h2> <p><tt class="docutils literal">generateDS.py</tt> generates calls to several methods that each have a default implementation in a superclass. The default superclass with default implementations is included in the generated code. @@ -2815,9 +2832,58 @@ that complexType definition. This dictionary is named <tt class="docutils literal">GDSClassesMapping</tt>. You will find it in the module generated with the "-o" option.</p> </div> +<div class="section" id="adding-custom-exported-attributes-and-namespace-prefix-definitions"> +<h2><a class="toc-backref" href="#id83">12.12 Adding custom exported attributes and namespace prefix definitions</a></h2> +<p>You can add additional attributes to exported XML content by (1) +providing a module named <tt class="docutils literal">generatedsnamespaces.py</tt>; (2) placing +that module somewhere so that it can be imported when you "run" your +generated module; and (3) including in <tt class="docutils literal">generatedsnamespaces.py</tt> a +global variable named <tt class="docutils literal">GenerateDSNamespaceDefs</tt> whose value is a +Python dictionary. The keys in this dictionary should be element +type names in the generated module. And the values should be text +strings that are attributes to be added to exported elements of that +type.</p> +<p>Here is an example:</p> +<pre class="literal-block"> +# file: generatedsnamespaces.py + +GenerateDSNamespaceDefs = { + "A1ElementType": 'xmlns:abc="http://www.abc.com/namespace_a1"', + "A2ElementType": 'xmlns:abc="http://www.abc.com/namespace_a2"', +} +</pre> +<p>Notes:</p> +<ul class="simple"> +<li>While the original intension of this facility was to enable the +user to add XML namespace prefix definitions to the XML content in +exported files, you can use it to add other attribute definitions +as well.</li> +<li>If you find that <tt class="docutils literal">generateDS.py</tt> is adding a specific namespace +prefix definition to many exported XML elements and you want to +suppress this behavior, take a look at the <tt class="docutils literal"><span class="pre">--no-namespace-defs</span></tt> +command line option. In particular, this command line option may +be useful when used together with the capability described in this +section (<tt class="docutils literal">generatedsnamespaces.py</tt>).</li> +</ul> +</div> </div> <div class="section" id="one-per-generating-separate-files-from-imported-included-schemas"> -<h1><a class="toc-backref" href="#id83">13 "One Per" -- generating separate files from imported/included schemas</a></h1> +<h1><a class="toc-backref" href="#id84">13 "One Per" -- generating separate files from imported/included schemas</a></h1> +<p>The <tt class="docutils literal">generateDS.py</tt> project provides support for two approaches to +this task:</p> +<ul class="simple"> +<li>The first (<a class="reference internal" href="#approach-1-command-line-option-one-file-per-xsd">Approach 1 -- Command line option +--one-file-per-xsd</a>, below) is likely to be easier to use, but if +it does not work for you as is, it is very difficult to customize.</li> +<li>The second method (<a class="reference internal" href="#approach-2-extraction-and-generation-utilities">Approach 2 -- Extraction and generation +utilities</a>, below) may require a little more work and +understanding, but offers more options and customization, and, +since the scripts that implement it are short and rather simple, +may be easier to customize or even re-write for your specific +needs.</li> +</ul> +<div class="section" id="approach-1-command-line-option-one-file-per-xsd"> +<h2><a class="toc-backref" href="#id85">13.1 Approach 1 -- Command line option --one-file-per-xsd</a></h2> <p>The <tt class="docutils literal"><span class="pre">--one-file-per-xsd</span></tt> command line option enables you to generate a separate Python module for each XML schema that is imported or included (using <tt class="docutils literal"><xs:import></tt> or <tt class="docutils literal"><xs:include></tt>) by @@ -2869,12 +2935,54 @@ directory into a Python package.</p> </li> </ul> </div> +<div class="section" id="approach-2-extraction-and-generation-utilities"> +<h2><a class="toc-backref" href="#id86">13.2 Approach 2 -- Extraction and generation utilities</a></h2> +<p>The <tt class="docutils literal">generateds/utils</tt> subdirectory contains two utility scripts +that may help with this task. The procedure is as follows:</p> +<ol class="arabic simple"> +<li>First, use <tt class="docutils literal">utils/collect_schema_locations.py</tt> to collect a set +of directives, one for each (included) schema and each module to +be generated. This utility writes out a JSON file that contains +the directives to be used in the next step.</li> +<li>Next, use <tt class="docutils literal">utils/batch_generate.py</tt> to generate one module (or +perhaps two modules, see below) for each directive in that JSON +file.</li> +</ol> +<p>Each of these modules gives a reasonable amount of usage information +in response to the <tt class="docutils literal"><span class="pre">--help</span></tt> command line option.</p> +<p>A few hints and suggestions:</p> +<ul class="simple"> +<li>After generating the JSON directives file you can modify it with +your text editor. For example, (1) you can add the name of +sub-class modules to be generated by <tt class="docutils literal">generateDS.py</tt>; (2) you +can specify command line options to be used by <tt class="docutils literal">generateDS.py</tt> +when generating specific modules; and (3) you can add new +directives to generate additional modules.</li> +<li>If you find yourself typing the same command line options to +<tt class="docutils literal">utils/batch_generate.py</tt> over and over, there is a facility to +put command line options that have long names (i.e., not one +character names) into a configuration file. The usage information +produced by <tt class="docutils literal">utils/batch_generate.py <span class="pre">--help</span></tt> shows an example. +Then use <tt class="docutils literal">utils/batch_generate.py <span class="pre">--config=myoptins.config</span> ...</tt> +to feed this configuration file to <tt class="docutils literal">utils/batch_generate.py</tt>. +The options in this configuration file can be overridden by those +entered on the command line.</li> +<li>The JSON directives file can contain comments, even though this is +not part of the JSON standard. A comment is any line that begins +with "//" where the "//" is proceeded only by white space +characters. <tt class="docutils literal">utils/batch_generate.py</tt> strips these lines out +before parsing the JSON file. However, if you plan to process +this JSON file with other processes, you will likely either not +want to add comments or plan to pre-process them in some way.</li> +</ul> +</div> +</div> <div class="section" id="how-to-modify-the-generated-code"> -<h1><a class="toc-backref" href="#id84">14 How to modify the generated code</a></h1> +<h1><a class="toc-backref" href="#id87">14 How to modify the generated code</a></h1> <p>This section attempts to explain how to modify and add features to the generated code.</p> <div class="section" id="adding-features-to-class-definitions"> -<h2><a class="toc-backref" href="#id85">14.1 Adding features to class definitions</a></h2> +<h2><a class="toc-backref" href="#id88">14.1 Adding features to class definitions</a></h2> <p>You can add new member definitions to a generated class. Look at the 'export' and 'exportLiteral' member functions for examples of how to access member variables and how to walk nested @@ -2919,7 +3027,7 @@ parser, for example, since generating the file.</li> </div> </div> <div class="section" id="examples-and-demonstrations"> -<h1><a class="toc-backref" href="#id86">15 Examples and demonstrations</a></h1> +<h1><a class="toc-backref" href="#id89">15 Examples and demonstrations</a></h1> <p>Under the directory Demos are several examples:</p> <ul class="simple"> <li>Demos/People provides a simple demonstration of generating @@ -2945,7 +3053,7 @@ containing explicit control logic, the order in which nodes of the parsed XML document are visited is under your control.</li> </ul> <div class="section" id="django-generating-models-and-forms"> -<h2><a class="toc-backref" href="#id87">15.1 Django -- Generating Models and Forms</a></h2> +<h2><a class="toc-backref" href="#id90">15.1 Django -- Generating Models and Forms</a></h2> <p><tt class="docutils literal">generateDS.py</tt> can be used to generate Django models and Django forms that represent the data structures defined in an XML Schema.</p> <p><strong>Note:</strong> In order to use this capability, you must obtain the @@ -2979,7 +3087,7 @@ use the "-p" command line option. For more information, do:</p> python gends_run_gen_django.py --help </pre> <div class="section" id="how-to-generate-django-models-and-forms"> -<h3><a class="toc-backref" href="#id88">15.1.1 How to generate Django models and forms</a></h3> +<h3><a class="toc-backref" href="#id91">15.1.1 How to generate Django models and forms</a></h3> <p><strong>Warning:</strong> Running this script attempts to over-write the following files in the current directory:</p> <ul class="simple"> @@ -3027,7 +3135,7 @@ Django application.</p> </ol> </div> <div class="section" id="how-it-works"> -<h3><a class="toc-backref" href="#id89">15.1.2 How it works</a></h3> +<h3><a class="toc-backref" href="#id92">15.1.2 How it works</a></h3> <p>Here are a few notes that might be helpful if and when you need to do some debugging or extend the current capabilities or write a new "meta-app" that uses the same approach but does something new and @@ -3054,9 +3162,9 @@ root super class of all generated data representation classes.</p> </div> </div> <div class="section" id="sample-code-and-extensions"> -<h1><a class="toc-backref" href="#id90">16 Sample code and extensions</a></h1> +<h1><a class="toc-backref" href="#id93">16 Sample code and extensions</a></h1> <div class="section" id="capturing-xs-date-elements-as-dates"> -<h2><a class="toc-backref" href="#id91">16.1 Capturing xs:date elements as dates</a></h2> +<h2><a class="toc-backref" href="#id94">16.1 Capturing xs:date elements as dates</a></h2> <p>The following extension employs a user method (see <a class="reference internal" href="#user-methods">User Methods</a>) in order to capture elements defined as xs:date as date objects.</p> @@ -3125,9 +3233,9 @@ import types </div> </div> <div class="section" id="limitations-of-generateds"> -<h1><a class="toc-backref" href="#id92">17 Limitations of generateDS</a></h1> +<h1><a class="toc-backref" href="#id95">17 Limitations of generateDS</a></h1> <div class="section" id="xml-schema-limitations"> -<h2><a class="toc-backref" href="#id93">17.1 XML Schema limitations</a></h2> +<h2><a class="toc-backref" href="#id96">17.1 XML Schema limitations</a></h2> <p>There are things in Xschema that are not supported. You will have to use a restricted sub-set of Xschema to define your data structures. See above for supported features. See people.xsd and @@ -3137,7 +3245,7 @@ does not work.</p> </div> </div> <div class="section" id="includes-the-xml-schema-xs-include-and-xs-import-elements"> -<h1><a class="toc-backref" href="#id94">18 Includes -- The XML schema xs:include and xs:import elements</a></h1> +<h1><a class="toc-backref" href="#id97">18 Includes -- The XML schema xs:include and xs:import elements</a></h1> <p>While <tt class="docutils literal">generateDS.py</tt> itself does not process XML Schema <tt class="docutils literal">include</tt> elements, the distribution provides a script <tt class="docutils literal">process_includes.py</tt> that can be used as a preprocessor. @@ -3171,7 +3279,7 @@ $ python process_includes.py --help </pre> </div> <div class="section" id="processing-relaxng-schemas"> -<h1><a class="toc-backref" href="#id95">19 Processing RelaxNG schemas</a></h1> +<h1><a class="toc-backref" href="#id98">19 Processing RelaxNG schemas</a></h1> <p>RelaxNG is a schema definition language and is an alternative to XML Schema. For more information on RelaxNG, see: <a class="reference external" href="http://relaxng.org/">http://relaxng.org/</a>.</p> <p><tt class="docutils literal">generateDS.py</tt> does not understand or process RelaxNG schemas. @@ -3212,7 +3320,7 @@ through <tt class="docutils literal">generateDS.py</tt>:</p> <a class="reference external" href="https://github.com/relaxng/jing-trang">https://github.com/relaxng/jing-trang</a></p> </div> <div class="section" id="acknowledgments"> -<h1><a class="toc-backref" href="#id96">20 Acknowledgments</a></h1> +<h1><a class="toc-backref" href="#id99">20 Acknowledgments</a></h1> <p>Many thanks to those who have used <tt class="docutils literal">generateDS.py</tt> and have contributed their comments and suggestions. These comments have been valuable both in teaching me about things I needed to know in @@ -3226,7 +3334,7 @@ following among others:</p> </ul> </div> <div class="section" id="see-also"> -<h1><a class="toc-backref" href="#id97">21 See also</a></h1> +<h1><a class="toc-backref" href="#id100">21 See also</a></h1> <p><a class="reference external" href="http://www.python.org">Python</a>: The Python home page.</p> <p><a class="reference external" href="http://www.davekuhlman.org">Dave's Page</a>: My home page, which contains more Python stuff.</p> <!-- vim:ft=rst: --> @@ -3235,7 +3343,7 @@ following among others:</p> <div class="footer"> <hr class="footer" /> <a class="reference external" href="generateDS.txt">View document source</a>. -Generated on: 2017-05-09 21:57 UTC. +Generated on: 2017-06-01 16:00 UTC. Generated by <a class="reference external" href="http://docutils.sourceforge.net/">Docutils</a> from <a class="reference external" href="http://docutils.sourceforge.net/rst.html">reStructuredText</a> source. </div> diff --git a/generateDS.py b/generateDS.py index 54f26f7f7ae9fd577ec71ebbdfa3e7fefff058e5..632f573f81c58235c5ed5d9075418a74e34f1dbd 100755 --- a/generateDS.py +++ b/generateDS.py @@ -80,6 +80,10 @@ Options: the export() method by the generated parse() and parseString() functions. Default=''. + --no-namespace-defs Do not pass namespace definitions as the value + for the namespacedef_ parameter of the export + method, even if it can be extraced from the + schema. --external-encoding=<encoding> Encode output written by the generated export methods using this encoding. Default, if omitted, @@ -213,7 +217,7 @@ logging.disable(logging.INFO) # Do not modify the following VERSION comments. # Used by updateversion.py. ##VERSION## -VERSION = '2.26a' +VERSION = '2.27a' ##VERSION## if sys.version_info.major == 2: @@ -244,6 +248,7 @@ NoVersion = False Dirpath = [] ExternalEncoding = sys.getdefaultencoding() Namespacedef = '' +NoNameSpaceDefs = False CleanupNameList = [(re.compile('[-:.]'), '_')] NamespacesDict = {} @@ -2846,6 +2851,10 @@ def generateExportFn(wrt, prefix, element, namespace, nameSpacesDef): wrt(" def export(self, outfile, level, namespace_='%s', " "name_='%s', namespacedef_='%s', pretty_print=True):\n" % (namespace, name, nameSpacesDef)) + wrt(" imported_ns_def_ = GenerateDSNamespaceDefs_.get" + "('%s')\n" % (name, )) + wrt(" if imported_ns_def_ is not None:\n") + wrt(" namespacedef_ = imported_ns_def_\n") wrt(' if pretty_print:\n') wrt(" eol_ = '\\n'\n") wrt(' else:\n') @@ -5030,7 +5039,34 @@ def parsexml_(infile, parser=None, **kwargs): return doc # -# User methods +# Namespace prefix definition table (and other attributes, too) +# +# The module generatedsnamespaces, if it is importable, must contain +# a dictionary named GeneratedsNamespaceDefs. This Python dictionary +# should map element type names (strings) to XML schema namespace prefix +# definitions. The export method for any class for which there is +# a namespace prefix definition, will export that definition in the +# XML representation of that element. See the export method of +# any generated element type class for a example of the use of this +# table. +# A sample table is: +# +# # File: generatedsnamespaces.py +# +# GenerateDSNamespaceDefs = {{ +# "ElementtypeA": "http://www.xxx.com/namespaceA", +# "ElementtypeB": "http://www.xxx.com/namespaceB", +# }} +# + +try: + from generatedsnamespaces import GenerateDSNamespaceDefs \ +as GenerateDSNamespaceDefs_ +except ImportError: + GenerateDSNamespaceDefs_ = {{}} + +# +# The root super-class for element type classes # # Calls to the methods in these classes are generated by generateDS.py. # You can replace these methods by re-implementing the following class @@ -6478,7 +6514,10 @@ def getUsedNamespacesDefs(element): def generateFromTree(wrt, prefix, elements, processed): for element in elements: - nameSpacesDef = getUsedNamespacesDefs(element) + if NoNameSpaceDefs: + nameSpacesDef = "" + else: + nameSpacesDef = getUsedNamespacesDefs(element) name = element.getCleanName() if 1: # if name not in processed: processed.append(name) @@ -6573,7 +6612,8 @@ def generate(outfileName, subclassFilename, behaviorFilename, if not isNewState(): sys.stderr.write('\n*** maxLoops exceeded. Something is ' 'wrong with --one-file-per-xsd.\n\n') - sys.stderr.write('*** Failed to process the following element ' + sys.stderr.write( + '*** Failed to process the following element ' 'definitions:\n %s\n' % (PostponedExtensions)) break element = PostponedExtensions.pop() @@ -6960,7 +7000,7 @@ def main(): global Force, GenerateProperties, SubclassSuffix, RootElement, \ ValidatorBodiesBasePath, UseGetterSetter, \ UserMethodsPath, XsdNameSpace, \ - Namespacedef, NoDates, NoVersion, \ + Namespacedef, NoNameSpaceDefs, NoDates, NoVersion, \ TEMPLATE_MAIN, TEMPLATE_SUBCLASS_FOOTER, Dirpath, \ ExternalEncoding, MemberSpecs, NoQuestions, \ ExportWrite, ExportEtree, ExportLiteral, \ @@ -6978,7 +7018,7 @@ def main(): 'root-element=', 'super=', 'validator-bodies=', 'use-getter-setter=', 'user-methods=', 'no-process-includes', 'silence', - 'namespacedef=', 'external-encoding=', + 'namespacedef=', 'no-namespace-defs', 'external-encoding=', 'member-specs=', 'no-dates', 'no-versions', 'no-questions', 'session=', 'fix-type-names=', 'version', 'export=', @@ -6998,6 +7038,7 @@ def main(): superModule = '???' processIncludes = 1 namespacedef = '' + NoNameSpaceDefs = False ExternalEncoding = sys.getdefaultencoding() NoDates = False NoVersion = False @@ -7139,6 +7180,8 @@ def main(): outputText = False elif option[0] == "--namespacedef": namespacedef = option[1] + elif option[0] == "--no-namespace-defs": + NoNameSpaceDefs = True elif option[0] == '--external-encoding': ExternalEncoding = option[1] elif option[0] in ('-q', '--no-questions'): diff --git a/generateDS.txt b/generateDS.txt index d3a572ab3f2a6c7c224846620e9eb3382d47c0c0..fba874220d7e2d5bb5320b4bcfc8465e65f156d6 100644 --- a/generateDS.txt +++ b/generateDS.txt @@ -12,7 +12,7 @@ generateDS -- Generate Data Structures from XML Schema .. version -:revision: 2.26a +:revision: 2.27a .. version @@ -302,6 +302,10 @@ Here is the usage message displayed by ``generateDS.py``:: the export() method by the generated parse() and parseString() functions. Default=''. + --no-namespace-defs Do not pass namespace definitions as the value + for the namespacedef_ parameter of the export + method, even if it can be extraced from the + schema. --external-encoding=<encoding> Encode output written by the generated export methods using this encoding. Default, if omitted, @@ -564,6 +568,15 @@ namespacedef="<http://...>" element. (Actually, you can insert any attribute.) The default is an empty string. +no-namespace-defs + Do not pass namespace definitions as the value for the + ``namespacedef_`` parameter of the export method, even if it can + be extraced from the schema. The default is off. You might + want to consider using this in combination with the ability to + attach namespace prefix definitions to specific element types + during export, as described here: `Adding custom exported + attributes and namespace prefix definitions`_. + external-encoding=<encoding> If an XML instance document contains character data or attribute values that are not in the ASCII character set, then @@ -605,7 +618,7 @@ export and use any of lxml's other capabilities. For example: ``--export="write etree"`` and ``--export="write"``. The - default is: ``--export="write literal"``. + default is: ``--export="write"``. preserve-cdata-tags Preserve CDATA tags. Normally, CDATA tags ("<![CDATA[ ... ]]>") @@ -1160,8 +1173,8 @@ Here is a bit of explanation of what that generated code will do. generated validation code calls ``gds_validate_xxx``, where "xxx" is a base, simple type. In some cases, you will be able to add additional code to that method to perform custom checking. See - section `Overridable methods`_ for information on how to use and - override that class. + section `Overridable methods -- generatedssuper.py`_ for + information on how to use and override that class. - When validation finds data that fails to validate, it generates a warning (using the ``warnings`` module from the Python standard @@ -1879,8 +1892,8 @@ in the ``GeneratedsSuper`` class. This method has a default implementation in the generated code. If your XML schema uses ``xs:any``, you may need to add some code to that default implementation of ``gds_build_any``. See section `Overridable -methods`_ for guidance on how to provide an implementation of that -method. +methods -- generatedssuper.py`_ for guidance on how to provide an +implementation of that method. For more help with this, look at the code generated from an XML schema that uses ``xs:any``. In particular, look at the code @@ -2587,8 +2600,8 @@ Suggestion -- How to begin: .. _`gends_user_methods.py`: https://bitbucket.org/dkuhlman/generateds/src -Overridable methods ----------------------------- +Overridable methods -- generatedssuper.py +------------------------------------------- ``generateDS.py`` generates calls to several methods that each have a default implementation in a superclass. The default superclass @@ -2723,9 +2736,64 @@ that complexType definition. This dictionary is named with the "-o" option. +Adding custom exported attributes and namespace prefix definitions +-------------------------------------------------------------------- + +You can add additional attributes to exported XML content by (1) +providing a module named ``generatedsnamespaces.py``; (2) placing +that module somewhere so that it can be imported when you "run" your +generated module; and (3) including in ``generatedsnamespaces.py`` a +global variable named ``GenerateDSNamespaceDefs`` whose value is a +Python dictionary. The keys in this dictionary should be element +type names in the generated module. And the values should be text +strings that are attributes to be added to exported elements of that +type. + +Here is an example:: + + # file: generatedsnamespaces.py + + GenerateDSNamespaceDefs = { + "A1ElementType": 'xmlns:abc="http://www.abc.com/namespace_a1"', + "A2ElementType": 'xmlns:abc="http://www.abc.com/namespace_a2"', + } + +Notes: + +- While the original intension of this facility was to enable the + user to add XML namespace prefix definitions to the XML content in + exported files, you can use it to add other attribute definitions + as well. + +- If you find that ``generateDS.py`` is adding a specific namespace + prefix definition to many exported XML elements and you want to + suppress this behavior, take a look at the ``--no-namespace-defs`` + command line option. In particular, this command line option may + be useful when used together with the capability described in this + section (``generatedsnamespaces.py``). + + "One Per" -- generating separate files from imported/included schemas ======================================================================= +The ``generateDS.py`` project provides support for two approaches to +this task: + +- The first (`Approach 1 -- Command line option + --one-file-per-xsd`_, below) is likely to be easier to use, but if + it does not work for you as is, it is very difficult to customize. + +- The second method (`Approach 2 -- Extraction and generation + utilities`_, below) may require a little more work and + understanding, but offers more options and customization, and, + since the scripts that implement it are short and rather simple, + may be easier to customize or even re-write for your specific + needs. + + +Approach 1 -- Command line option --one-file-per-xsd +---------------------------------------------------------- + The ``--one-file-per-xsd`` command line option enables you to generate a separate Python module for each XML schema that is imported or included (using ``<xs:import>`` or ``<xs:include>``) by @@ -2778,6 +2846,52 @@ Here are a few hints, guidelines, and suggestions: directory into a Python package. +Approach 2 -- Extraction and generation utilities +--------------------------------------------------- + +The ``generateds/utils`` subdirectory contains two utility scripts +that may help with this task. The procedure is as follows: + +1. First, use ``utils/collect_schema_locations.py`` to collect a set + of directives, one for each (included) schema and each module to + be generated. This utility writes out a JSON file that contains + the directives to be used in the next step. + +2. Next, use ``utils/batch_generate.py`` to generate one module (or + perhaps two modules, see below) for each directive in that JSON + file. + +Each of these modules gives a reasonable amount of usage information +in response to the ``--help`` command line option. + +A few hints and suggestions: + +- After generating the JSON directives file you can modify it with + your text editor. For example, (1) you can add the name of + sub-class modules to be generated by ``generateDS.py``; (2) you + can specify command line options to be used by ``generateDS.py`` + when generating specific modules; and (3) you can add new + directives to generate additional modules. + +- If you find yourself typing the same command line options to + ``utils/batch_generate.py`` over and over, there is a facility to + put command line options that have long names (i.e., not one + character names) into a configuration file. The usage information + produced by ``utils/batch_generate.py --help`` shows an example. + Then use ``utils/batch_generate.py --config=myoptins.config ...`` + to feed this configuration file to ``utils/batch_generate.py``. + The options in this configuration file can be overridden by those + entered on the command line. + +- The JSON directives file can contain comments, even though this is + not part of the JSON standard. A comment is any line that begins + with "//" where the "//" is proceeded only by white space + characters. ``utils/batch_generate.py`` strips these lines out + before parsing the JSON file. However, if you plan to process + this JSON file with other processes, you will likely either not + want to add comments or plan to pre-process them in some way. + + How to modify the generated code ================================ diff --git a/generateds_gui_notes.html b/generateds_gui_notes.html index a34f76b1c8a5e1d0240aedf76fb1a1052bb7a1bf..275359d7a20daed681614335b4fab4b1bc9564d6 100644 --- a/generateds_gui_notes.html +++ b/generateds_gui_notes.html @@ -220,7 +220,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">revision:</th><td class="field-body">2.26a</td> +<tr class="field"><th class="field-name">revision:</th><td class="field-body">2.27a</td> </tr> </tbody> </table> @@ -229,7 +229,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">May 09, 2017</td> +<tr class="field"><th class="field-name">date:</th><td class="field-body">June 01, 2017</td> </tr> </tbody> </table> @@ -401,7 +401,7 @@ $ mv generateds_gui.mo locale/ru/LC_MESSAGES/ <div class="footer"> <hr class="footer" /> <a class="reference external" href="generateds_gui_notes.txt">View document source</a>. -Generated on: 2017-05-09 21:57 UTC. +Generated on: 2017-06-01 16:00 UTC. Generated by <a class="reference external" href="http://docutils.sourceforge.net/">Docutils</a> from <a class="reference external" href="http://docutils.sourceforge.net/rst.html">reStructuredText</a> source. </div> diff --git a/generateds_gui_notes.txt b/generateds_gui_notes.txt index 49d17c20439a2530d774cea7b0ce3158dbe62b10..ac0da3a85968c8489d4cea7a31cf249379a5ca5a 100644 --- a/generateds_gui_notes.txt +++ b/generateds_gui_notes.txt @@ -12,7 +12,7 @@ GenerateDS GUI Notes .. version -:revision: 2.26a +:revision: 2.27a .. version diff --git a/gui/generateds_gui.py b/gui/generateds_gui.py index 5a7e6a4e1700fb4daa417713294c23e47a4fe102..a7e35417f5f4f9af60150f706dd9c13029d79e00 100755 --- a/gui/generateds_gui.py +++ b/gui/generateds_gui.py @@ -41,7 +41,7 @@ from libgenerateDS.gui import generateds_gui_session # Do not modify the following VERSION comments. # Used by updateversion.py. ##VERSION## -VERSION = '2.26a' +VERSION = '2.27a' ##VERSION## diff --git a/librarytemplate_howto.html b/librarytemplate_howto.html index 5d3738abc667233576c78d8b99a04883228aafc4..8e4978e9e5396daf6a72078dae0b51e61d55102c 100644 --- a/librarytemplate_howto.html +++ b/librarytemplate_howto.html @@ -217,7 +217,7 @@ dkuhlman (at) davekuhlman (dot) org <col class="field-name" /> <col class="field-body" /> <tbody valign="top"> -<tr class="field"><th class="field-name">revision:</th><td class="field-body">2.26a</td> +<tr class="field"><th class="field-name">revision:</th><td class="field-body">2.27a</td> </tr> </tbody> </table> @@ -226,7 +226,7 @@ dkuhlman (at) davekuhlman (dot) org <col class="field-name" /> <col class="field-body" /> <tbody valign="top"> -<tr class="field"><th class="field-name">date:</th><td class="field-body">May 09, 2017</td> +<tr class="field"><th class="field-name">date:</th><td class="field-body">June 01, 2017</td> </tr> </tbody> </table> @@ -380,7 +380,7 @@ this command for your needs. For example, you may need to use <div class="footer"> <hr class="footer" /> <a class="reference external" href="librarytemplate_howto.txt">View document source</a>. -Generated on: 2017-05-09 21:57 UTC. +Generated on: 2017-06-01 16:00 UTC. Generated by <a class="reference external" href="http://docutils.sourceforge.net/">Docutils</a> from <a class="reference external" href="http://docutils.sourceforge.net/rst.html">reStructuredText</a> source. </div> diff --git a/librarytemplate_howto.txt b/librarytemplate_howto.txt index 28383c0bc796994115503f2453c90c1ea77f135f..808eeb8b0efbb1b202a35cfb545cb2c1526e7802 100644 --- a/librarytemplate_howto.txt +++ b/librarytemplate_howto.txt @@ -8,7 +8,7 @@ How to package a generateDS.py generated library .. version -:revision: 2.26a +:revision: 2.27a .. version diff --git a/process_includes.py b/process_includes.py index e030a21d45a8dff9bb41e29d3e8869c17d381c5d..43aa474d7a7cd5b1af299d995dca29af1b5a7cb4 100755 --- a/process_includes.py +++ b/process_includes.py @@ -40,7 +40,7 @@ except ImportError: # Do not modify the following VERSION comments. # Used by updateversion.py. ##VERSION## -VERSION = '2.26a' +VERSION = '2.27a' ##VERSION## CatalogDict = {} @@ -89,16 +89,19 @@ def process_include_files( return doc -def get_all_root_file_paths(infile, inpath='', catalogpath=None): +def get_all_root_file_paths( + infile, + inpath='', + catalogpath=None, + shallow=False): load_catalog(catalogpath) - doc1 = etree.parse(infile) root1 = doc1.getroot() rootPaths = [] params = Params() params.parent_url = infile params.base_url = os.path.split(inpath)[0] - get_root_file_paths(root1, params, rootPaths) + get_root_file_paths(root1, params, rootPaths, shallow) rootPaths.append(inpath) return rootPaths @@ -266,26 +269,24 @@ def collect_inserts_aux(child, params, inserts, options): return roots -def get_root_file_paths(node, params, rootPaths): - +def get_root_file_paths(node, params, rootPaths, shallow): namespace = node.nsmap[node.prefix] child_iter1 = node.iterfind('{%s}include' % (namespace, )) child_iter2 = node.iterfind('{%s}import' % (namespace, )) for child in itertools.chain(child_iter1, child_iter2): - get_root_file_paths_aux(child, params, rootPaths) + get_root_file_paths_aux(child, params, rootPaths, shallow) -def get_root_file_paths_aux(child, params, rootPaths): +def get_root_file_paths_aux(child, params, rootPaths, shallow): save_base_url = params.base_url path, _ = get_ref_info(child, params) string_content = resolve_ref(child, params, None) if string_content is not None: - root = etree.fromstring(string_content, base_url=params.base_url) - get_root_file_paths(root, params, rootPaths) - + if not shallow: + root = etree.fromstring(string_content, base_url=params.base_url) + get_root_file_paths(root, params, rootPaths, shallow) if path is not None and path not in rootPaths: rootPaths.append(path) - params.base_url = save_base_url diff --git a/setup.py b/setup.py index 6be7d960dd747df93de078f71bfad8a6d2141a94..0e959618a68d50ef3d9e63323435220894fc5626 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.26a", + version="2.27a", ##VERSION## author="Dave Kuhlman", author_email="dkuhlman@davekuhlman.org", diff --git a/tests/OnePer/oneperType00_2One.py b/tests/OnePer/oneperType00_2One.py index 96ad3987ec9b17b35e1d92e9a3901fa64aa99be3..143ef3dd9fa73ef472c6f5f79b9475166768005c 100644 --- a/tests/OnePer/oneperType00_2One.py +++ b/tests/OnePer/oneperType00_2One.py @@ -56,7 +56,33 @@ def parsexml_(infile, parser=None, **kwargs): return doc # -# User methods +# Namespace prefix definition table (and other attributes, too) +# +# The module generatedsnamespaces, if it is importable, must contain +# a dictionary named GeneratedsNamespaceDefs. This Python dictionary +# should map element type names (strings) to XML schema namespace prefix +# definitions. The export method for any class for which there is +# a namespace prefix definition, will export that definition in the +# XML representation of that element. See the export method of +# any generated element type class for a example of the use of this +# table. +# A sample table is: +# +# # File: generatedsnamespaces.py +# +# GenerateDSNamespaceDefs = { +# "ElementtypeA": "http://www.xxx.com/namespaceA", +# "ElementtypeB": "http://www.xxx.com/namespaceB", +# } +# + +try: + from generatedsnamespaces import GenerateDSNamespaceDefs as GenerateDSNamespaceDefs_ +except ImportError: + GenerateDSNamespaceDefs_ = {} + +# +# The root super-class for element type classes # # Calls to the methods in these classes are generated by generateDS.py. # You can replace these methods by re-implementing the following class @@ -699,6 +725,9 @@ class oneperType00_1(GeneratedsSuper): else: return False def export(self, outfile, level, namespace_='', name_='oneperType00_1', namespacedef_='', pretty_print=True): + imported_ns_def_ = GenerateDSNamespaceDefs_.get('oneperType00_1') + if imported_ns_def_ is not None: + namespacedef_ = imported_ns_def_ if pretty_print: eol_ = '\n' else: diff --git a/tests/OnePer/oneperType01_2One.py b/tests/OnePer/oneperType01_2One.py index 6b9aec3b013a81a01ffeb2bba977ddf2f5629371..40f336af98745b601b7e98c2555c8ce455429372 100644 --- a/tests/OnePer/oneperType01_2One.py +++ b/tests/OnePer/oneperType01_2One.py @@ -56,7 +56,33 @@ def parsexml_(infile, parser=None, **kwargs): return doc # -# User methods +# Namespace prefix definition table (and other attributes, too) +# +# The module generatedsnamespaces, if it is importable, must contain +# a dictionary named GeneratedsNamespaceDefs. This Python dictionary +# should map element type names (strings) to XML schema namespace prefix +# definitions. The export method for any class for which there is +# a namespace prefix definition, will export that definition in the +# XML representation of that element. See the export method of +# any generated element type class for a example of the use of this +# table. +# A sample table is: +# +# # File: generatedsnamespaces.py +# +# GenerateDSNamespaceDefs = { +# "ElementtypeA": "http://www.xxx.com/namespaceA", +# "ElementtypeB": "http://www.xxx.com/namespaceB", +# } +# + +try: + from generatedsnamespaces import GenerateDSNamespaceDefs as GenerateDSNamespaceDefs_ +except ImportError: + GenerateDSNamespaceDefs_ = {} + +# +# The root super-class for element type classes # # Calls to the methods in these classes are generated by generateDS.py. # You can replace these methods by re-implementing the following class @@ -699,6 +725,9 @@ class oneperType01_1(GeneratedsSuper): else: return False def export(self, outfile, level, namespace_='', name_='oneperType01_1', namespacedef_='', pretty_print=True): + imported_ns_def_ = GenerateDSNamespaceDefs_.get('oneperType01_1') + if imported_ns_def_ is not None: + namespacedef_ = imported_ns_def_ if pretty_print: eol_ = '\n' else: @@ -780,6 +809,9 @@ class oneperType01_2(GeneratedsSuper): else: return False def export(self, outfile, level, namespace_='', name_='oneperType01_2', namespacedef_='', pretty_print=True): + imported_ns_def_ = GenerateDSNamespaceDefs_.get('oneperType01_2') + if imported_ns_def_ is not None: + namespacedef_ = imported_ns_def_ if pretty_print: eol_ = '\n' else: diff --git a/tests/OnePer/oneperType02_2One.py b/tests/OnePer/oneperType02_2One.py index 55cbdf0fda175b43586389201b5294f18756caa3..55b604597bf938b6ec21ab9f21a445e133fb30a5 100644 --- a/tests/OnePer/oneperType02_2One.py +++ b/tests/OnePer/oneperType02_2One.py @@ -56,7 +56,33 @@ def parsexml_(infile, parser=None, **kwargs): return doc # -# User methods +# Namespace prefix definition table (and other attributes, too) +# +# The module generatedsnamespaces, if it is importable, must contain +# a dictionary named GeneratedsNamespaceDefs. This Python dictionary +# should map element type names (strings) to XML schema namespace prefix +# definitions. The export method for any class for which there is +# a namespace prefix definition, will export that definition in the +# XML representation of that element. See the export method of +# any generated element type class for a example of the use of this +# table. +# A sample table is: +# +# # File: generatedsnamespaces.py +# +# GenerateDSNamespaceDefs = { +# "ElementtypeA": "http://www.xxx.com/namespaceA", +# "ElementtypeB": "http://www.xxx.com/namespaceB", +# } +# + +try: + from generatedsnamespaces import GenerateDSNamespaceDefs as GenerateDSNamespaceDefs_ +except ImportError: + GenerateDSNamespaceDefs_ = {} + +# +# The root super-class for element type classes # # Calls to the methods in these classes are generated by generateDS.py. # You can replace these methods by re-implementing the following class @@ -699,6 +725,9 @@ class oneperType02_1(GeneratedsSuper): else: return False def export(self, outfile, level, namespace_='', name_='oneperType02_1', namespacedef_='', pretty_print=True): + imported_ns_def_ = GenerateDSNamespaceDefs_.get('oneperType02_1') + if imported_ns_def_ is not None: + namespacedef_ = imported_ns_def_ if pretty_print: eol_ = '\n' else: @@ -780,6 +809,9 @@ class oneperType02_2(GeneratedsSuper): else: return False def export(self, outfile, level, namespace_='', name_='oneperType02_2', namespacedef_='', pretty_print=True): + imported_ns_def_ = GenerateDSNamespaceDefs_.get('oneperType02_2') + if imported_ns_def_ is not None: + namespacedef_ = imported_ns_def_ if pretty_print: eol_ = '\n' else: diff --git a/tests/OnePer/oneperType03_2One.py b/tests/OnePer/oneperType03_2One.py index f34f72684f352e525b8a8a551d8c66ad94e80a8a..5095a6680175f20d2b16ed9222eb8063822142df 100644 --- a/tests/OnePer/oneperType03_2One.py +++ b/tests/OnePer/oneperType03_2One.py @@ -56,7 +56,33 @@ def parsexml_(infile, parser=None, **kwargs): return doc # -# User methods +# Namespace prefix definition table (and other attributes, too) +# +# The module generatedsnamespaces, if it is importable, must contain +# a dictionary named GeneratedsNamespaceDefs. This Python dictionary +# should map element type names (strings) to XML schema namespace prefix +# definitions. The export method for any class for which there is +# a namespace prefix definition, will export that definition in the +# XML representation of that element. See the export method of +# any generated element type class for a example of the use of this +# table. +# A sample table is: +# +# # File: generatedsnamespaces.py +# +# GenerateDSNamespaceDefs = { +# "ElementtypeA": "http://www.xxx.com/namespaceA", +# "ElementtypeB": "http://www.xxx.com/namespaceB", +# } +# + +try: + from generatedsnamespaces import GenerateDSNamespaceDefs as GenerateDSNamespaceDefs_ +except ImportError: + GenerateDSNamespaceDefs_ = {} + +# +# The root super-class for element type classes # # Calls to the methods in these classes are generated by generateDS.py. # You can replace these methods by re-implementing the following class @@ -699,6 +725,9 @@ class oneperType03_1(GeneratedsSuper): else: return False def export(self, outfile, level, namespace_='', name_='oneperType03_1', namespacedef_='', pretty_print=True): + imported_ns_def_ = GenerateDSNamespaceDefs_.get('oneperType03_1') + if imported_ns_def_ is not None: + namespacedef_ = imported_ns_def_ if pretty_print: eol_ = '\n' else: @@ -780,6 +809,9 @@ class oneperType03_2(GeneratedsSuper): else: return False def export(self, outfile, level, namespace_='', name_='oneperType03_2', namespacedef_='', pretty_print=True): + imported_ns_def_ = GenerateDSNamespaceDefs_.get('oneperType03_2') + if imported_ns_def_ is not None: + namespacedef_ = imported_ns_def_ if pretty_print: eol_ = '\n' else: diff --git a/tests/abstract_type1_sup.py b/tests/abstract_type1_sup.py index 7d63ed14bc9e10df05751191289f6f5a490d5482..643efb616c46e9161acc49fe42b59656aa57edb6 100644 --- a/tests/abstract_type1_sup.py +++ b/tests/abstract_type1_sup.py @@ -55,7 +55,33 @@ def parsexml_(infile, parser=None, **kwargs): return doc # -# User methods +# Namespace prefix definition table (and other attributes, too) +# +# The module generatedsnamespaces, if it is importable, must contain +# a dictionary named GeneratedsNamespaceDefs. This Python dictionary +# should map element type names (strings) to XML schema namespace prefix +# definitions. The export method for any class for which there is +# a namespace prefix definition, will export that definition in the +# XML representation of that element. See the export method of +# any generated element type class for a example of the use of this +# table. +# A sample table is: +# +# # File: generatedsnamespaces.py +# +# GenerateDSNamespaceDefs = { +# "ElementtypeA": "http://www.xxx.com/namespaceA", +# "ElementtypeB": "http://www.xxx.com/namespaceB", +# } +# + +try: + from generatedsnamespaces import GenerateDSNamespaceDefs as GenerateDSNamespaceDefs_ +except ImportError: + GenerateDSNamespaceDefs_ = {} + +# +# The root super-class for element type classes # # Calls to the methods in these classes are generated by generateDS.py. # You can replace these methods by re-implementing the following class @@ -699,6 +725,9 @@ class carrierType(GeneratedsSuper): else: return False def export(self, outfile, level, namespace_='target:', name_='carrierType', namespacedef_='xmlns:target="http://cars.example.com/schema"', pretty_print=True): + imported_ns_def_ = GenerateDSNamespaceDefs_.get('carrierType') + if imported_ns_def_ is not None: + namespacedef_ = imported_ns_def_ if pretty_print: eol_ = '\n' else: @@ -786,6 +815,9 @@ class Vehicle(GeneratedsSuper): else: return False def export(self, outfile, level, namespace_='target:', name_='Vehicle', namespacedef_='xmlns:target="http://cars.example.com/schema"', pretty_print=True): + imported_ns_def_ = GenerateDSNamespaceDefs_.get('Vehicle') + if imported_ns_def_ is not None: + namespacedef_ = imported_ns_def_ if pretty_print: eol_ = '\n' else: @@ -854,6 +886,9 @@ class Car(Vehicle): else: return False def export(self, outfile, level, namespace_='target:', name_='Car', namespacedef_='xmlns:target="http://cars.example.com/schema"', pretty_print=True): + imported_ns_def_ = GenerateDSNamespaceDefs_.get('Car') + if imported_ns_def_ is not None: + namespacedef_ = imported_ns_def_ if pretty_print: eol_ = '\n' else: @@ -917,6 +952,9 @@ class Plane(Vehicle): else: return False def export(self, outfile, level, namespace_='target:', name_='Plane', namespacedef_='xmlns:target="http://cars.example.com/schema"', pretty_print=True): + imported_ns_def_ = GenerateDSNamespaceDefs_.get('Plane') + if imported_ns_def_ is not None: + namespacedef_ = imported_ns_def_ if pretty_print: eol_ = '\n' else: diff --git a/tests/annotations1_sup.py b/tests/annotations1_sup.py index f7b7f4cb8d39d00351d49fd96ab4cf40c476baf9..d716c9606d6f0f368797a5ebc5876642618fec06 100644 --- a/tests/annotations1_sup.py +++ b/tests/annotations1_sup.py @@ -55,7 +55,33 @@ def parsexml_(infile, parser=None, **kwargs): return doc # -# User methods +# Namespace prefix definition table (and other attributes, too) +# +# The module generatedsnamespaces, if it is importable, must contain +# a dictionary named GeneratedsNamespaceDefs. This Python dictionary +# should map element type names (strings) to XML schema namespace prefix +# definitions. The export method for any class for which there is +# a namespace prefix definition, will export that definition in the +# XML representation of that element. See the export method of +# any generated element type class for a example of the use of this +# table. +# A sample table is: +# +# # File: generatedsnamespaces.py +# +# GenerateDSNamespaceDefs = { +# "ElementtypeA": "http://www.xxx.com/namespaceA", +# "ElementtypeB": "http://www.xxx.com/namespaceB", +# } +# + +try: + from generatedsnamespaces import GenerateDSNamespaceDefs as GenerateDSNamespaceDefs_ +except ImportError: + GenerateDSNamespaceDefs_ = {} + +# +# The root super-class for element type classes # # Calls to the methods in these classes are generated by generateDS.py. # You can replace these methods by re-implementing the following class @@ -701,6 +727,9 @@ class document1Type(GeneratedsSuper): else: return False def export(self, outfile, level, namespace_='', name_='document1Type', namespacedef_='', pretty_print=True): + imported_ns_def_ = GenerateDSNamespaceDefs_.get('document1Type') + if imported_ns_def_ is not None: + namespacedef_ = imported_ns_def_ if pretty_print: eol_ = '\n' else: @@ -795,6 +824,9 @@ class document2Type(GeneratedsSuper): else: return False def export(self, outfile, level, namespace_='', name_='document2Type', namespacedef_='', pretty_print=True): + imported_ns_def_ = GenerateDSNamespaceDefs_.get('document2Type') + if imported_ns_def_ is not None: + namespacedef_ = imported_ns_def_ if pretty_print: eol_ = '\n' else: @@ -893,6 +925,9 @@ class document3Type(GeneratedsSuper): else: return False def export(self, outfile, level, namespace_='', name_='document3Type', namespacedef_='', pretty_print=True): + imported_ns_def_ = GenerateDSNamespaceDefs_.get('document3Type') + if imported_ns_def_ is not None: + namespacedef_ = imported_ns_def_ if pretty_print: eol_ = '\n' else: diff --git a/tests/anonymous_type1_sup.py b/tests/anonymous_type1_sup.py index 54f4775c3bba0ae1c46ffa83be4af05db6904509..ac77e9c45bd3e9eb5b9b320f05f689506e9d6791 100644 --- a/tests/anonymous_type1_sup.py +++ b/tests/anonymous_type1_sup.py @@ -55,7 +55,33 @@ def parsexml_(infile, parser=None, **kwargs): return doc # -# User methods +# Namespace prefix definition table (and other attributes, too) +# +# The module generatedsnamespaces, if it is importable, must contain +# a dictionary named GeneratedsNamespaceDefs. This Python dictionary +# should map element type names (strings) to XML schema namespace prefix +# definitions. The export method for any class for which there is +# a namespace prefix definition, will export that definition in the +# XML representation of that element. See the export method of +# any generated element type class for a example of the use of this +# table. +# A sample table is: +# +# # File: generatedsnamespaces.py +# +# GenerateDSNamespaceDefs = { +# "ElementtypeA": "http://www.xxx.com/namespaceA", +# "ElementtypeB": "http://www.xxx.com/namespaceB", +# } +# + +try: + from generatedsnamespaces import GenerateDSNamespaceDefs as GenerateDSNamespaceDefs_ +except ImportError: + GenerateDSNamespaceDefs_ = {} + +# +# The root super-class for element type classes # # Calls to the methods in these classes are generated by generateDS.py. # You can replace these methods by re-implementing the following class @@ -703,6 +729,9 @@ class FooList(GeneratedsSuper): else: return False def export(self, outfile, level, namespace_='', name_='FooList', namespacedef_='', pretty_print=True): + imported_ns_def_ = GenerateDSNamespaceDefs_.get('FooList') + if imported_ns_def_ is not None: + namespacedef_ = imported_ns_def_ if pretty_print: eol_ = '\n' else: @@ -799,6 +828,9 @@ class FooType1(GeneratedsSuper): else: return False def export(self, outfile, level, namespace_='', name_='FooType1', namespacedef_='', pretty_print=True): + imported_ns_def_ = GenerateDSNamespaceDefs_.get('FooType1') + if imported_ns_def_ is not None: + namespacedef_ = imported_ns_def_ if pretty_print: eol_ = '\n' else: @@ -883,6 +915,9 @@ class BarType2(GeneratedsSuper): else: return False def export(self, outfile, level, namespace_='', name_='BarType2', namespacedef_='', pretty_print=True): + imported_ns_def_ = GenerateDSNamespaceDefs_.get('BarType2') + if imported_ns_def_ is not None: + namespacedef_ = imported_ns_def_ if pretty_print: eol_ = '\n' else: @@ -967,6 +1002,9 @@ class BazType3(GeneratedsSuper): else: return False def export(self, outfile, level, namespace_='', name_='BazType3', namespacedef_='', pretty_print=True): + imported_ns_def_ = GenerateDSNamespaceDefs_.get('BazType3') + if imported_ns_def_ is not None: + namespacedef_ = imported_ns_def_ if pretty_print: eol_ = '\n' else: diff --git a/tests/anysimpletype1_sup.py b/tests/anysimpletype1_sup.py index 37b25dcd83423207dd9c3c99b0f2cad559262ea7..7122f86c2692c56e0a7f29887b945befc187f2f1 100644 --- a/tests/anysimpletype1_sup.py +++ b/tests/anysimpletype1_sup.py @@ -55,7 +55,33 @@ def parsexml_(infile, parser=None, **kwargs): return doc # -# User methods +# Namespace prefix definition table (and other attributes, too) +# +# The module generatedsnamespaces, if it is importable, must contain +# a dictionary named GeneratedsNamespaceDefs. This Python dictionary +# should map element type names (strings) to XML schema namespace prefix +# definitions. The export method for any class for which there is +# a namespace prefix definition, will export that definition in the +# XML representation of that element. See the export method of +# any generated element type class for a example of the use of this +# table. +# A sample table is: +# +# # File: generatedsnamespaces.py +# +# GenerateDSNamespaceDefs = { +# "ElementtypeA": "http://www.xxx.com/namespaceA", +# "ElementtypeB": "http://www.xxx.com/namespaceB", +# } +# + +try: + from generatedsnamespaces import GenerateDSNamespaceDefs as GenerateDSNamespaceDefs_ +except ImportError: + GenerateDSNamespaceDefs_ = {} + +# +# The root super-class for element type classes # # Calls to the methods in these classes are generated by generateDS.py. # You can replace these methods by re-implementing the following class @@ -697,6 +723,9 @@ class test1element(GeneratedsSuper): else: return False def export(self, outfile, level, namespace_='', name_='test1element', namespacedef_='', pretty_print=True): + imported_ns_def_ = GenerateDSNamespaceDefs_.get('test1element') + if imported_ns_def_ is not None: + namespacedef_ = imported_ns_def_ if pretty_print: eol_ = '\n' else: @@ -779,6 +808,9 @@ class cimAnySimpleType(GeneratedsSuper): else: return False def export(self, outfile, level, namespace_='', name_='cimAnySimpleType', namespacedef_='', pretty_print=True): + imported_ns_def_ = GenerateDSNamespaceDefs_.get('cimAnySimpleType') + if imported_ns_def_ is not None: + namespacedef_ = imported_ns_def_ if pretty_print: eol_ = '\n' else: diff --git a/tests/anywildcard1_sup.py b/tests/anywildcard1_sup.py index fc9d2dde41bfcf9e8007136d472b93635734383e..bc06e7d65384863900e50b0712c7e4c55ccbe5af 100644 --- a/tests/anywildcard1_sup.py +++ b/tests/anywildcard1_sup.py @@ -55,7 +55,33 @@ def parsexml_(infile, parser=None, **kwargs): return doc # -# User methods +# Namespace prefix definition table (and other attributes, too) +# +# The module generatedsnamespaces, if it is importable, must contain +# a dictionary named GeneratedsNamespaceDefs. This Python dictionary +# should map element type names (strings) to XML schema namespace prefix +# definitions. The export method for any class for which there is +# a namespace prefix definition, will export that definition in the +# XML representation of that element. See the export method of +# any generated element type class for a example of the use of this +# table. +# A sample table is: +# +# # File: generatedsnamespaces.py +# +# GenerateDSNamespaceDefs = { +# "ElementtypeA": "http://www.xxx.com/namespaceA", +# "ElementtypeB": "http://www.xxx.com/namespaceB", +# } +# + +try: + from generatedsnamespaces import GenerateDSNamespaceDefs as GenerateDSNamespaceDefs_ +except ImportError: + GenerateDSNamespaceDefs_ = {} + +# +# The root super-class for element type classes # # Calls to the methods in these classes are generated by generateDS.py. # You can replace these methods by re-implementing the following class @@ -703,6 +729,9 @@ class PlantType_single(GeneratedsSuper): else: return False def export(self, outfile, level, namespace_='', name_='PlantType_single', namespacedef_='', pretty_print=True): + imported_ns_def_ = GenerateDSNamespaceDefs_.get('PlantType_single') + if imported_ns_def_ is not None: + namespacedef_ = imported_ns_def_ if pretty_print: eol_ = '\n' else: @@ -805,6 +834,9 @@ class PlantType_multiple(GeneratedsSuper): else: return False def export(self, outfile, level, namespace_='', name_='PlantType_multiple', namespacedef_='', pretty_print=True): + imported_ns_def_ = GenerateDSNamespaceDefs_.get('PlantType_multiple') + if imported_ns_def_ is not None: + namespacedef_ = imported_ns_def_ if pretty_print: eol_ = '\n' else: @@ -898,6 +930,9 @@ class DescriptionType(GeneratedsSuper): else: return False def export(self, outfile, level, namespace_='', name_='DescriptionType', namespacedef_='', pretty_print=True): + imported_ns_def_ = GenerateDSNamespaceDefs_.get('DescriptionType') + if imported_ns_def_ is not None: + namespacedef_ = imported_ns_def_ if pretty_print: eol_ = '\n' else: @@ -985,6 +1020,9 @@ class CatalogType(GeneratedsSuper): else: return False def export(self, outfile, level, namespace_='', name_='CatalogType', namespacedef_='', pretty_print=True): + imported_ns_def_ = GenerateDSNamespaceDefs_.get('CatalogType') + if imported_ns_def_ is not None: + namespacedef_ = imported_ns_def_ if pretty_print: eol_ = '\n' else: @@ -1070,6 +1108,9 @@ class PlantType_single_nochild(GeneratedsSuper): else: return False def export(self, outfile, level, namespace_='', name_='PlantType_single_nochild', namespacedef_='', pretty_print=True): + imported_ns_def_ = GenerateDSNamespaceDefs_.get('PlantType_single_nochild') + if imported_ns_def_ is not None: + namespacedef_ = imported_ns_def_ if pretty_print: eol_ = '\n' else: @@ -1147,6 +1188,9 @@ class PlantType_multiple_nochild(GeneratedsSuper): else: return False def export(self, outfile, level, namespace_='', name_='PlantType_multiple_nochild', namespacedef_='', pretty_print=True): + imported_ns_def_ = GenerateDSNamespaceDefs_.get('PlantType_multiple_nochild') + if imported_ns_def_ is not None: + namespacedef_ = imported_ns_def_ if pretty_print: eol_ = '\n' else: diff --git a/tests/attr_groups1_sup.py b/tests/attr_groups1_sup.py index 064f970eabda9b9db679727f9d15e342b7cfa170..49e3fdbe22304380490cd5c3ebf3082642c82856 100644 --- a/tests/attr_groups1_sup.py +++ b/tests/attr_groups1_sup.py @@ -55,7 +55,33 @@ def parsexml_(infile, parser=None, **kwargs): return doc # -# User methods +# Namespace prefix definition table (and other attributes, too) +# +# The module generatedsnamespaces, if it is importable, must contain +# a dictionary named GeneratedsNamespaceDefs. This Python dictionary +# should map element type names (strings) to XML schema namespace prefix +# definitions. The export method for any class for which there is +# a namespace prefix definition, will export that definition in the +# XML representation of that element. See the export method of +# any generated element type class for a example of the use of this +# table. +# A sample table is: +# +# # File: generatedsnamespaces.py +# +# GenerateDSNamespaceDefs = { +# "ElementtypeA": "http://www.xxx.com/namespaceA", +# "ElementtypeB": "http://www.xxx.com/namespaceB", +# } +# + +try: + from generatedsnamespaces import GenerateDSNamespaceDefs as GenerateDSNamespaceDefs_ +except ImportError: + GenerateDSNamespaceDefs_ = {} + +# +# The root super-class for element type classes # # Calls to the methods in these classes are generated by generateDS.py. # You can replace these methods by re-implementing the following class @@ -729,6 +755,9 @@ class GetUserReq(GeneratedsSuper): else: return False def export(self, outfile, level, namespace_='', name_='GetUserReq', namespacedef_='', pretty_print=True): + imported_ns_def_ = GenerateDSNamespaceDefs_.get('GetUserReq') + if imported_ns_def_ is not None: + namespacedef_ = imported_ns_def_ if pretty_print: eol_ = '\n' else: diff --git a/tests/catalogtest1_sup.py b/tests/catalogtest1_sup.py index 08226684ea68920263a68aba9c576fda0a64a6e7..94fef3351567340dfe28f66bc9d84614acd50b58 100644 --- a/tests/catalogtest1_sup.py +++ b/tests/catalogtest1_sup.py @@ -56,7 +56,33 @@ def parsexml_(infile, parser=None, **kwargs): return doc # -# User methods +# Namespace prefix definition table (and other attributes, too) +# +# The module generatedsnamespaces, if it is importable, must contain +# a dictionary named GeneratedsNamespaceDefs. This Python dictionary +# should map element type names (strings) to XML schema namespace prefix +# definitions. The export method for any class for which there is +# a namespace prefix definition, will export that definition in the +# XML representation of that element. See the export method of +# any generated element type class for a example of the use of this +# table. +# A sample table is: +# +# # File: generatedsnamespaces.py +# +# GenerateDSNamespaceDefs = { +# "ElementtypeA": "http://www.xxx.com/namespaceA", +# "ElementtypeB": "http://www.xxx.com/namespaceB", +# } +# + +try: + from generatedsnamespaces import GenerateDSNamespaceDefs as GenerateDSNamespaceDefs_ +except ImportError: + GenerateDSNamespaceDefs_ = {} + +# +# The root super-class for element type classes # # Calls to the methods in these classes are generated by generateDS.py. # You can replace these methods by re-implementing the following class diff --git a/tests/cdata1_sup.py b/tests/cdata1_sup.py index 3ddcfae17c801282c47548168177ef6e6f473e6f..81149c2de3f0390c98a886c1c0f7938fa42aa76d 100644 --- a/tests/cdata1_sup.py +++ b/tests/cdata1_sup.py @@ -56,7 +56,33 @@ def parsexml_(infile, parser=None, **kwargs): return doc # -# User methods +# Namespace prefix definition table (and other attributes, too) +# +# The module generatedsnamespaces, if it is importable, must contain +# a dictionary named GeneratedsNamespaceDefs. This Python dictionary +# should map element type names (strings) to XML schema namespace prefix +# definitions. The export method for any class for which there is +# a namespace prefix definition, will export that definition in the +# XML representation of that element. See the export method of +# any generated element type class for a example of the use of this +# table. +# A sample table is: +# +# # File: generatedsnamespaces.py +# +# GenerateDSNamespaceDefs = { +# "ElementtypeA": "http://www.xxx.com/namespaceA", +# "ElementtypeB": "http://www.xxx.com/namespaceB", +# } +# + +try: + from generatedsnamespaces import GenerateDSNamespaceDefs as GenerateDSNamespaceDefs_ +except ImportError: + GenerateDSNamespaceDefs_ = {} + +# +# The root super-class for element type classes # # Calls to the methods in these classes are generated by generateDS.py. # You can replace these methods by re-implementing the following class @@ -700,6 +726,9 @@ class cdataListType(GeneratedsSuper): else: return False def export(self, outfile, level, namespace_='', name_='cdataListType', namespacedef_='', pretty_print=True): + imported_ns_def_ = GenerateDSNamespaceDefs_.get('cdataListType') + if imported_ns_def_ is not None: + namespacedef_ = imported_ns_def_ if pretty_print: eol_ = '\n' else: @@ -774,6 +803,9 @@ class cdataType(GeneratedsSuper): else: return False def export(self, outfile, level, namespace_='', name_='cdataType', namespacedef_='', pretty_print=True): + imported_ns_def_ = GenerateDSNamespaceDefs_.get('cdataType') + if imported_ns_def_ is not None: + namespacedef_ = imported_ns_def_ if pretty_print: eol_ = '\n' else: diff --git a/tests/cleanupname1_sup.py b/tests/cleanupname1_sup.py index ce85f41d7cceaf54d80bda393d31fc814b1dee73..11983e9ed25f4b0a5fd817e4ebefc58ed04e0a11 100644 --- a/tests/cleanupname1_sup.py +++ b/tests/cleanupname1_sup.py @@ -56,7 +56,33 @@ def parsexml_(infile, parser=None, **kwargs): return doc # -# User methods +# Namespace prefix definition table (and other attributes, too) +# +# The module generatedsnamespaces, if it is importable, must contain +# a dictionary named GeneratedsNamespaceDefs. This Python dictionary +# should map element type names (strings) to XML schema namespace prefix +# definitions. The export method for any class for which there is +# a namespace prefix definition, will export that definition in the +# XML representation of that element. See the export method of +# any generated element type class for a example of the use of this +# table. +# A sample table is: +# +# # File: generatedsnamespaces.py +# +# GenerateDSNamespaceDefs = { +# "ElementtypeA": "http://www.xxx.com/namespaceA", +# "ElementtypeB": "http://www.xxx.com/namespaceB", +# } +# + +try: + from generatedsnamespaces import GenerateDSNamespaceDefs as GenerateDSNamespaceDefs_ +except ImportError: + GenerateDSNamespaceDefs_ = {} + +# +# The root super-class for element type classes # # Calls to the methods in these classes are generated by generateDS.py. # You can replace these methods by re-implementing the following class @@ -714,6 +740,9 @@ class dataKind(GeneratedsSuper): else: return False def export(self, outfile, level, namespace_='', name_='dataType', namespacedef_='', pretty_print=True): + imported_ns_def_ = GenerateDSNamespaceDefs_.get('dataType') + if imported_ns_def_ is not None: + namespacedef_ = imported_ns_def_ if pretty_print: eol_ = '\n' else: @@ -816,6 +845,9 @@ class data1Kind(GeneratedsSuper): else: return False def export(self, outfile, level, namespace_='', name_='data1Type', namespacedef_='', pretty_print=True): + imported_ns_def_ = GenerateDSNamespaceDefs_.get('data1Type') + if imported_ns_def_ is not None: + namespacedef_ = imported_ns_def_ if pretty_print: eol_ = '\n' else: @@ -890,6 +922,9 @@ class MlassData2(GeneratedsSuper): else: return False def export(self, outfile, level, namespace_='', name_='TypeData2', namespacedef_='', pretty_print=True): + imported_ns_def_ = GenerateDSNamespaceDefs_.get('TypeData2') + if imported_ns_def_ is not None: + namespacedef_ = imported_ns_def_ if pretty_print: eol_ = '\n' else: @@ -964,6 +999,9 @@ class RealTypeData3(GeneratedsSuper): else: return False def export(self, outfile, level, namespace_='', name_='RealTypeData3', namespacedef_='', pretty_print=True): + imported_ns_def_ = GenerateDSNamespaceDefs_.get('RealTypeData3') + if imported_ns_def_ is not None: + namespacedef_ = imported_ns_def_ if pretty_print: eol_ = '\n' else: @@ -1038,6 +1076,9 @@ class MMMMMMdataKind(GeneratedsSuper): else: return False def export(self, outfile, level, namespace_='', name_='AABBCCdataType', namespacedef_='', pretty_print=True): + imported_ns_def_ = GenerateDSNamespaceDefs_.get('AABBCCdataType') + if imported_ns_def_ is not None: + namespacedef_ = imported_ns_def_ if pretty_print: eol_ = '\n' else: @@ -1112,6 +1153,9 @@ class dataTypeNNNMNNN(GeneratedsSuper): else: return False def export(self, outfile, level, namespace_='', name_='dataTypeXYZAXYZ', namespacedef_='', pretty_print=True): + imported_ns_def_ = GenerateDSNamespaceDefs_.get('dataTypeXYZAXYZ') + if imported_ns_def_ is not None: + namespacedef_ = imported_ns_def_ if pretty_print: eol_ = '\n' else: diff --git a/tests/defaults_cases1_sup.py b/tests/defaults_cases1_sup.py index 6a6b5dcc9bc2818c9104babb2a62e3cbdf10bc87..4482304b4c5e71d3955710aa6f2e33640d5adc2c 100644 --- a/tests/defaults_cases1_sup.py +++ b/tests/defaults_cases1_sup.py @@ -54,7 +54,33 @@ def parsexml_(infile, parser=None, **kwargs): return doc # -# User methods +# Namespace prefix definition table (and other attributes, too) +# +# The module generatedsnamespaces, if it is importable, must contain +# a dictionary named GeneratedsNamespaceDefs. This Python dictionary +# should map element type names (strings) to XML schema namespace prefix +# definitions. The export method for any class for which there is +# a namespace prefix definition, will export that definition in the +# XML representation of that element. See the export method of +# any generated element type class for a example of the use of this +# table. +# A sample table is: +# +# # File: generatedsnamespaces.py +# +# GenerateDSNamespaceDefs = { +# "ElementtypeA": "http://www.xxx.com/namespaceA", +# "ElementtypeB": "http://www.xxx.com/namespaceB", +# } +# + +try: + from generatedsnamespaces import GenerateDSNamespaceDefs as GenerateDSNamespaceDefs_ +except ImportError: + GenerateDSNamespaceDefs_ = {} + +# +# The root super-class for element type classes # # Calls to the methods in these classes are generated by generateDS.py. # You can replace these methods by re-implementing the following class @@ -709,6 +735,9 @@ class DefaultTypes(GeneratedsSuper): else: return False def export(self, outfile, level, namespace_='', name_='DefaultTypes', namespacedef_='', pretty_print=True): + imported_ns_def_ = GenerateDSNamespaceDefs_.get('DefaultTypes') + if imported_ns_def_ is not None: + namespacedef_ = imported_ns_def_ if pretty_print: eol_ = '\n' else: @@ -825,6 +854,9 @@ class DefaultType1(GeneratedsSuper): else: return False def export(self, outfile, level, namespace_='', name_='DefaultType1', namespacedef_='', pretty_print=True): + imported_ns_def_ = GenerateDSNamespaceDefs_.get('DefaultType1') + if imported_ns_def_ is not None: + namespacedef_ = imported_ns_def_ if pretty_print: eol_ = '\n' else: @@ -984,6 +1016,9 @@ class DefaultType2(GeneratedsSuper): else: return False def export(self, outfile, level, namespace_='', name_='DefaultType2', namespacedef_='', pretty_print=True): + imported_ns_def_ = GenerateDSNamespaceDefs_.get('DefaultType2') + if imported_ns_def_ is not None: + namespacedef_ = imported_ns_def_ if pretty_print: eol_ = '\n' else: diff --git a/tests/defaults_coverage1_sup.py b/tests/defaults_coverage1_sup.py index 7808d170a06ea558b76055846b823af8e89ed1c5..534c099bbdd31b3d60bde43356b7534d42db97cb 100644 --- a/tests/defaults_coverage1_sup.py +++ b/tests/defaults_coverage1_sup.py @@ -55,7 +55,33 @@ def parsexml_(infile, parser=None, **kwargs): return doc # -# User methods +# Namespace prefix definition table (and other attributes, too) +# +# The module generatedsnamespaces, if it is importable, must contain +# a dictionary named GeneratedsNamespaceDefs. This Python dictionary +# should map element type names (strings) to XML schema namespace prefix +# definitions. The export method for any class for which there is +# a namespace prefix definition, will export that definition in the +# XML representation of that element. See the export method of +# any generated element type class for a example of the use of this +# table. +# A sample table is: +# +# # File: generatedsnamespaces.py +# +# GenerateDSNamespaceDefs = { +# "ElementtypeA": "http://www.xxx.com/namespaceA", +# "ElementtypeB": "http://www.xxx.com/namespaceB", +# } +# + +try: + from generatedsnamespaces import GenerateDSNamespaceDefs as GenerateDSNamespaceDefs_ +except ImportError: + GenerateDSNamespaceDefs_ = {} + +# +# The root super-class for element type classes # # Calls to the methods in these classes are generated by generateDS.py. # You can replace these methods by re-implementing the following class @@ -698,6 +724,9 @@ class DefaultTypes(GeneratedsSuper): else: return False def export(self, outfile, level, namespace_='', name_='DefaultTypes', namespacedef_='', pretty_print=True): + imported_ns_def_ = GenerateDSNamespaceDefs_.get('DefaultTypes') + if imported_ns_def_ is not None: + namespacedef_ = imported_ns_def_ if pretty_print: eol_ = '\n' else: @@ -883,6 +912,9 @@ class DefaultType1(GeneratedsSuper): else: return False def export(self, outfile, level, namespace_='', name_='DefaultType1', namespacedef_='', pretty_print=True): + imported_ns_def_ = GenerateDSNamespaceDefs_.get('DefaultType1') + if imported_ns_def_ is not None: + namespacedef_ = imported_ns_def_ if pretty_print: eol_ = '\n' else: @@ -1215,6 +1247,9 @@ class DefaultType2(GeneratedsSuper): else: return False def export(self, outfile, level, namespace_='', name_='DefaultType2', namespacedef_='', pretty_print=True): + imported_ns_def_ = GenerateDSNamespaceDefs_.get('DefaultType2') + if imported_ns_def_ is not None: + namespacedef_ = imported_ns_def_ if pretty_print: eol_ = '\n' else: diff --git a/tests/extensions1_sup.py b/tests/extensions1_sup.py index 18b6c74ae3bda8a2d92c6b7ce32f255c554c4234..6eb4a465157d53d09cc6cc3e022411ad9eea9af8 100644 --- a/tests/extensions1_sup.py +++ b/tests/extensions1_sup.py @@ -55,7 +55,33 @@ def parsexml_(infile, parser=None, **kwargs): return doc # -# User methods +# Namespace prefix definition table (and other attributes, too) +# +# The module generatedsnamespaces, if it is importable, must contain +# a dictionary named GeneratedsNamespaceDefs. This Python dictionary +# should map element type names (strings) to XML schema namespace prefix +# definitions. The export method for any class for which there is +# a namespace prefix definition, will export that definition in the +# XML representation of that element. See the export method of +# any generated element type class for a example of the use of this +# table. +# A sample table is: +# +# # File: generatedsnamespaces.py +# +# GenerateDSNamespaceDefs = { +# "ElementtypeA": "http://www.xxx.com/namespaceA", +# "ElementtypeB": "http://www.xxx.com/namespaceB", +# } +# + +try: + from generatedsnamespaces import GenerateDSNamespaceDefs as GenerateDSNamespaceDefs_ +except ImportError: + GenerateDSNamespaceDefs_ = {} + +# +# The root super-class for element type classes # # Calls to the methods in these classes are generated by generateDS.py. # You can replace these methods by re-implementing the following class @@ -697,6 +723,9 @@ class SpecialDate(GeneratedsSuper): else: return False def export(self, outfile, level, namespace_='', name_='SpecialDate', namespacedef_='', pretty_print=True): + imported_ns_def_ = GenerateDSNamespaceDefs_.get('SpecialDate') + if imported_ns_def_ is not None: + namespacedef_ = imported_ns_def_ if pretty_print: eol_ = '\n' else: @@ -772,6 +801,9 @@ class ExtremeDate(GeneratedsSuper): else: return False def export(self, outfile, level, namespace_='', name_='ExtremeDate', namespacedef_='', pretty_print=True): + imported_ns_def_ = GenerateDSNamespaceDefs_.get('ExtremeDate') + if imported_ns_def_ is not None: + namespacedef_ = imported_ns_def_ if pretty_print: eol_ = '\n' else: @@ -847,6 +879,9 @@ class singleExtremeDate(GeneratedsSuper): else: return False def export(self, outfile, level, namespace_='', name_='singleExtremeDate', namespacedef_='', pretty_print=True): + imported_ns_def_ = GenerateDSNamespaceDefs_.get('singleExtremeDate') + if imported_ns_def_ is not None: + namespacedef_ = imported_ns_def_ if pretty_print: eol_ = '\n' else: @@ -929,6 +964,9 @@ class containerType(GeneratedsSuper): else: return False def export(self, outfile, level, namespace_='', name_='containerType', namespacedef_='', pretty_print=True): + imported_ns_def_ = GenerateDSNamespaceDefs_.get('containerType') + if imported_ns_def_ is not None: + namespacedef_ = imported_ns_def_ if pretty_print: eol_ = '\n' else: @@ -1041,6 +1079,9 @@ class simpleFactoidType(GeneratedsSuper): else: return False def export(self, outfile, level, namespace_='', name_='simpleFactoidType', namespacedef_='', pretty_print=True): + imported_ns_def_ = GenerateDSNamespaceDefs_.get('simpleFactoidType') + if imported_ns_def_ is not None: + namespacedef_ = imported_ns_def_ if pretty_print: eol_ = '\n' else: @@ -1162,6 +1203,9 @@ class mixedFactoidType(GeneratedsSuper): else: return False def export(self, outfile, level, namespace_='', name_='mixedFactoidType', namespacedef_='', pretty_print=True): + imported_ns_def_ = GenerateDSNamespaceDefs_.get('mixedFactoidType') + if imported_ns_def_ is not None: + namespacedef_ = imported_ns_def_ if pretty_print: eol_ = '\n' else: @@ -1253,6 +1297,9 @@ class BaseType(GeneratedsSuper): else: return False def export(self, outfile, level, namespace_='', name_='BaseType', namespacedef_='', pretty_print=True): + imported_ns_def_ = GenerateDSNamespaceDefs_.get('BaseType') + if imported_ns_def_ is not None: + namespacedef_ = imported_ns_def_ if pretty_print: eol_ = '\n' else: @@ -1349,6 +1396,9 @@ class DerivedType(BaseType): else: return False def export(self, outfile, level, namespace_='', name_='DerivedType', namespacedef_='', pretty_print=True): + imported_ns_def_ = GenerateDSNamespaceDefs_.get('DerivedType') + if imported_ns_def_ is not None: + namespacedef_ = imported_ns_def_ if pretty_print: eol_ = '\n' else: @@ -1434,6 +1484,9 @@ class MyInteger(GeneratedsSuper): else: return False def export(self, outfile, level, namespace_='', name_='MyInteger', namespacedef_='', pretty_print=True): + imported_ns_def_ = GenerateDSNamespaceDefs_.get('MyInteger') + if imported_ns_def_ is not None: + namespacedef_ = imported_ns_def_ if pretty_print: eol_ = '\n' else: @@ -1509,6 +1562,9 @@ class MyBoolean(GeneratedsSuper): else: return False def export(self, outfile, level, namespace_='', name_='MyBoolean', namespacedef_='', pretty_print=True): + imported_ns_def_ = GenerateDSNamespaceDefs_.get('MyBoolean') + if imported_ns_def_ is not None: + namespacedef_ = imported_ns_def_ if pretty_print: eol_ = '\n' else: @@ -1584,6 +1640,9 @@ class MyFloat(GeneratedsSuper): else: return False def export(self, outfile, level, namespace_='', name_='MyFloat', namespacedef_='', pretty_print=True): + imported_ns_def_ = GenerateDSNamespaceDefs_.get('MyFloat') + if imported_ns_def_ is not None: + namespacedef_ = imported_ns_def_ if pretty_print: eol_ = '\n' else: @@ -1659,6 +1718,9 @@ class MyDouble(GeneratedsSuper): else: return False def export(self, outfile, level, namespace_='', name_='MyDouble', namespacedef_='', pretty_print=True): + imported_ns_def_ = GenerateDSNamespaceDefs_.get('MyDouble') + if imported_ns_def_ is not None: + namespacedef_ = imported_ns_def_ if pretty_print: eol_ = '\n' else: diff --git a/tests/ipo1_sup.py b/tests/ipo1_sup.py index a8103241d16d691fd4fa944621e02e07fb521236..34ba227d17a67b5c7d2e85a38aefdd53312aa531 100644 --- a/tests/ipo1_sup.py +++ b/tests/ipo1_sup.py @@ -54,7 +54,33 @@ def parsexml_(infile, parser=None, **kwargs): return doc # -# User methods +# Namespace prefix definition table (and other attributes, too) +# +# The module generatedsnamespaces, if it is importable, must contain +# a dictionary named GeneratedsNamespaceDefs. This Python dictionary +# should map element type names (strings) to XML schema namespace prefix +# definitions. The export method for any class for which there is +# a namespace prefix definition, will export that definition in the +# XML representation of that element. See the export method of +# any generated element type class for a example of the use of this +# table. +# A sample table is: +# +# # File: generatedsnamespaces.py +# +# GenerateDSNamespaceDefs = { +# "ElementtypeA": "http://www.xxx.com/namespaceA", +# "ElementtypeB": "http://www.xxx.com/namespaceB", +# } +# + +try: + from generatedsnamespaces import GenerateDSNamespaceDefs as GenerateDSNamespaceDefs_ +except ImportError: + GenerateDSNamespaceDefs_ = {} + +# +# The root super-class for element type classes # # Calls to the methods in these classes are generated by generateDS.py. # You can replace these methods by re-implementing the following class @@ -715,6 +741,9 @@ class PurchaseOrderType(GeneratedsSuper): else: return False def export(self, outfile, level, namespace_='ipo:', name_='PurchaseOrderType', namespacedef_='xmlns:ipo="http://www.example.com/IPO"', pretty_print=True): + imported_ns_def_ = GenerateDSNamespaceDefs_.get('PurchaseOrderType') + if imported_ns_def_ is not None: + namespacedef_ = imported_ns_def_ if pretty_print: eol_ = '\n' else: @@ -826,6 +855,9 @@ class Items(GeneratedsSuper): else: return False def export(self, outfile, level, namespace_='ipo:', name_='Items', namespacedef_='xmlns:ipo="http://www.example.com/IPO"', pretty_print=True): + imported_ns_def_ = GenerateDSNamespaceDefs_.get('Items') + if imported_ns_def_ is not None: + namespacedef_ = imported_ns_def_ if pretty_print: eol_ = '\n' else: @@ -928,6 +960,9 @@ class item(GeneratedsSuper): else: return False def export(self, outfile, level, namespace_='ipo:', name_='item', namespacedef_='xmlns:ipo="http://www.example.com/IPO"', pretty_print=True): + imported_ns_def_ = GenerateDSNamespaceDefs_.get('item') + if imported_ns_def_ is not None: + namespacedef_ = imported_ns_def_ if pretty_print: eol_ = '\n' else: @@ -1042,6 +1077,9 @@ class quantity(GeneratedsSuper): else: return False def export(self, outfile, level, namespace_='ipo:', name_='quantity', namespacedef_='xmlns:ipo="http://www.example.com/IPO"', pretty_print=True): + imported_ns_def_ = GenerateDSNamespaceDefs_.get('quantity') + if imported_ns_def_ is not None: + namespacedef_ = imported_ns_def_ if pretty_print: eol_ = '\n' else: @@ -1119,6 +1157,9 @@ class Address(GeneratedsSuper): else: return False def export(self, outfile, level, namespace_='ipo:', name_='Address', namespacedef_='xmlns:ipo="http://www.example.com/IPO"', pretty_print=True): + imported_ns_def_ = GenerateDSNamespaceDefs_.get('Address') + if imported_ns_def_ is not None: + namespacedef_ = imported_ns_def_ if pretty_print: eol_ = '\n' else: @@ -1234,6 +1275,9 @@ class USAddress(Address): else: return False def export(self, outfile, level, namespace_='ipo:', name_='USAddress', namespacedef_='xmlns:ipo="http://www.example.com/IPO"', pretty_print=True): + imported_ns_def_ = GenerateDSNamespaceDefs_.get('USAddress') + if imported_ns_def_ is not None: + namespacedef_ = imported_ns_def_ if pretty_print: eol_ = '\n' else: @@ -1331,6 +1375,9 @@ class UKAddress(Address): else: return False def export(self, outfile, level, namespace_='ipo:', name_='UKAddress', namespacedef_='xmlns:ipo="http://www.example.com/IPO"', pretty_print=True): + imported_ns_def_ = GenerateDSNamespaceDefs_.get('UKAddress') + if imported_ns_def_ is not None: + namespacedef_ = imported_ns_def_ if pretty_print: eol_ = '\n' else: diff --git a/tests/ipo2_sup.py b/tests/ipo2_sup.py index a8103241d16d691fd4fa944621e02e07fb521236..34ba227d17a67b5c7d2e85a38aefdd53312aa531 100644 --- a/tests/ipo2_sup.py +++ b/tests/ipo2_sup.py @@ -54,7 +54,33 @@ def parsexml_(infile, parser=None, **kwargs): return doc # -# User methods +# Namespace prefix definition table (and other attributes, too) +# +# The module generatedsnamespaces, if it is importable, must contain +# a dictionary named GeneratedsNamespaceDefs. This Python dictionary +# should map element type names (strings) to XML schema namespace prefix +# definitions. The export method for any class for which there is +# a namespace prefix definition, will export that definition in the +# XML representation of that element. See the export method of +# any generated element type class for a example of the use of this +# table. +# A sample table is: +# +# # File: generatedsnamespaces.py +# +# GenerateDSNamespaceDefs = { +# "ElementtypeA": "http://www.xxx.com/namespaceA", +# "ElementtypeB": "http://www.xxx.com/namespaceB", +# } +# + +try: + from generatedsnamespaces import GenerateDSNamespaceDefs as GenerateDSNamespaceDefs_ +except ImportError: + GenerateDSNamespaceDefs_ = {} + +# +# The root super-class for element type classes # # Calls to the methods in these classes are generated by generateDS.py. # You can replace these methods by re-implementing the following class @@ -715,6 +741,9 @@ class PurchaseOrderType(GeneratedsSuper): else: return False def export(self, outfile, level, namespace_='ipo:', name_='PurchaseOrderType', namespacedef_='xmlns:ipo="http://www.example.com/IPO"', pretty_print=True): + imported_ns_def_ = GenerateDSNamespaceDefs_.get('PurchaseOrderType') + if imported_ns_def_ is not None: + namespacedef_ = imported_ns_def_ if pretty_print: eol_ = '\n' else: @@ -826,6 +855,9 @@ class Items(GeneratedsSuper): else: return False def export(self, outfile, level, namespace_='ipo:', name_='Items', namespacedef_='xmlns:ipo="http://www.example.com/IPO"', pretty_print=True): + imported_ns_def_ = GenerateDSNamespaceDefs_.get('Items') + if imported_ns_def_ is not None: + namespacedef_ = imported_ns_def_ if pretty_print: eol_ = '\n' else: @@ -928,6 +960,9 @@ class item(GeneratedsSuper): else: return False def export(self, outfile, level, namespace_='ipo:', name_='item', namespacedef_='xmlns:ipo="http://www.example.com/IPO"', pretty_print=True): + imported_ns_def_ = GenerateDSNamespaceDefs_.get('item') + if imported_ns_def_ is not None: + namespacedef_ = imported_ns_def_ if pretty_print: eol_ = '\n' else: @@ -1042,6 +1077,9 @@ class quantity(GeneratedsSuper): else: return False def export(self, outfile, level, namespace_='ipo:', name_='quantity', namespacedef_='xmlns:ipo="http://www.example.com/IPO"', pretty_print=True): + imported_ns_def_ = GenerateDSNamespaceDefs_.get('quantity') + if imported_ns_def_ is not None: + namespacedef_ = imported_ns_def_ if pretty_print: eol_ = '\n' else: @@ -1119,6 +1157,9 @@ class Address(GeneratedsSuper): else: return False def export(self, outfile, level, namespace_='ipo:', name_='Address', namespacedef_='xmlns:ipo="http://www.example.com/IPO"', pretty_print=True): + imported_ns_def_ = GenerateDSNamespaceDefs_.get('Address') + if imported_ns_def_ is not None: + namespacedef_ = imported_ns_def_ if pretty_print: eol_ = '\n' else: @@ -1234,6 +1275,9 @@ class USAddress(Address): else: return False def export(self, outfile, level, namespace_='ipo:', name_='USAddress', namespacedef_='xmlns:ipo="http://www.example.com/IPO"', pretty_print=True): + imported_ns_def_ = GenerateDSNamespaceDefs_.get('USAddress') + if imported_ns_def_ is not None: + namespacedef_ = imported_ns_def_ if pretty_print: eol_ = '\n' else: @@ -1331,6 +1375,9 @@ class UKAddress(Address): else: return False def export(self, outfile, level, namespace_='ipo:', name_='UKAddress', namespacedef_='xmlns:ipo="http://www.example.com/IPO"', pretty_print=True): + imported_ns_def_ = GenerateDSNamespaceDefs_.get('UKAddress') + if imported_ns_def_ is not None: + namespacedef_ = imported_ns_def_ if pretty_print: eol_ = '\n' else: diff --git a/tests/mapcleanname1_sup.py b/tests/mapcleanname1_sup.py index f6017af6ae1985ce90f15593977aa45383e494cd..96a479bcb1a405394f8cb47810c8e2c59050f7ad 100644 --- a/tests/mapcleanname1_sup.py +++ b/tests/mapcleanname1_sup.py @@ -55,7 +55,33 @@ def parsexml_(infile, parser=None, **kwargs): return doc # -# User methods +# Namespace prefix definition table (and other attributes, too) +# +# The module generatedsnamespaces, if it is importable, must contain +# a dictionary named GeneratedsNamespaceDefs. This Python dictionary +# should map element type names (strings) to XML schema namespace prefix +# definitions. The export method for any class for which there is +# a namespace prefix definition, will export that definition in the +# XML representation of that element. See the export method of +# any generated element type class for a example of the use of this +# table. +# A sample table is: +# +# # File: generatedsnamespaces.py +# +# GenerateDSNamespaceDefs = { +# "ElementtypeA": "http://www.xxx.com/namespaceA", +# "ElementtypeB": "http://www.xxx.com/namespaceB", +# } +# + +try: + from generatedsnamespaces import GenerateDSNamespaceDefs as GenerateDSNamespaceDefs_ +except ImportError: + GenerateDSNamespaceDefs_ = {} + +# +# The root super-class for element type classes # # Calls to the methods in these classes are generated by generateDS.py. # You can replace these methods by re-implementing the following class @@ -714,6 +740,9 @@ class complex_type01(GeneratedsSuper): else: return False def export(self, outfile, level, namespace_='', name_='complex-type01', namespacedef_='', pretty_print=True): + imported_ns_def_ = GenerateDSNamespaceDefs_.get('complex-type01') + if imported_ns_def_ is not None: + namespacedef_ = imported_ns_def_ if pretty_print: eol_ = '\n' else: @@ -836,6 +865,9 @@ class complex_type02(GeneratedsSuper): else: return False def export(self, outfile, level, namespace_='', name_='complex-type02', namespacedef_='', pretty_print=True): + imported_ns_def_ = GenerateDSNamespaceDefs_.get('complex-type02') + if imported_ns_def_ is not None: + namespacedef_ = imported_ns_def_ if pretty_print: eol_ = '\n' else: @@ -957,6 +989,9 @@ class complex_type03(complex_type02): else: return False def export(self, outfile, level, namespace_='', name_='complex-type03', namespacedef_='', pretty_print=True): + imported_ns_def_ = GenerateDSNamespaceDefs_.get('complex-type03') + if imported_ns_def_ is not None: + namespacedef_ = imported_ns_def_ if pretty_print: eol_ = '\n' else: @@ -1074,6 +1109,9 @@ class type_(GeneratedsSuper): else: return False def export(self, outfile, level, namespace_='', name_='type', namespacedef_='', pretty_print=True): + imported_ns_def_ = GenerateDSNamespaceDefs_.get('type') + if imported_ns_def_ is not None: + namespacedef_ = imported_ns_def_ if pretty_print: eol_ = '\n' else: @@ -1195,6 +1233,9 @@ class complex_type04(type_): else: return False def export(self, outfile, level, namespace_='', name_='complex-type04', namespacedef_='', pretty_print=True): + imported_ns_def_ = GenerateDSNamespaceDefs_.get('complex-type04') + if imported_ns_def_ is not None: + namespacedef_ = imported_ns_def_ if pretty_print: eol_ = '\n' else: @@ -1312,6 +1353,9 @@ class build_(GeneratedsSuper): else: return False def export(self, outfile, level, namespace_='', name_='build', namespacedef_='', pretty_print=True): + imported_ns_def_ = GenerateDSNamespaceDefs_.get('build') + if imported_ns_def_ is not None: + namespacedef_ = imported_ns_def_ if pretty_print: eol_ = '\n' else: @@ -1433,6 +1477,9 @@ class complex_type05(build_): else: return False def export(self, outfile, level, namespace_='', name_='complex-type05', namespacedef_='', pretty_print=True): + imported_ns_def_ = GenerateDSNamespaceDefs_.get('complex-type05') + if imported_ns_def_ is not None: + namespacedef_ = imported_ns_def_ if pretty_print: eol_ = '\n' else: diff --git a/tests/nested_def1_sup.py b/tests/nested_def1_sup.py index 86079794fe66bf243a5209cc045dd1cac5c1d855..9ead07e6528d6c6000a388f3f731b31a31201144 100644 --- a/tests/nested_def1_sup.py +++ b/tests/nested_def1_sup.py @@ -54,7 +54,33 @@ def parsexml_(infile, parser=None, **kwargs): return doc # -# User methods +# Namespace prefix definition table (and other attributes, too) +# +# The module generatedsnamespaces, if it is importable, must contain +# a dictionary named GeneratedsNamespaceDefs. This Python dictionary +# should map element type names (strings) to XML schema namespace prefix +# definitions. The export method for any class for which there is +# a namespace prefix definition, will export that definition in the +# XML representation of that element. See the export method of +# any generated element type class for a example of the use of this +# table. +# A sample table is: +# +# # File: generatedsnamespaces.py +# +# GenerateDSNamespaceDefs = { +# "ElementtypeA": "http://www.xxx.com/namespaceA", +# "ElementtypeB": "http://www.xxx.com/namespaceB", +# } +# + +try: + from generatedsnamespaces import GenerateDSNamespaceDefs as GenerateDSNamespaceDefs_ +except ImportError: + GenerateDSNamespaceDefs_ = {} + +# +# The root super-class for element type classes # # Calls to the methods in these classes are generated by generateDS.py. # You can replace these methods by re-implementing the following class @@ -697,6 +723,9 @@ class containerType(GeneratedsSuper): else: return False def export(self, outfile, level, namespace_='', name_='containerType', namespacedef_='', pretty_print=True): + imported_ns_def_ = GenerateDSNamespaceDefs_.get('containerType') + if imported_ns_def_ is not None: + namespacedef_ = imported_ns_def_ if pretty_print: eol_ = '\n' else: @@ -778,6 +807,9 @@ class classAType(GeneratedsSuper): else: return False def export(self, outfile, level, namespace_='', name_='classAType', namespacedef_='', pretty_print=True): + imported_ns_def_ = GenerateDSNamespaceDefs_.get('classAType') + if imported_ns_def_ is not None: + namespacedef_ = imported_ns_def_ if pretty_print: eol_ = '\n' else: @@ -852,6 +884,9 @@ class classBType(GeneratedsSuper): else: return False def export(self, outfile, level, namespace_='', name_='classBType', namespacedef_='', pretty_print=True): + imported_ns_def_ = GenerateDSNamespaceDefs_.get('classBType') + if imported_ns_def_ is not None: + namespacedef_ = imported_ns_def_ if pretty_print: eol_ = '\n' else: @@ -930,6 +965,9 @@ class innerType(GeneratedsSuper): else: return False def export(self, outfile, level, namespace_='', name_='innerType', namespacedef_='', pretty_print=True): + imported_ns_def_ = GenerateDSNamespaceDefs_.get('innerType') + if imported_ns_def_ is not None: + namespacedef_ = imported_ns_def_ if pretty_print: eol_ = '\n' else: @@ -1010,6 +1048,9 @@ class innerType1(GeneratedsSuper): else: return False def export(self, outfile, level, namespace_='', name_='innerType1', namespacedef_='', pretty_print=True): + imported_ns_def_ = GenerateDSNamespaceDefs_.get('innerType1') + if imported_ns_def_ is not None: + namespacedef_ = imported_ns_def_ if pretty_print: eol_ = '\n' else: diff --git a/tests/out1_sup.py b/tests/out1_sup.py index 3530babe3909ec04d9d6225f39c647155e3ae096..24fa5f721b0f9528644b6f73d6cc8794b461761e 100644 --- a/tests/out1_sup.py +++ b/tests/out1_sup.py @@ -55,7 +55,33 @@ def parsexml_(infile, parser=None, **kwargs): return doc # -# User methods +# Namespace prefix definition table (and other attributes, too) +# +# The module generatedsnamespaces, if it is importable, must contain +# a dictionary named GeneratedsNamespaceDefs. This Python dictionary +# should map element type names (strings) to XML schema namespace prefix +# definitions. The export method for any class for which there is +# a namespace prefix definition, will export that definition in the +# XML representation of that element. See the export method of +# any generated element type class for a example of the use of this +# table. +# A sample table is: +# +# # File: generatedsnamespaces.py +# +# GenerateDSNamespaceDefs = { +# "ElementtypeA": "http://www.xxx.com/namespaceA", +# "ElementtypeB": "http://www.xxx.com/namespaceB", +# } +# + +try: + from generatedsnamespaces import GenerateDSNamespaceDefs as GenerateDSNamespaceDefs_ +except ImportError: + GenerateDSNamespaceDefs_ = {} + +# +# The root super-class for element type classes # # Calls to the methods in these classes are generated by generateDS.py. # You can replace these methods by re-implementing the following class @@ -743,6 +769,9 @@ class people(GeneratedsSuper): else: return False def export(self, outfile, level, namespace_='', name_='people', namespacedef_='', pretty_print=True): + imported_ns_def_ = GenerateDSNamespaceDefs_.get('people') + if imported_ns_def_ is not None: + namespacedef_ = imported_ns_def_ if pretty_print: eol_ = '\n' else: @@ -987,6 +1016,9 @@ class comments(GeneratedsSuper): else: return False def export(self, outfile, level, namespace_='', name_='comments', namespacedef_='', pretty_print=True): + imported_ns_def_ = GenerateDSNamespaceDefs_.get('comments') + if imported_ns_def_ is not None: + namespacedef_ = imported_ns_def_ if pretty_print: eol_ = '\n' else: @@ -1197,6 +1229,9 @@ class person(GeneratedsSuper): else: return False def export(self, outfile, level, namespace_='', name_='person', namespacedef_='', pretty_print=True): + imported_ns_def_ = GenerateDSNamespaceDefs_.get('person') + if imported_ns_def_ is not None: + namespacedef_ = imported_ns_def_ if pretty_print: eol_ = '\n' else: @@ -1578,6 +1613,9 @@ class programmer(person): else: return False def export(self, outfile, level, namespace_='', name_='programmer', namespacedef_='', pretty_print=True): + imported_ns_def_ = GenerateDSNamespaceDefs_.get('programmer') + if imported_ns_def_ is not None: + namespacedef_ = imported_ns_def_ if pretty_print: eol_ = '\n' else: @@ -1984,6 +2022,9 @@ class param(GeneratedsSuper): else: return False def export(self, outfile, level, namespace_='', name_='param', namespacedef_='', pretty_print=True): + imported_ns_def_ = GenerateDSNamespaceDefs_.get('param') + if imported_ns_def_ is not None: + namespacedef_ = imported_ns_def_ if pretty_print: eol_ = '\n' else: @@ -2178,6 +2219,9 @@ class python_programmer(programmer): else: return False def export(self, outfile, level, namespace_='', name_='python-programmer', namespacedef_='', pretty_print=True): + imported_ns_def_ = GenerateDSNamespaceDefs_.get('python-programmer') + if imported_ns_def_ is not None: + namespacedef_ = imported_ns_def_ if pretty_print: eol_ = '\n' else: @@ -2334,6 +2378,9 @@ class java_programmer(programmer): else: return False def export(self, outfile, level, namespace_='', name_='java-programmer', namespacedef_='', pretty_print=True): + imported_ns_def_ = GenerateDSNamespaceDefs_.get('java-programmer') + if imported_ns_def_ is not None: + namespacedef_ = imported_ns_def_ if pretty_print: eol_ = '\n' else: @@ -2506,6 +2553,9 @@ class agent(GeneratedsSuper): else: return False def export(self, outfile, level, namespace_='', name_='agent', namespacedef_='', pretty_print=True): + imported_ns_def_ = GenerateDSNamespaceDefs_.get('agent') + if imported_ns_def_ is not None: + namespacedef_ = imported_ns_def_ if pretty_print: eol_ = '\n' else: @@ -2690,6 +2740,9 @@ class special_agent(GeneratedsSuper): else: return False def export(self, outfile, level, namespace_='', name_='special-agent', namespacedef_='', pretty_print=True): + imported_ns_def_ = GenerateDSNamespaceDefs_.get('special-agent') + if imported_ns_def_ is not None: + namespacedef_ = imported_ns_def_ if pretty_print: eol_ = '\n' else: @@ -2907,6 +2960,9 @@ class booster(GeneratedsSuper): else: return False def export(self, outfile, level, namespace_='', name_='booster', namespacedef_='', pretty_print=True): + imported_ns_def_ = GenerateDSNamespaceDefs_.get('booster') + if imported_ns_def_ is not None: + namespacedef_ = imported_ns_def_ if pretty_print: eol_ = '\n' else: @@ -3144,6 +3200,9 @@ class info(GeneratedsSuper): else: return False def export(self, outfile, level, namespace_='', name_='info', namespacedef_='', pretty_print=True): + imported_ns_def_ = GenerateDSNamespaceDefs_.get('info') + if imported_ns_def_ is not None: + namespacedef_ = imported_ns_def_ if pretty_print: eol_ = '\n' else: @@ -3305,6 +3364,9 @@ class client_handlerType(GeneratedsSuper): else: return False def export(self, outfile, level, namespace_='', name_='client-handlerType', namespacedef_='', pretty_print=True): + imported_ns_def_ = GenerateDSNamespaceDefs_.get('client-handlerType') + if imported_ns_def_ is not None: + namespacedef_ = imported_ns_def_ if pretty_print: eol_ = '\n' else: diff --git a/tests/people_procincl1_sup.py b/tests/people_procincl1_sup.py index 6898534bf8f60c78a48f378635a1f53d0725340b..b592f81724b26a2c4d074d830d5d2ac3eacaefdf 100644 --- a/tests/people_procincl1_sup.py +++ b/tests/people_procincl1_sup.py @@ -55,7 +55,33 @@ def parsexml_(infile, parser=None, **kwargs): return doc # -# User methods +# Namespace prefix definition table (and other attributes, too) +# +# The module generatedsnamespaces, if it is importable, must contain +# a dictionary named GeneratedsNamespaceDefs. This Python dictionary +# should map element type names (strings) to XML schema namespace prefix +# definitions. The export method for any class for which there is +# a namespace prefix definition, will export that definition in the +# XML representation of that element. See the export method of +# any generated element type class for a example of the use of this +# table. +# A sample table is: +# +# # File: generatedsnamespaces.py +# +# GenerateDSNamespaceDefs = { +# "ElementtypeA": "http://www.xxx.com/namespaceA", +# "ElementtypeB": "http://www.xxx.com/namespaceB", +# } +# + +try: + from generatedsnamespaces import GenerateDSNamespaceDefs as GenerateDSNamespaceDefs_ +except ImportError: + GenerateDSNamespaceDefs_ = {} + +# +# The root super-class for element type classes # # Calls to the methods in these classes are generated by generateDS.py. # You can replace these methods by re-implementing the following class @@ -755,6 +781,9 @@ class people(GeneratedsSuper): else: return False def export(self, outfile, level, namespace_='', name_='people', namespacedef_='', pretty_print=True): + imported_ns_def_ = GenerateDSNamespaceDefs_.get('people') + if imported_ns_def_ is not None: + namespacedef_ = imported_ns_def_ if pretty_print: eol_ = '\n' else: @@ -897,6 +926,9 @@ class comments(GeneratedsSuper): else: return False def export(self, outfile, level, namespace_='', name_='comments', namespacedef_='', pretty_print=True): + imported_ns_def_ = GenerateDSNamespaceDefs_.get('comments') + if imported_ns_def_ is not None: + namespacedef_ = imported_ns_def_ if pretty_print: eol_ = '\n' else: @@ -1051,6 +1083,9 @@ class person(GeneratedsSuper): else: return False def export(self, outfile, level, namespace_='', name_='person', namespacedef_='', pretty_print=True): + imported_ns_def_ = GenerateDSNamespaceDefs_.get('person') + if imported_ns_def_ is not None: + namespacedef_ = imported_ns_def_ if pretty_print: eol_ = '\n' else: @@ -1208,6 +1243,9 @@ class specialperson(person): else: return False def export(self, outfile, level, namespace_='', name_='specialperson', namespacedef_='', pretty_print=True): + imported_ns_def_ = GenerateDSNamespaceDefs_.get('specialperson') + if imported_ns_def_ is not None: + namespacedef_ = imported_ns_def_ if pretty_print: eol_ = '\n' else: @@ -1300,6 +1338,9 @@ class param(GeneratedsSuper): else: return False def export(self, outfile, level, namespace_='', name_='param', namespacedef_='', pretty_print=True): + imported_ns_def_ = GenerateDSNamespaceDefs_.get('param') + if imported_ns_def_ is not None: + namespacedef_ = imported_ns_def_ if pretty_print: eol_ = '\n' else: @@ -1433,6 +1474,9 @@ class agent(GeneratedsSuper): else: return False def export(self, outfile, level, namespace_='', name_='agent', namespacedef_='', pretty_print=True): + imported_ns_def_ = GenerateDSNamespaceDefs_.get('agent') + if imported_ns_def_ is not None: + namespacedef_ = imported_ns_def_ if pretty_print: eol_ = '\n' else: @@ -1570,6 +1614,9 @@ class special_agent(GeneratedsSuper): else: return False def export(self, outfile, level, namespace_='', name_='special-agent', namespacedef_='', pretty_print=True): + imported_ns_def_ = GenerateDSNamespaceDefs_.get('special-agent') + if imported_ns_def_ is not None: + namespacedef_ = imported_ns_def_ if pretty_print: eol_ = '\n' else: @@ -1721,6 +1768,9 @@ class booster(GeneratedsSuper): else: return False def export(self, outfile, level, namespace_='', name_='booster', namespacedef_='', pretty_print=True): + imported_ns_def_ = GenerateDSNamespaceDefs_.get('booster') + if imported_ns_def_ is not None: + namespacedef_ = imported_ns_def_ if pretty_print: eol_ = '\n' else: @@ -1866,6 +1916,9 @@ class info(GeneratedsSuper): else: return False def export(self, outfile, level, namespace_='', name_='info', namespacedef_='', pretty_print=True): + imported_ns_def_ = GenerateDSNamespaceDefs_.get('info') + if imported_ns_def_ is not None: + namespacedef_ = imported_ns_def_ if pretty_print: eol_ = '\n' else: @@ -1958,6 +2011,9 @@ class vehicle(GeneratedsSuper): else: return False def export(self, outfile, level, namespace_='', name_='vehicle', namespacedef_='', pretty_print=True): + imported_ns_def_ = GenerateDSNamespaceDefs_.get('vehicle') + if imported_ns_def_ is not None: + namespacedef_ = imported_ns_def_ if pretty_print: eol_ = '\n' else: @@ -2045,6 +2101,9 @@ class automobile(vehicle): else: return False def export(self, outfile, level, namespace_='', name_='automobile', namespacedef_='', pretty_print=True): + imported_ns_def_ = GenerateDSNamespaceDefs_.get('automobile') + if imported_ns_def_ is not None: + namespacedef_ = imported_ns_def_ if pretty_print: eol_ = '\n' else: @@ -2123,6 +2182,9 @@ class airplane(vehicle): else: return False def export(self, outfile, level, namespace_='', name_='airplane', namespacedef_='', pretty_print=True): + imported_ns_def_ = GenerateDSNamespaceDefs_.get('airplane') + if imported_ns_def_ is not None: + namespacedef_ = imported_ns_def_ if pretty_print: eol_ = '\n' else: @@ -2297,6 +2359,9 @@ class programmer(person): else: return False def export(self, outfile, level, namespace_='', name_='programmer', namespacedef_='', pretty_print=True): + imported_ns_def_ = GenerateDSNamespaceDefs_.get('programmer') + if imported_ns_def_ is not None: + namespacedef_ = imported_ns_def_ if pretty_print: eol_ = '\n' else: @@ -2556,6 +2621,9 @@ class client_handlerType(GeneratedsSuper): else: return False def export(self, outfile, level, namespace_='', name_='client-handlerType', namespacedef_='', pretty_print=True): + imported_ns_def_ = GenerateDSNamespaceDefs_.get('client-handlerType') + if imported_ns_def_ is not None: + namespacedef_ = imported_ns_def_ if pretty_print: eol_ = '\n' else: @@ -2654,6 +2722,9 @@ class java_programmer(programmer): else: return False def export(self, outfile, level, namespace_='', name_='java-programmer', namespacedef_='', pretty_print=True): + imported_ns_def_ = GenerateDSNamespaceDefs_.get('java-programmer') + if imported_ns_def_ is not None: + namespacedef_ = imported_ns_def_ if pretty_print: eol_ = '\n' else: @@ -2752,6 +2823,9 @@ class python_programmer(programmer): else: return False def export(self, outfile, level, namespace_='', name_='python-programmer', namespacedef_='', pretty_print=True): + imported_ns_def_ = GenerateDSNamespaceDefs_.get('python-programmer') + if imported_ns_def_ is not None: + namespacedef_ = imported_ns_def_ if pretty_print: eol_ = '\n' else: diff --git a/tests/prefix_classname1_sup.py b/tests/prefix_classname1_sup.py index e0fa52d4e7e2e732abd726cb1ff29f8dff040592..0c4fe6cdb0960e246d23eb907c18c34c1a7ce1d6 100644 --- a/tests/prefix_classname1_sup.py +++ b/tests/prefix_classname1_sup.py @@ -55,7 +55,33 @@ def parsexml_(infile, parser=None, **kwargs): return doc # -# User methods +# Namespace prefix definition table (and other attributes, too) +# +# The module generatedsnamespaces, if it is importable, must contain +# a dictionary named GeneratedsNamespaceDefs. This Python dictionary +# should map element type names (strings) to XML schema namespace prefix +# definitions. The export method for any class for which there is +# a namespace prefix definition, will export that definition in the +# XML representation of that element. See the export method of +# any generated element type class for a example of the use of this +# table. +# A sample table is: +# +# # File: generatedsnamespaces.py +# +# GenerateDSNamespaceDefs = { +# "ElementtypeA": "http://www.xxx.com/namespaceA", +# "ElementtypeB": "http://www.xxx.com/namespaceB", +# } +# + +try: + from generatedsnamespaces import GenerateDSNamespaceDefs as GenerateDSNamespaceDefs_ +except ImportError: + GenerateDSNamespaceDefs_ = {} + +# +# The root super-class for element type classes # # Calls to the methods in these classes are generated by generateDS.py. # You can replace these methods by re-implementing the following class @@ -743,6 +769,9 @@ class tomato_people(GeneratedsSuper): else: return False def export(self, outfile, level, namespace_='', name_='people', namespacedef_='', pretty_print=True): + imported_ns_def_ = GenerateDSNamespaceDefs_.get('people') + if imported_ns_def_ is not None: + namespacedef_ = imported_ns_def_ if pretty_print: eol_ = '\n' else: @@ -867,6 +896,9 @@ class tomato_comments(GeneratedsSuper): else: return False def export(self, outfile, level, namespace_='', name_='comments', namespacedef_='', pretty_print=True): + imported_ns_def_ = GenerateDSNamespaceDefs_.get('comments') + if imported_ns_def_ is not None: + namespacedef_ = imported_ns_def_ if pretty_print: eol_ = '\n' else: @@ -1013,6 +1045,9 @@ class tomato_person(GeneratedsSuper): else: return False def export(self, outfile, level, namespace_='', name_='person', namespacedef_='', pretty_print=True): + imported_ns_def_ = GenerateDSNamespaceDefs_.get('person') + if imported_ns_def_ is not None: + namespacedef_ = imported_ns_def_ if pretty_print: eol_ = '\n' else: @@ -1278,6 +1313,9 @@ class tomato_programmer(tomato_person): else: return False def export(self, outfile, level, namespace_='', name_='programmer', namespacedef_='', pretty_print=True): + imported_ns_def_ = GenerateDSNamespaceDefs_.get('programmer') + if imported_ns_def_ is not None: + namespacedef_ = imported_ns_def_ if pretty_print: eol_ = '\n' else: @@ -1565,6 +1603,9 @@ class tomato_param(GeneratedsSuper): else: return False def export(self, outfile, level, namespace_='', name_='param', namespacedef_='', pretty_print=True): + imported_ns_def_ = GenerateDSNamespaceDefs_.get('param') + if imported_ns_def_ is not None: + namespacedef_ = imported_ns_def_ if pretty_print: eol_ = '\n' else: @@ -1678,6 +1719,9 @@ class tomato_python_programmer(tomato_programmer): else: return False def export(self, outfile, level, namespace_='', name_='python-programmer', namespacedef_='', pretty_print=True): + imported_ns_def_ = GenerateDSNamespaceDefs_.get('python-programmer') + if imported_ns_def_ is not None: + namespacedef_ = imported_ns_def_ if pretty_print: eol_ = '\n' else: @@ -1771,6 +1815,9 @@ class tomato_java_programmer(tomato_programmer): else: return False def export(self, outfile, level, namespace_='', name_='java-programmer', namespacedef_='', pretty_print=True): + imported_ns_def_ = GenerateDSNamespaceDefs_.get('java-programmer') + if imported_ns_def_ is not None: + namespacedef_ = imported_ns_def_ if pretty_print: eol_ = '\n' else: @@ -1876,6 +1923,9 @@ class tomato_agent(GeneratedsSuper): else: return False def export(self, outfile, level, namespace_='', name_='agent', namespacedef_='', pretty_print=True): + imported_ns_def_ = GenerateDSNamespaceDefs_.get('agent') + if imported_ns_def_ is not None: + namespacedef_ = imported_ns_def_ if pretty_print: eol_ = '\n' else: @@ -1990,6 +2040,9 @@ class tomato_special_agent(GeneratedsSuper): else: return False def export(self, outfile, level, namespace_='', name_='special-agent', namespacedef_='', pretty_print=True): + imported_ns_def_ = GenerateDSNamespaceDefs_.get('special-agent') + if imported_ns_def_ is not None: + namespacedef_ = imported_ns_def_ if pretty_print: eol_ = '\n' else: @@ -2137,6 +2190,9 @@ class tomato_booster(GeneratedsSuper): else: return False def export(self, outfile, level, namespace_='', name_='booster', namespacedef_='', pretty_print=True): + imported_ns_def_ = GenerateDSNamespaceDefs_.get('booster') + if imported_ns_def_ is not None: + namespacedef_ = imported_ns_def_ if pretty_print: eol_ = '\n' else: @@ -2277,6 +2333,9 @@ class tomato_info(GeneratedsSuper): else: return False def export(self, outfile, level, namespace_='', name_='info', namespacedef_='', pretty_print=True): + imported_ns_def_ = GenerateDSNamespaceDefs_.get('info') + if imported_ns_def_ is not None: + namespacedef_ = imported_ns_def_ if pretty_print: eol_ = '\n' else: @@ -2371,6 +2430,9 @@ class tomato_client_handlerType(GeneratedsSuper): else: return False def export(self, outfile, level, namespace_='', name_='client-handlerType', namespacedef_='', pretty_print=True): + imported_ns_def_ = GenerateDSNamespaceDefs_.get('client-handlerType') + if imported_ns_def_ is not None: + namespacedef_ = imported_ns_def_ if pretty_print: eol_ = '\n' else: diff --git a/tests/recursive_simpletype1_sup.py b/tests/recursive_simpletype1_sup.py index b4201cf5f875e2d9be06997dab32844db02e0431..d9ed0d7504e709064a6a455f7a9df9d8304cb561 100644 --- a/tests/recursive_simpletype1_sup.py +++ b/tests/recursive_simpletype1_sup.py @@ -55,7 +55,33 @@ def parsexml_(infile, parser=None, **kwargs): return doc # -# User methods +# Namespace prefix definition table (and other attributes, too) +# +# The module generatedsnamespaces, if it is importable, must contain +# a dictionary named GeneratedsNamespaceDefs. This Python dictionary +# should map element type names (strings) to XML schema namespace prefix +# definitions. The export method for any class for which there is +# a namespace prefix definition, will export that definition in the +# XML representation of that element. See the export method of +# any generated element type class for a example of the use of this +# table. +# A sample table is: +# +# # File: generatedsnamespaces.py +# +# GenerateDSNamespaceDefs = { +# "ElementtypeA": "http://www.xxx.com/namespaceA", +# "ElementtypeB": "http://www.xxx.com/namespaceB", +# } +# + +try: + from generatedsnamespaces import GenerateDSNamespaceDefs as GenerateDSNamespaceDefs_ +except ImportError: + GenerateDSNamespaceDefs_ = {} + +# +# The root super-class for element type classes # # Calls to the methods in these classes are generated by generateDS.py. # You can replace these methods by re-implementing the following class @@ -703,6 +729,9 @@ class PersonType(GeneratedsSuper): else: return False def export(self, outfile, level, namespace_='', name_='PersonType', namespacedef_='', pretty_print=True): + imported_ns_def_ = GenerateDSNamespaceDefs_.get('PersonType') + if imported_ns_def_ is not None: + namespacedef_ = imported_ns_def_ if pretty_print: eol_ = '\n' else: diff --git a/tests/reference_simpletype1_sup.py b/tests/reference_simpletype1_sup.py index 6b00823bfdb364811fda7c2bbd2d2e86baaa90b8..15f6908b61a2663943c8520cd5455fed45c2e337 100644 --- a/tests/reference_simpletype1_sup.py +++ b/tests/reference_simpletype1_sup.py @@ -55,7 +55,33 @@ def parsexml_(infile, parser=None, **kwargs): return doc # -# User methods +# Namespace prefix definition table (and other attributes, too) +# +# The module generatedsnamespaces, if it is importable, must contain +# a dictionary named GeneratedsNamespaceDefs. This Python dictionary +# should map element type names (strings) to XML schema namespace prefix +# definitions. The export method for any class for which there is +# a namespace prefix definition, will export that definition in the +# XML representation of that element. See the export method of +# any generated element type class for a example of the use of this +# table. +# A sample table is: +# +# # File: generatedsnamespaces.py +# +# GenerateDSNamespaceDefs = { +# "ElementtypeA": "http://www.xxx.com/namespaceA", +# "ElementtypeB": "http://www.xxx.com/namespaceB", +# } +# + +try: + from generatedsnamespaces import GenerateDSNamespaceDefs as GenerateDSNamespaceDefs_ +except ImportError: + GenerateDSNamespaceDefs_ = {} + +# +# The root super-class for element type classes # # Calls to the methods in these classes are generated by generateDS.py. # You can replace these methods by re-implementing the following class @@ -707,6 +733,9 @@ class dummy(GeneratedsSuper): else: return False def export(self, outfile, level, namespace_='', name_='dummy', namespacedef_='', pretty_print=True): + imported_ns_def_ = GenerateDSNamespaceDefs_.get('dummy') + if imported_ns_def_ is not None: + namespacedef_ = imported_ns_def_ if pretty_print: eol_ = '\n' else: diff --git a/tests/rem_dup_elems1_sup.py b/tests/rem_dup_elems1_sup.py index 3740da719fc5fe32da298e8c58f70a436d1e149a..a5fe933bf55ccffea22ffa7185b5ada37564fde2 100644 --- a/tests/rem_dup_elems1_sup.py +++ b/tests/rem_dup_elems1_sup.py @@ -56,7 +56,33 @@ def parsexml_(infile, parser=None, **kwargs): return doc # -# User methods +# Namespace prefix definition table (and other attributes, too) +# +# The module generatedsnamespaces, if it is importable, must contain +# a dictionary named GeneratedsNamespaceDefs. This Python dictionary +# should map element type names (strings) to XML schema namespace prefix +# definitions. The export method for any class for which there is +# a namespace prefix definition, will export that definition in the +# XML representation of that element. See the export method of +# any generated element type class for a example of the use of this +# table. +# A sample table is: +# +# # File: generatedsnamespaces.py +# +# GenerateDSNamespaceDefs = { +# "ElementtypeA": "http://www.xxx.com/namespaceA", +# "ElementtypeB": "http://www.xxx.com/namespaceB", +# } +# + +try: + from generatedsnamespaces import GenerateDSNamespaceDefs as GenerateDSNamespaceDefs_ +except ImportError: + GenerateDSNamespaceDefs_ = {} + +# +# The root super-class for element type classes # # Calls to the methods in these classes are generated by generateDS.py. # You can replace these methods by re-implementing the following class @@ -711,6 +737,9 @@ class authorsType(GeneratedsSuper): else: return False def export(self, outfile, level, namespace_='', name_='authorsType', namespacedef_='', pretty_print=True): + imported_ns_def_ = GenerateDSNamespaceDefs_.get('authorsType') + if imported_ns_def_ is not None: + namespacedef_ = imported_ns_def_ if pretty_print: eol_ = '\n' else: @@ -792,6 +821,9 @@ class author(GeneratedsSuper): else: return False def export(self, outfile, level, namespace_='', name_='author', namespacedef_='', pretty_print=True): + imported_ns_def_ = GenerateDSNamespaceDefs_.get('author') + if imported_ns_def_ is not None: + namespacedef_ = imported_ns_def_ if pretty_print: eol_ = '\n' else: diff --git a/tests/simplecontent_restriction1_sup.py b/tests/simplecontent_restriction1_sup.py index 1533d86af9247375d6aa4d01e1ba677f53de3b22..c532b53ff309cd561b22953a60cb95c838bc9a7f 100644 --- a/tests/simplecontent_restriction1_sup.py +++ b/tests/simplecontent_restriction1_sup.py @@ -55,7 +55,33 @@ def parsexml_(infile, parser=None, **kwargs): return doc # -# User methods +# Namespace prefix definition table (and other attributes, too) +# +# The module generatedsnamespaces, if it is importable, must contain +# a dictionary named GeneratedsNamespaceDefs. This Python dictionary +# should map element type names (strings) to XML schema namespace prefix +# definitions. The export method for any class for which there is +# a namespace prefix definition, will export that definition in the +# XML representation of that element. See the export method of +# any generated element type class for a example of the use of this +# table. +# A sample table is: +# +# # File: generatedsnamespaces.py +# +# GenerateDSNamespaceDefs = { +# "ElementtypeA": "http://www.xxx.com/namespaceA", +# "ElementtypeB": "http://www.xxx.com/namespaceB", +# } +# + +try: + from generatedsnamespaces import GenerateDSNamespaceDefs as GenerateDSNamespaceDefs_ +except ImportError: + GenerateDSNamespaceDefs_ = {} + +# +# The root super-class for element type classes # # Calls to the methods in these classes are generated by generateDS.py. # You can replace these methods by re-implementing the following class @@ -724,6 +750,9 @@ class IdentifierType(GeneratedsSuper): else: return False def export(self, outfile, level, namespace_='', name_='IdentifierType', namespacedef_='', pretty_print=True): + imported_ns_def_ = GenerateDSNamespaceDefs_.get('IdentifierType') + if imported_ns_def_ is not None: + namespacedef_ = imported_ns_def_ if pretty_print: eol_ = '\n' else: @@ -847,6 +876,9 @@ class BillOfResourcesIDType(IdentifierType): else: return False def export(self, outfile, level, namespace_='', name_='BillOfResourcesIDType', namespacedef_='', pretty_print=True): + imported_ns_def_ = GenerateDSNamespaceDefs_.get('BillOfResourcesIDType') + if imported_ns_def_ is not None: + namespacedef_ = imported_ns_def_ if pretty_print: eol_ = '\n' else: @@ -916,6 +948,9 @@ class BillOfMaterialIDType(IdentifierType): else: return False def export(self, outfile, level, namespace_='', name_='BillOfMaterialIDType', namespacedef_='', pretty_print=True): + imported_ns_def_ = GenerateDSNamespaceDefs_.get('BillOfMaterialIDType') + if imported_ns_def_ is not None: + namespacedef_ = imported_ns_def_ if pretty_print: eol_ = '\n' else: diff --git a/tests/simpletype_memberspecs1_sup.py b/tests/simpletype_memberspecs1_sup.py index 1aa42644c94fb52f394ff08421ea4b8d0841198f..6d445a1e37d21be12d2a3b083fb9772a08084496 100644 --- a/tests/simpletype_memberspecs1_sup.py +++ b/tests/simpletype_memberspecs1_sup.py @@ -55,7 +55,33 @@ def parsexml_(infile, parser=None, **kwargs): return doc # -# User methods +# Namespace prefix definition table (and other attributes, too) +# +# The module generatedsnamespaces, if it is importable, must contain +# a dictionary named GeneratedsNamespaceDefs. This Python dictionary +# should map element type names (strings) to XML schema namespace prefix +# definitions. The export method for any class for which there is +# a namespace prefix definition, will export that definition in the +# XML representation of that element. See the export method of +# any generated element type class for a example of the use of this +# table. +# A sample table is: +# +# # File: generatedsnamespaces.py +# +# GenerateDSNamespaceDefs = { +# "ElementtypeA": "http://www.xxx.com/namespaceA", +# "ElementtypeB": "http://www.xxx.com/namespaceB", +# } +# + +try: + from generatedsnamespaces import GenerateDSNamespaceDefs as GenerateDSNamespaceDefs_ +except ImportError: + GenerateDSNamespaceDefs_ = {} + +# +# The root super-class for element type classes # # Calls to the methods in these classes are generated by generateDS.py. # You can replace these methods by re-implementing the following class @@ -697,6 +723,9 @@ class SpecialDate(GeneratedsSuper): else: return False def export(self, outfile, level, namespace_='pl:', name_='SpecialDate', namespacedef_='xmlns:pl="http://kuhlman.com/people.xsd"', pretty_print=True): + imported_ns_def_ = GenerateDSNamespaceDefs_.get('SpecialDate') + if imported_ns_def_ is not None: + namespacedef_ = imported_ns_def_ if pretty_print: eol_ = '\n' else: @@ -772,6 +801,9 @@ class ExtremeDate(GeneratedsSuper): else: return False def export(self, outfile, level, namespace_='pl:', name_='ExtremeDate', namespacedef_='xmlns:pl="http://kuhlman.com/people.xsd"', pretty_print=True): + imported_ns_def_ = GenerateDSNamespaceDefs_.get('ExtremeDate') + if imported_ns_def_ is not None: + namespacedef_ = imported_ns_def_ if pretty_print: eol_ = '\n' else: diff --git a/tests/simpletypes_other1_sup.py b/tests/simpletypes_other1_sup.py index 0c55d98700a4fa33ef8fff2298233c651324306d..0b60027539addbd9ac23a3fa2bb33b5c7c462ce9 100644 --- a/tests/simpletypes_other1_sup.py +++ b/tests/simpletypes_other1_sup.py @@ -55,7 +55,33 @@ def parsexml_(infile, parser=None, **kwargs): return doc # -# User methods +# Namespace prefix definition table (and other attributes, too) +# +# The module generatedsnamespaces, if it is importable, must contain +# a dictionary named GeneratedsNamespaceDefs. This Python dictionary +# should map element type names (strings) to XML schema namespace prefix +# definitions. The export method for any class for which there is +# a namespace prefix definition, will export that definition in the +# XML representation of that element. See the export method of +# any generated element type class for a example of the use of this +# table. +# A sample table is: +# +# # File: generatedsnamespaces.py +# +# GenerateDSNamespaceDefs = { +# "ElementtypeA": "http://www.xxx.com/namespaceA", +# "ElementtypeB": "http://www.xxx.com/namespaceB", +# } +# + +try: + from generatedsnamespaces import GenerateDSNamespaceDefs as GenerateDSNamespaceDefs_ +except ImportError: + GenerateDSNamespaceDefs_ = {} + +# +# The root super-class for element type classes # # Calls to the methods in these classes are generated by generateDS.py. # You can replace these methods by re-implementing the following class @@ -699,6 +725,9 @@ class simpleTypeTestsType(GeneratedsSuper): else: return False def export(self, outfile, level, namespace_='', name_='simpleTypeTestsType', namespacedef_='', pretty_print=True): + imported_ns_def_ = GenerateDSNamespaceDefs_.get('simpleTypeTestsType') + if imported_ns_def_ is not None: + namespacedef_ = imported_ns_def_ if pretty_print: eol_ = '\n' else: @@ -929,6 +958,9 @@ class simpleTypeTestDefs(GeneratedsSuper): else: return False def export(self, outfile, level, namespace_='', name_='simpleTypeTestDefs', namespacedef_='', pretty_print=True): + imported_ns_def_ = GenerateDSNamespaceDefs_.get('simpleTypeTestDefs') + if imported_ns_def_ is not None: + namespacedef_ = imported_ns_def_ if pretty_print: eol_ = '\n' else: diff --git a/tests/to_etree1_sup.py b/tests/to_etree1_sup.py index 347dcdc86a8108578bd601d9ab42638be7bad203..016d5f57c171d20409e7e8bba16a3c1e28e180cc 100644 --- a/tests/to_etree1_sup.py +++ b/tests/to_etree1_sup.py @@ -57,7 +57,33 @@ def parsexml_(infile, parser=None, **kwargs): return doc # -# User methods +# Namespace prefix definition table (and other attributes, too) +# +# The module generatedsnamespaces, if it is importable, must contain +# a dictionary named GeneratedsNamespaceDefs. This Python dictionary +# should map element type names (strings) to XML schema namespace prefix +# definitions. The export method for any class for which there is +# a namespace prefix definition, will export that definition in the +# XML representation of that element. See the export method of +# any generated element type class for a example of the use of this +# table. +# A sample table is: +# +# # File: generatedsnamespaces.py +# +# GenerateDSNamespaceDefs = { +# "ElementtypeA": "http://www.xxx.com/namespaceA", +# "ElementtypeB": "http://www.xxx.com/namespaceB", +# } +# + +try: + from generatedsnamespaces import GenerateDSNamespaceDefs as GenerateDSNamespaceDefs_ +except ImportError: + GenerateDSNamespaceDefs_ = {} + +# +# The root super-class for element type classes # # Calls to the methods in these classes are generated by generateDS.py. # You can replace these methods by re-implementing the following class diff --git a/tests/validate_simpletypes1_sup.py b/tests/validate_simpletypes1_sup.py index bef973b3a41c570091e6f53aea60261ea4194bc7..6d42d6a41d238b30f1429de5e15864dfae2e768e 100644 --- a/tests/validate_simpletypes1_sup.py +++ b/tests/validate_simpletypes1_sup.py @@ -54,7 +54,33 @@ def parsexml_(infile, parser=None, **kwargs): return doc # -# User methods +# Namespace prefix definition table (and other attributes, too) +# +# The module generatedsnamespaces, if it is importable, must contain +# a dictionary named GeneratedsNamespaceDefs. This Python dictionary +# should map element type names (strings) to XML schema namespace prefix +# definitions. The export method for any class for which there is +# a namespace prefix definition, will export that definition in the +# XML representation of that element. See the export method of +# any generated element type class for a example of the use of this +# table. +# A sample table is: +# +# # File: generatedsnamespaces.py +# +# GenerateDSNamespaceDefs = { +# "ElementtypeA": "http://www.xxx.com/namespaceA", +# "ElementtypeB": "http://www.xxx.com/namespaceB", +# } +# + +try: + from generatedsnamespaces import GenerateDSNamespaceDefs as GenerateDSNamespaceDefs_ +except ImportError: + GenerateDSNamespaceDefs_ = {} + +# +# The root super-class for element type classes # # Calls to the methods in these classes are generated by generateDS.py. # You can replace these methods by re-implementing the following class @@ -742,6 +768,9 @@ class containerType(GeneratedsSuper): else: return False def export(self, outfile, level, namespace_='', name_='containerType', namespacedef_='', pretty_print=True): + imported_ns_def_ = GenerateDSNamespaceDefs_.get('containerType') + if imported_ns_def_ is not None: + namespacedef_ = imported_ns_def_ if pretty_print: eol_ = '\n' else: @@ -1150,6 +1179,9 @@ class simpleOneType(GeneratedsSuper): else: return False def export(self, outfile, level, namespace_='', name_='simpleOneType', namespacedef_='', pretty_print=True): + imported_ns_def_ = GenerateDSNamespaceDefs_.get('simpleOneType') + if imported_ns_def_ is not None: + namespacedef_ = imported_ns_def_ if pretty_print: eol_ = '\n' else: @@ -1457,6 +1489,9 @@ class simpleTwoType(GeneratedsSuper): else: return False def export(self, outfile, level, namespace_='', name_='simpleTwoType', namespacedef_='', pretty_print=True): + imported_ns_def_ = GenerateDSNamespaceDefs_.get('simpleTwoType') + if imported_ns_def_ is not None: + namespacedef_ = imported_ns_def_ if pretty_print: eol_ = '\n' else: @@ -1539,6 +1574,9 @@ class simpleTwoElementOneType(GeneratedsSuper): else: return False def export(self, outfile, level, namespace_='', name_='simpleTwoElementOneType', namespacedef_='', pretty_print=True): + imported_ns_def_ = GenerateDSNamespaceDefs_.get('simpleTwoElementOneType') + if imported_ns_def_ is not None: + namespacedef_ = imported_ns_def_ if pretty_print: eol_ = '\n' else: diff --git a/tests/validate_simpletypes1_warnings.txt b/tests/validate_simpletypes1_warnings.txt index ff179792e61beeab9b8c8977b9c7897b1ad4064b..04097a2ba78da8d3513a4edd00c0c6c325bbe060 100644 --- a/tests/validate_simpletypes1_warnings.txt +++ b/tests/validate_simpletypes1_warnings.txt @@ -1,60 +1,60 @@ -tests/validate_simpletypes2_sup.py:993: UserWarning: Value "2" does not match xsd minExclusive restriction on integer_range_1_st +tests/validate_simpletypes2_sup.py:1022: UserWarning: Value "2" does not match xsd minExclusive restriction on integer_range_1_st warnings_.warn('Value "%(value)s" does not match xsd minExclusive restriction on integer_range_1_st' % {"value" : value} ) -tests/validate_simpletypes2_sup.py:1003: UserWarning: Value "mmaaa1234mnopzzz" does not match xsd pattern restrictions: [['^aaa.*zzz$', '^bbb.*xxx$'], ['^.*123.*$', '^.*456.*$']] +tests/validate_simpletypes2_sup.py:1032: UserWarning: Value "mmaaa1234mnopzzz" does not match xsd pattern restrictions: [['^aaa.*zzz$', '^bbb.*xxx$'], ['^.*123.*$', '^.*456.*$']] warnings_.warn('Value "%s" does not match xsd pattern restrictions: %s' % (value.encode('utf-8'), self.validate_pattern_st_patterns_, )) -tests/validate_simpletypes2_sup.py:1016: UserWarning: Value "floatxx" does not match xsd enumeration restriction on token_enum_st +tests/validate_simpletypes2_sup.py:1045: UserWarning: Value "floatxx" does not match xsd enumeration restriction on token_enum_st warnings_.warn('Value "%(value)s" does not match xsd enumeration restriction on token_enum_st' % {"value" : value.encode("utf-8")} ) -tests/validate_simpletypes2_sup.py:1023: UserWarning: Value "22" does not match xsd maxInclusive restriction on integer_range_incl_st +tests/validate_simpletypes2_sup.py:1052: UserWarning: Value "22" does not match xsd maxInclusive restriction on integer_range_incl_st warnings_.warn('Value "%(value)s" does not match xsd maxInclusive restriction on integer_range_incl_st' % {"value" : value} ) -tests/validate_simpletypes2_sup.py:1028: UserWarning: Value "-40" does not match xsd minExclusive restriction on integer_range_excl_st +tests/validate_simpletypes2_sup.py:1057: UserWarning: Value "-40" does not match xsd minExclusive restriction on integer_range_excl_st warnings_.warn('Value "%(value)s" does not match xsd minExclusive restriction on integer_range_excl_st' % {"value" : value} ) -tests/validate_simpletypes2_sup.py:1037: UserWarning: Value "mno pqr" does not match xsd minLength restriction on min_max_length_st +tests/validate_simpletypes2_sup.py:1066: UserWarning: Value "mno pqr" does not match xsd minLength restriction on min_max_length_st warnings_.warn('Value "%(value)s" does not match xsd minLength restriction on min_max_length_st' % {"value" : value.encode("utf-8")} ) -tests/validate_simpletypes2_sup.py:1042: UserWarning: Value "012345" does not match xsd length restriction on length_st +tests/validate_simpletypes2_sup.py:1071: UserWarning: Value "012345" does not match xsd length restriction on length_st warnings_.warn('Value "%(value)s" does not match xsd length restriction on length_st' % {"value" : value.encode("utf-8")} ) -tests/validate_simpletypes2_sup.py:1119: UserWarning: Value "0.2" does not match xsd minInclusive restriction on anonymous_float_valueType +tests/validate_simpletypes2_sup.py:1148: UserWarning: Value "0.2" does not match xsd minInclusive restriction on anonymous_float_valueType warnings_.warn('Value "%(value)s" does not match xsd minInclusive restriction on anonymous_float_valueType' % {"value" : value} ) -tests/validate_simpletypes2_sup.py:1113: UserWarning: Value "efgh" does not match xsd pattern restrictions: [['^abcd$|^ef\\|gh$']] +tests/validate_simpletypes2_sup.py:1142: UserWarning: Value "efgh" does not match xsd pattern restrictions: [['^abcd$|^ef\\|gh$']] warnings_.warn('Value "%s" does not match xsd pattern restrictions: %s' % (value.encode('utf-8'), self.validate_vbar_pattern_st_patterns_, )) -tests/validate_simpletypes2_sup.py:995: UserWarning: Value "9" does not match xsd maxExclusive restriction on integer_range_1_st +tests/validate_simpletypes2_sup.py:1024: UserWarning: Value "9" does not match xsd maxExclusive restriction on integer_range_1_st warnings_.warn('Value "%(value)s" does not match xsd maxExclusive restriction on integer_range_1_st' % {"value" : value} ) -tests/validate_simpletypes2_sup.py:1003: UserWarning: Value "aaa1234mnopzzzbcd" does not match xsd pattern restrictions: [['^aaa.*zzz$', '^bbb.*xxx$'], ['^.*123.*$', '^.*456.*$']] +tests/validate_simpletypes2_sup.py:1032: UserWarning: Value "aaa1234mnopzzzbcd" does not match xsd pattern restrictions: [['^aaa.*zzz$', '^bbb.*xxx$'], ['^.*123.*$', '^.*456.*$']] warnings_.warn('Value "%s" does not match xsd pattern restrictions: %s' % (value.encode('utf-8'), self.validate_pattern_st_patterns_, )) -tests/validate_simpletypes2_sup.py:1021: UserWarning: Value "-50" does not match xsd minInclusive restriction on integer_range_incl_st +tests/validate_simpletypes2_sup.py:1050: UserWarning: Value "-50" does not match xsd minInclusive restriction on integer_range_incl_st warnings_.warn('Value "%(value)s" does not match xsd minInclusive restriction on integer_range_incl_st' % {"value" : value} ) -tests/validate_simpletypes2_sup.py:1035: UserWarning: Value "asdf asdf asdf asdf asdf asdf" does not match xsd maxLength restriction on min_max_length_st +tests/validate_simpletypes2_sup.py:1064: UserWarning: Value "asdf asdf asdf asdf asdf asdf" does not match xsd maxLength restriction on min_max_length_st warnings_.warn('Value "%(value)s" does not match xsd maxLength restriction on min_max_length_st' % {"value" : value.encode("utf-8")} ) -tests/validate_simpletypes2_sup.py:1042: UserWarning: Value "01234567890" does not match xsd length restriction on length_st +tests/validate_simpletypes2_sup.py:1071: UserWarning: Value "01234567890" does not match xsd length restriction on length_st warnings_.warn('Value "%(value)s" does not match xsd length restriction on length_st' % {"value" : value.encode("utf-8")} ) -tests/validate_simpletypes2_sup.py:1052: UserWarning: Value "2015-05-01" does not match xsd minInclusive restriction on date_minincl_st +tests/validate_simpletypes2_sup.py:1081: UserWarning: Value "2015-05-01" does not match xsd minInclusive restriction on date_minincl_st warnings_.warn('Value "%(value)s" does not match xsd minInclusive restriction on date_minincl_st' % {"value" : value} ) -tests/validate_simpletypes2_sup.py:1057: UserWarning: Value "2015-11-01" does not match xsd maxInclusive restriction on date_maxincl_st +tests/validate_simpletypes2_sup.py:1086: UserWarning: Value "2015-11-01" does not match xsd maxInclusive restriction on date_maxincl_st warnings_.warn('Value "%(value)s" does not match xsd maxInclusive restriction on date_maxincl_st' % {"value" : value} ) -tests/validate_simpletypes2_sup.py:1062: UserWarning: Value "2015-05-01" does not match xsd minExclusive restriction on date_minexcl_st +tests/validate_simpletypes2_sup.py:1091: UserWarning: Value "2015-05-01" does not match xsd minExclusive restriction on date_minexcl_st warnings_.warn('Value "%(value)s" does not match xsd minExclusive restriction on date_minexcl_st' % {"value" : value} ) -tests/validate_simpletypes2_sup.py:1067: UserWarning: Value "2015-11-01" does not match xsd maxExclusive restriction on date_maxexcl_st +tests/validate_simpletypes2_sup.py:1096: UserWarning: Value "2015-11-01" does not match xsd maxExclusive restriction on date_maxexcl_st warnings_.warn('Value "%(value)s" does not match xsd maxExclusive restriction on date_maxexcl_st' % {"value" : value} ) -tests/validate_simpletypes2_sup.py:1072: UserWarning: Value "13:30:00" does not match xsd minInclusive restriction on time_minincl_st +tests/validate_simpletypes2_sup.py:1101: UserWarning: Value "13:30:00" does not match xsd minInclusive restriction on time_minincl_st warnings_.warn('Value "%(value)s" does not match xsd minInclusive restriction on time_minincl_st' % {"value" : value} ) -tests/validate_simpletypes2_sup.py:1077: UserWarning: Value "17:00:00" does not match xsd maxInclusive restriction on time_maxincl_st +tests/validate_simpletypes2_sup.py:1106: UserWarning: Value "17:00:00" does not match xsd maxInclusive restriction on time_maxincl_st warnings_.warn('Value "%(value)s" does not match xsd maxInclusive restriction on time_maxincl_st' % {"value" : value} ) -tests/validate_simpletypes2_sup.py:1082: UserWarning: Value "13:30:00" does not match xsd minExclusive restriction on time_minexcl_st +tests/validate_simpletypes2_sup.py:1111: UserWarning: Value "13:30:00" does not match xsd minExclusive restriction on time_minexcl_st warnings_.warn('Value "%(value)s" does not match xsd minExclusive restriction on time_minexcl_st' % {"value" : value} ) -tests/validate_simpletypes2_sup.py:1087: UserWarning: Value "17:00:00" does not match xsd maxExclusive restriction on time_maxexcl_st +tests/validate_simpletypes2_sup.py:1116: UserWarning: Value "17:00:00" does not match xsd maxExclusive restriction on time_maxexcl_st warnings_.warn('Value "%(value)s" does not match xsd maxExclusive restriction on time_maxexcl_st' % {"value" : value} ) -tests/validate_simpletypes2_sup.py:1092: UserWarning: Value "2015-06-01 13:20:10" does not match xsd minInclusive restriction on datetime_minincl_st +tests/validate_simpletypes2_sup.py:1121: UserWarning: Value "2015-06-01 13:20:10" does not match xsd minInclusive restriction on datetime_minincl_st warnings_.warn('Value "%(value)s" does not match xsd minInclusive restriction on datetime_minincl_st' % {"value" : value} ) -tests/validate_simpletypes2_sup.py:1097: UserWarning: Value "2015-11-01 14:20:10" does not match xsd maxInclusive restriction on datetime_maxincl_st +tests/validate_simpletypes2_sup.py:1126: UserWarning: Value "2015-11-01 14:20:10" does not match xsd maxInclusive restriction on datetime_maxincl_st warnings_.warn('Value "%(value)s" does not match xsd maxInclusive restriction on datetime_maxincl_st' % {"value" : value} ) -tests/validate_simpletypes2_sup.py:1102: UserWarning: Value "2015-06-01 13:20:10" does not match xsd minExclusive restriction on datetime_minexcl_st +tests/validate_simpletypes2_sup.py:1131: UserWarning: Value "2015-06-01 13:20:10" does not match xsd minExclusive restriction on datetime_minexcl_st warnings_.warn('Value "%(value)s" does not match xsd minExclusive restriction on datetime_minexcl_st' % {"value" : value} ) -tests/validate_simpletypes2_sup.py:1107: UserWarning: Value "2015-11-01 14:20:10" does not match xsd maxExclusive restriction on datetime_maxexcl_st +tests/validate_simpletypes2_sup.py:1136: UserWarning: Value "2015-11-01 14:20:10" does not match xsd maxExclusive restriction on datetime_maxexcl_st warnings_.warn('Value "%(value)s" does not match xsd maxExclusive restriction on datetime_maxexcl_st' % {"value" : value} ) -tests/validate_simpletypes2_sup.py:1121: UserWarning: Value "6.6" does not match xsd maxInclusive restriction on anonymous_float_valueType +tests/validate_simpletypes2_sup.py:1150: UserWarning: Value "6.6" does not match xsd maxInclusive restriction on anonymous_float_valueType warnings_.warn('Value "%(value)s" does not match xsd maxInclusive restriction on anonymous_float_valueType' % {"value" : value} ) -tests/validate_simpletypes2_sup.py:1000: UserWarning: Value "aaa12zzz" does not match xsd minLength restriction on pattern_st +tests/validate_simpletypes2_sup.py:1029: UserWarning: Value "aaa12zzz" does not match xsd minLength restriction on pattern_st warnings_.warn('Value "%(value)s" does not match xsd minLength restriction on pattern_st' % {"value" : value} ) -tests/validate_simpletypes2_sup.py:1003: UserWarning: Value "aaa12zzz" does not match xsd pattern restrictions: [['^aaa.*zzz$', '^bbb.*xxx$'], ['^.*123.*$', '^.*456.*$']] +tests/validate_simpletypes2_sup.py:1032: UserWarning: Value "aaa12zzz" does not match xsd pattern restrictions: [['^aaa.*zzz$', '^bbb.*xxx$'], ['^.*123.*$', '^.*456.*$']] warnings_.warn('Value "%s" does not match xsd pattern restrictions: %s' % (value.encode('utf-8'), self.validate_pattern_st_patterns_, )) -tests/validate_simpletypes2_sup.py:1533: UserWarning: Value "pqrst" does not match xsd minLength restriction on simpleTwoElementTwoType +tests/validate_simpletypes2_sup.py:1568: UserWarning: Value "pqrst" does not match xsd minLength restriction on simpleTwoElementTwoType warnings_.warn('Value "%(value)s" does not match xsd minLength restriction on simpleTwoElementTwoType' % {"value" : value.encode("utf-8")} ) diff --git a/tests/validate_simpletypes2_sup.py b/tests/validate_simpletypes2_sup.py index bef973b3a41c570091e6f53aea60261ea4194bc7..6d42d6a41d238b30f1429de5e15864dfae2e768e 100644 --- a/tests/validate_simpletypes2_sup.py +++ b/tests/validate_simpletypes2_sup.py @@ -54,7 +54,33 @@ def parsexml_(infile, parser=None, **kwargs): return doc # -# User methods +# Namespace prefix definition table (and other attributes, too) +# +# The module generatedsnamespaces, if it is importable, must contain +# a dictionary named GeneratedsNamespaceDefs. This Python dictionary +# should map element type names (strings) to XML schema namespace prefix +# definitions. The export method for any class for which there is +# a namespace prefix definition, will export that definition in the +# XML representation of that element. See the export method of +# any generated element type class for a example of the use of this +# table. +# A sample table is: +# +# # File: generatedsnamespaces.py +# +# GenerateDSNamespaceDefs = { +# "ElementtypeA": "http://www.xxx.com/namespaceA", +# "ElementtypeB": "http://www.xxx.com/namespaceB", +# } +# + +try: + from generatedsnamespaces import GenerateDSNamespaceDefs as GenerateDSNamespaceDefs_ +except ImportError: + GenerateDSNamespaceDefs_ = {} + +# +# The root super-class for element type classes # # Calls to the methods in these classes are generated by generateDS.py. # You can replace these methods by re-implementing the following class @@ -742,6 +768,9 @@ class containerType(GeneratedsSuper): else: return False def export(self, outfile, level, namespace_='', name_='containerType', namespacedef_='', pretty_print=True): + imported_ns_def_ = GenerateDSNamespaceDefs_.get('containerType') + if imported_ns_def_ is not None: + namespacedef_ = imported_ns_def_ if pretty_print: eol_ = '\n' else: @@ -1150,6 +1179,9 @@ class simpleOneType(GeneratedsSuper): else: return False def export(self, outfile, level, namespace_='', name_='simpleOneType', namespacedef_='', pretty_print=True): + imported_ns_def_ = GenerateDSNamespaceDefs_.get('simpleOneType') + if imported_ns_def_ is not None: + namespacedef_ = imported_ns_def_ if pretty_print: eol_ = '\n' else: @@ -1457,6 +1489,9 @@ class simpleTwoType(GeneratedsSuper): else: return False def export(self, outfile, level, namespace_='', name_='simpleTwoType', namespacedef_='', pretty_print=True): + imported_ns_def_ = GenerateDSNamespaceDefs_.get('simpleTwoType') + if imported_ns_def_ is not None: + namespacedef_ = imported_ns_def_ if pretty_print: eol_ = '\n' else: @@ -1539,6 +1574,9 @@ class simpleTwoElementOneType(GeneratedsSuper): else: return False def export(self, outfile, level, namespace_='', name_='simpleTwoElementOneType', namespacedef_='', pretty_print=True): + imported_ns_def_ = GenerateDSNamespaceDefs_.get('simpleTwoElementOneType') + if imported_ns_def_ is not None: + namespacedef_ = imported_ns_def_ if pretty_print: eol_ = '\n' else: diff --git a/tutorial/generateds_tutorial.html b/tutorial/generateds_tutorial.html index 4ee1307a50fe4dadabb3be865ec6694e242ffcd4..48cc09d54b9c3a7937b5dc19f1152d250b8e5edb 100644 --- a/tutorial/generateds_tutorial.html +++ b/tutorial/generateds_tutorial.html @@ -219,7 +219,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">revision:</th><td class="field-body">2.26a</td> +<tr class="field"><th class="field-name">revision:</th><td class="field-body">2.27a</td> </tr> </tbody> </table> @@ -228,7 +228,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">May 09, 2017</td> +<tr class="field"><th class="field-name">date:</th><td class="field-body">June 01, 2017</td> </tr> </tbody> </table> @@ -1210,7 +1210,7 @@ named <tt class="docutils literal">garden_api.py</tt>, you can create an instanc <div class="footer"> <hr class="footer" /> <a class="reference external" href="generateds_tutorial.txt">View document source</a>. -Generated on: 2017-05-09 21:57 UTC. +Generated on: 2017-06-01 16:00 UTC. Generated by <a class="reference external" href="http://docutils.sourceforge.net/">Docutils</a> from <a class="reference external" href="http://docutils.sourceforge.net/rst.html">reStructuredText</a> source. </div> diff --git a/tutorial/generateds_tutorial.txt b/tutorial/generateds_tutorial.txt index ec5b5db503d55caf53b2db5efe822caa530babf9..7bab582e533e01283dd44da712a20217daac1325 100644 --- a/tutorial/generateds_tutorial.txt +++ b/tutorial/generateds_tutorial.txt @@ -11,7 +11,7 @@ generateDS -- Introduction and Tutorial .. version -:revision: 2.26a +:revision: 2.27a .. version diff --git a/tutorial/generateds_tutorial.zip b/tutorial/generateds_tutorial.zip index 490a139bad4144c6118c1b4a99694371778130b9..6790559d1746dd3a640a3c64508389e1abded303 100644 Binary files a/tutorial/generateds_tutorial.zip and b/tutorial/generateds_tutorial.zip differ diff --git a/updateversion.py b/updateversion.py index 0ec261804c54d002002df424aabdffbf9f79f38f..1ded1394df4ea9b285e892dd80fdb96a3dbc5402 100755 --- a/updateversion.py +++ b/updateversion.py @@ -16,6 +16,7 @@ Example: # # Imports +from __future__ import print_function import sys import getopt import re @@ -71,7 +72,7 @@ def updateversion(version): for spec in REPL_SPEC: targetfilename = spec['filename'] if VERBOSE: - print 'updating: "%s"' % (targetfilename, ) + print('updating: "%s"' % (targetfilename, )) targetfile = open(targetfilename, 'r') content = targetfile.read() targetfile.close() @@ -100,7 +101,7 @@ def update1file(targetfilename, content): def replfuncmaker(version): def replfunc(matchobj): if VERBOSE: - print '(replfunc) matchobj.groups()', matchobj.groups() + print('(replfunc) matchobj.groups()', matchobj.groups()) return matchobj.group(1) + version + matchobj.group(3) return replfunc @@ -109,7 +110,7 @@ USAGE_TEXT = __doc__ def usage(): - print USAGE_TEXT + print(USAGE_TEXT) sys.exit(1) diff --git a/utils/README.txt b/utils/README.txt new file mode 100644 index 0000000000000000000000000000000000000000..56294979636aea1ffc2087ab83d2363b6c802d95 --- /dev/null +++ b/utils/README.txt @@ -0,0 +1,110 @@ +=================================== +Utility scripts for generateDS.py +=================================== + +This document provides an explanation of and instructions on the use +of several utilities that are in this subdirectory and that preform +helpful tasks related to ``generateDS.py``. + +Note that these utility scripts do not install automatically. You +can find them in the ``generateds/utirs`` directory; and you can +either copy them to some directory on your path or create a +(symbolic) link to them from some directory on your path. + + +show_schema_hierarchy.py +========================== + +XML schemas often import other schemas which import still other +schemas etc. to an arbitrary depth. If you feel it might be helpful +to learn which schemas are being imported by your schema and +recursively which schema *they* import, then this utility might be +helpful. + +Run ``python show_schema_hierarchy.py --help`` for usage notes. + + +collect_schema_locations.py +============================= + +This utility scans the top level schema and produces a JSON file +containing directives. This directives file can be used by +``batch_generate.py`` to run ``generateDS.py`` to generate a module +for each of the schema references that is extracted. + +Run ``python collect_schema_locations.py --help`` for usage notes. +There are some notes in the ``generateDS.py`` documentation. + +Here is a sample of the directives file that is produced:: + + { + "directives": [ + { + "schema": "DtsInstrumentBox.xsd", + "outfile": "DtsInstrumentBox.py", + "outsubfile": "", + "flags": "" + }, + { + "schema": "ProdmlCommon.xsd", + "outfile": "ProdmlCommon.py", + "outsubfile": "", + "flags": "-f --member-specs=list --no-namespace-defs" + }, + { + "schema": "FiberOpticalPath.xsd", + "outfile": "FiberOpticalPath.py", + "outsubfile": "", + "flags": "" + } + ] + } + + +batch_generate.py +=================== + +``batch_generate.py`` runs ``generateDS.py`` to do batch generation +of multiple modules. ``batch_generate.py`` determines which modules +to generate from which schemas by reading directives from a JSON +file. + +Run ``python batch_generate.py --help`` for usage notes. And, there +are a few notes in the ``generateDS.py`` documentation. + + +The directive file +-------------------- + +The directives file can be produced by running +``collect_schema_locations.py``, or it can be written by hand. + +You can also add command line options to the "flags" entries and can +add the name of sub-class modules to be generated to the +"outsubfile" entries. + +Comments in the directives file -- The directives file is a JSON +file, and JSON does not support comments. However, for use with +``batch_generate.py``, the input directives file can contain +comments. Any line whose first non-whitespace characters are "//" +is considered a comment and is discarded by ``batch_generate.py`` +before the remaining contents are parsed by the JSON parser. + +See the notes in this file on ``collect_schema_locations.py`` for a +sample of the directives file. + + +Options and configuration +--------------------------- + +Each of the long-name command line options (the ones preceded by +"--", excluding ``--config``) can be placed in a configuration file +and referenced with the ``--config`` command line option. Here is a +sample of a configuration file:: + + [generateds-batch] + verbose = true + command = ./generateDS.py + flags = -f --member-specs=dict + in-path = energistics/prodml/v2.0/xsd_schemas + out-path = OnePer3 diff --git a/utils/batch_generate.py b/utils/batch_generate.py new file mode 100755 index 0000000000000000000000000000000000000000..d8f955d8fd33ff59dda52af4012da50439e7d0c1 --- /dev/null +++ b/utils/batch_generate.py @@ -0,0 +1,243 @@ +#!/usr/bin/env python + +""" +usage: batch_generate.py [-h] [--config CONFIG] [-c COMMAND] [--flags FLAGS] + [--in-path IN_PATH] [--out-path OUT_PATH] [-v] + infilename + +synopsis: + read input directives from JSON file (produced by + collect_schema_locations.py) and generate python modules. + +positional arguments: + infilename input JSON file containing directives + +optional arguments: + -h, --help show this help message and exit + --config CONFIG configuration file + -c COMMAND, --command COMMAND + command. Default is "generateDS.py" + --flags FLAGS command line options for generateDS.py + --in-path IN_PATH path to the directory containing the input schemas + --out-path OUT_PATH path to a directory into which modules should be + generated + -v, --verbose Print messages during actions. + +examples: + python batch_generate.py input_directives.json + python batch_generate.py --config=name.config input_directives.json + +notes: + The configuration file (see --config) has the following form: + + [generateds] + verbose = true + command = ./generateDS.py + flags = -f --member-specs=dict + in-path = energistics/prodml/v2.0/xsd_schemas + out-path = OnePer + + The option names in this configuration file are the long command line + option names. Options entered on the command line over-ride options + in this config file. + Flags/options for generateDS.py -- These flags are passed to + generateDS.py as command line options. Precedence: (1) Flags in + the directives file override the --flags command line option to + batch_generate.py. (2) Flags in the --flags command line option + to batch_generate.py override flags in the configuration file (the + argument to --config=). +""" + + +# +# imports +from __future__ import print_function +import os +import argparse +import configparser +import subprocess +import json + + +# +# Global variables + + +# +# Private functions + +def dbg_msg(options, msg): + """Print a message if verbose is on.""" + if options.verbose: + print(msg) + + +def generate_one(directive, options): + """Generate modules for one XML schema.""" + schema_name = directive.get('schema') + outfilename = directive.get('outfile') + outsubfilename = directive.get('outsubfile') + if options.in_path: + schema_name = os.path.join(options.in_path, schema_name) + modulename = outfilename.split('.')[0] + if options.out_path: + outfilename = os.path.join(options.out_path, outfilename) + if outsubfilename: + if options.out_path: + outsubfilename = os.path.join(options.out_path, outsubfilename) + outsubfilestem = outsubfilename + outsubfilename = '--super={} -s {}'.format(modulename, outsubfilename) + else: + outsubfilename = "" + outsubfilestem = outsubfilename + flags = directive.get('flags') + if not flags: + flags = options.flags + #flags = '{} {}'.format(flags, options.flags) + cmd = '{} {} -o {} {} {}'.format( + options.command, + flags, + outfilename, + outsubfilename, + schema_name, + ) + dbg_msg(options, '\ncmd: {}'.format(cmd)) + result = subprocess.run( + cmd, + stderr=subprocess.PIPE, + stdout=subprocess.PIPE, + shell=True, + ) + dbg_msg(options, 'generated: {} {}'.format(outfilename, outsubfilestem)) + if result.stderr: + print('errors: {}'.format(result.stderr)) + if result.stdout: + print('output: {}'.format(result.stdout)) + + +def merge_options(options): + """Merge config file options and command line options. + Command line options over-ride config file options. + """ + config = configparser.ConfigParser() + config.read(options.config) + if not config.has_section('generateds-batch'): + raise RuntimeError( + 'config file missing required section "generateds-batch"') + section = config['generateds-batch'] + for key in section: + key1 = key.replace('-', '_') + if not getattr(options, key1): + setattr(options, key1, section[key]) + + +def load_json_file(infile): + """Read file. Strip out lines that begin with '//'.""" + lines = [] + for line in infile: + if not line.lstrip().startswith('//'): + lines.append(line) + content = ''.join(lines) + return content + + +# +# Exported functions +def batch_generate(infile, options): + """Generate module(s) for each line in directives file.""" + content = load_json_file(infile) + specification = json.loads(content) + directives = specification['directives'] + for directive in directives: + generate_one(directive, options) + + +def main(): + description = """\ +synopsis: + read input directives from JSON file (produced by + collect_schema_locations.py) and generate python modules. +""" + epilog = """\ +examples: + python batch_generate.py input_directives.json + python batch_generate.py --config=name.config input_directives.json + +notes: + The input directives file is a JSON file. batch_generate.py will + run generateDS.py once for each directive in this JSON file. + This directives file can be produced by + utils/collect_schema_locations.py. + The configuration file (see --config) has the following form: + + [generateds] + verbose = true + command = ./generateDS.py + flags = -f --member-specs=dict + in-path = energistics/prodml/v2.0/xsd_schemas + out-path = OnePer + + The option names in this configuration file are the long command line + option names. Options entered on the command line over-ride options + in this config file. + Flags/options for generateDS.py -- These flags are passed to + generateDS.py as command line options. Precedence: (1) Flags in + the directives file override the --flags command line option to + batch_generate.py. (2) Flags in the --flags command line option + to batch_generate.py override flags in the configuration file (the + argument to --config=). + The input directives file can contain comments. Any line whose first + non-whitespace characters are "//" is considered a comment and is + discarded before the remaining contents are parsed by the JSON parser. +""" + parser = argparse.ArgumentParser( + description=description, + epilog=epilog, + formatter_class=argparse.RawDescriptionHelpFormatter, + ) + parser.add_argument( + "infilename", + help="input JSON file containing directives", + ) + parser.add_argument( + "--config", + help="configuration file", + ) + parser.add_argument( + "-c", "--command", + #default="generateDS.py", + help="command. Default is \"generateDS.py\"", + ) + parser.add_argument( + "--flags", + help="command line options for generateDS.py", + ) + parser.add_argument( + "--in-path", + help="path to the directory containing the input schemas", + ) + parser.add_argument( + "--out-path", + help="path to a directory into which modules should be generated", + ) + parser.add_argument( + "-v", "--verbose", + action="store_true", + help="Print messages during actions.", + ) + options = parser.parse_args() + if options.config: + merge_options(options) + if not options.command: + options.command = 'generateDS.py' + if not options.flags: + options.flags = '' + dbg_msg(options, '\noptions: {}'.format(options)) + infile = open(options.infilename, 'r') + batch_generate(infile, options) + + +if __name__ == '__main__': + #import pdb; pdb.set_trace() + #import ipdb; ipdb.set_trace() + main() diff --git a/utils/collect_schema_locations.py b/utils/collect_schema_locations.py new file mode 100755 index 0000000000000000000000000000000000000000..228410dbbf3caaf3560e09cae3ba05082982c8bf --- /dev/null +++ b/utils/collect_schema_locations.py @@ -0,0 +1,155 @@ +#!/usr/bin/env python + +""" +usage: collect_schema_locations.py [-h] [-f] [-v] infilename [outfilename] + +synopsis: + collect schema locations from xs:include/xs:import elements in schema. + +positional arguments: + infilename name/location of the XML schema file to be searched + outfilename output file name; if ommited stdout + +optional arguments: + -h, --help show this help message and exit + -f, --force force overwrite existing output file + -v, --verbose print messages during actions. + +examples: + python collect_schema_locations.py myschema.xsd + python collect_schema_locations.py myschema.xsd outfile.txt +""" + + +# +# imports +from __future__ import print_function +import sys +import os +import argparse +import json +from lxml import etree + + +# +# Global variables + + +# +# Private functions + +def dbg_msg(options, msg): + """Print a message if verbose is on.""" + if options.verbose: + print(msg) + + +def extract_locations(infile, options): + doc = etree.parse(infile) + root = doc.getroot() + elements = root.xpath( + './/xs:include', + namespaces=root.nsmap, + ) + locations = [] + for element in elements: + schema_name = element.get('schemaLocation') + locations.append(schema_name) + return locations + + +def generate(locations, outfile, options): + directives = [] + for location in locations: + schema_name = location + outfilename = os.path.split(schema_name)[1] + outfilename = os.path.splitext(outfilename)[0] + outfilename = '{}.py'.format(outfilename) + directive = { + 'schema': schema_name, + 'outfile': outfilename, + 'outsubfile': '', + 'flags': '', + } + directives.append(directive) + return directives + + +def make_output_file(outfilename, options): + if os.path.exists(outfilename) and not options.force: + sys.exit("\noutput file exists. Use -f/--force to over-write.\n") + outfile = open(outfilename, 'w') + return outfile + + +# +# Exported functions + +def extract_and_generate(infile, outfile, options): + locations = extract_locations(infile, options) + directives = generate(locations, outfile, options) + specification = { + 'directives': directives, + } + json.dump(specification, outfile, indent=' ') + + +def main(): + description = """\ +synopsis: + collect schema locations from xs:include/xs:import elements in schema. +""" + epilog = """\ +examples: + python collect_schema_locations.py myschema.xsd + python collect_schema_locations.py myschema.xsd outfile.txt + +notes: + The output directives file is a JSON file suitable for input to + utils/batch_generate.py. This directives file contains one directive + for each module to be generated by generateDS.py. + You can edit this resulting JSON file, for example to add a sub-class + module file or flags/options for generateDS.py that are specific + to each directive. +""" + parser = argparse.ArgumentParser( + description=description, + epilog=epilog, + formatter_class=argparse.RawDescriptionHelpFormatter, + ) + parser.add_argument( + "infilename", + help="name/location of the XML schema file to be searched" + ) + parser.add_argument( + "outfilename", + nargs="?", + default=None, + help="output file name; if ommited stdout" + ) + parser.add_argument( + "-f", "--force", + action="store_true", + help="force overwrite existing output file", + ) + parser.add_argument( + "-v", "--verbose", + action="store_true", + help="print messages during actions.", + ) + options = parser.parse_args() + infile = open(options.infilename, 'r') + if options.outfilename: + outfile = make_output_file(options.outfilename, options) + else: + outfile = sys.stdout + extract_and_generate(infile, outfile, options) + infile.close() + if options.outfilename: + outfile.close() + + +if __name__ == '__main__': + #import pdb; pdb.set_trace() + #import ipdb; ipdb.set_trace() + main() diff --git a/utils/show_schema_hierarchy.py b/utils/show_schema_hierarchy.py new file mode 100755 index 0000000000000000000000000000000000000000..83afb971678fddd39a50bf3a064c77bc21aadb0d --- /dev/null +++ b/utils/show_schema_hierarchy.py @@ -0,0 +1,138 @@ +#!/usr/bin/env python + +""" +usage: show_schema_hierarchy.py [-h] [-i INDENT] [--eliminate-branch-dups] + [--show-loop-references] [-v] + inschema + +synopsis: + show an indented schema hierarchy of xs:include/xs:import. + +positional arguments: + inschema The input (root) schema + +optional arguments: + -h, --help show this help message and exit + -i INDENT, --indent INDENT + Indent string. default: " " (4 spaces) + --eliminate-branch-dups + Eliminate (ignore) duplicate references even when + previously seen in other branches + --show-loop-references + Show references that would cause loops + -v, --verbose Print messages during actions. + +examples: + python show_schema_hierarchy.py root_schema.xsd +""" + + +# +# imports +from __future__ import print_function +#import sys +import argparse +from lxml import etree + + +# +# Global variables + + +# +# Private functions + +def dbg_msg(options, msg): + """Print a message if verbose is on.""" + if options.verbose: + print(msg) + + +# +# Exported functions + + +def show_hierarchy(inschema, path, indent, namespaces, previous, options): + if not inschema.startswith('http') and path: + inschemaloc = '{}/{}'.format(path, inschema) + else: + inschemaloc = inschema + if inschema in previous: + if options.show_loop_references: + print('{}*loop* -- {}'.format(indent, inschemaloc)) + #print('{} *previous* -- {}'.format(indent, previous)) + return + previous.add(inschema) + print('{}{} -- {}'.format(indent, inschema, inschemaloc)) + doc = etree.parse(inschemaloc) + root = doc.getroot() + elements = root.xpath('./xs:include', namespaces=namespaces) + elements += root.xpath('./xs:import', namespaces=namespaces) + indent1 = indent + options.indent + if inschema.startswith('http'): + stem = inschema.split('/')[-1] + ln = 0 - (len(stem) + 1) + path = inschema[:ln] + for element in elements: + location = element.get('schemaLocation') + if options.eliminate_branch_dups: + previous1 = previous + else: + previous1 = previous.copy() + show_hierarchy(location, path, indent1, namespaces, previous1, options) + + +def main(): + description = """\ +synopsis: + show an indented schema hierarchy of schema documents that are + pulled in by xs:include and xs:import. +""" + epilog = """\ +examples: + python show_schema_hierarchy.py root_schema.xsd + python show_schema_hierarchy.py -v --show-loop-references root_schema.xsd +""" + parser = argparse.ArgumentParser( + description=description, + epilog=epilog, + formatter_class=argparse.RawDescriptionHelpFormatter, + ) + parser.add_argument( + "inschema", + help="the input (root) schema", + ) + parser.add_argument( + "-i", "--indent", + default=" ", + help='indent string. default is 4 spaces', + ) + parser.add_argument( + "--eliminate-branch-dups", + action="store_true", + help="eliminate (ignore) duplicate references even when previously " + "seen in other branches", + ) + parser.add_argument( + "--show-loop-references", + action="store_true", + help="show references that would cause loops" + ) + parser.add_argument( + "-v", "--verbose", + action="store_true", + help="print additional messages during actions.", + ) + options = parser.parse_args() + parent = '' + indent = '' + namespaces = {'xs': 'http://www.w3.org/2001/XMLSchema'} + previous = set() + show_hierarchy( + options.inschema, parent, indent, namespaces, previous, options) + + +if __name__ == '__main__': + #import pdb; pdb.set_trace() + #import ipdb; ipdb.set_trace() + main()