From b67aa2b41247991e361dec0963670b4e5108410a Mon Sep 17 00:00:00 2001 From: Trygve Laugstøl Date: Fri, 15 Mar 2019 07:58:06 +0100 Subject: o Merging XSD files into one. --- src/ee/xml/bomFile.py | 1917 ------------------------------------- src/ee/xml/bom_file_utils.py | 23 +- src/ee/xml/indexFile.py | 1101 --------------------- src/ee/xml/types.py | 2161 ++++++++++++++++++++++++++++++++++++++++++ 4 files changed, 2170 insertions(+), 3032 deletions(-) delete mode 100644 src/ee/xml/bomFile.py delete mode 100644 src/ee/xml/indexFile.py create mode 100644 src/ee/xml/types.py (limited to 'src/ee/xml') diff --git a/src/ee/xml/bomFile.py b/src/ee/xml/bomFile.py deleted file mode 100644 index 0557a6c..0000000 --- a/src/ee/xml/bomFile.py +++ /dev/null @@ -1,1917 +0,0 @@ -#!/usr/bin/env python -# -*- coding: utf-8 -*- - -# -# Generated by generateDS.py. -# Python 3.7.2+ (default, Feb 27 2019, 15:41:59) [GCC 8.2.0] -# -# Command line options: -# ('-f', '') -# ('--no-dates', '') -# ('--no-versions', '') -# ('--output-directory', 'src/ee/xml') -# ('-o', 'src/ee/xml/bomFile.py') -# ('-m', '') -# -# Command line arguments: -# xsd/ee-bom.xsd -# -# Command line: -# env/bin/generateDS.py -f --no-dates --no-versions --output-directory="src/ee/xml" -o "src/ee/xml/bomFile.py" -m xsd/ee-bom.xsd -# -# Current working directory (os.getcwd()): -# ee-python -# - -import sys -import re as re_ -import base64 -import datetime as datetime_ -import warnings as warnings_ -try: - from lxml import etree as etree_ -except ImportError: - from xml.etree import ElementTree as etree_ - - -Validate_simpletypes_ = True -if sys.version_info.major == 2: - BaseStrType_ = basestring -else: - BaseStrType_ = str - - -def parsexml_(infile, parser=None, **kwargs): - if parser is None: - # Use the lxml ElementTree compatible parser so that, e.g., - # we ignore comments. - try: - parser = etree_.ETCompatXMLParser() - except AttributeError: - # fallback to xml.etree - parser = etree_.XMLParser() - doc = etree_.parse(infile, parser=parser, **kwargs) - return doc - -def parsexmlstring_(instring, parser=None, **kwargs): - if parser is None: - # Use the lxml ElementTree compatible parser so that, e.g., - # we ignore comments. - try: - parser = etree_.ETCompatXMLParser() - except AttributeError: - # fallback to xml.etree - parser = etree_.XMLParser() - element = etree_.fromstring(instring, parser=parser, **kwargs) - return element - -# -# 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 -# in a module named generatedssuper.py. - -try: - from generatedssuper import GeneratedsSuper -except ImportError as exp: - - class GeneratedsSuper(object): - tzoff_pattern = re_.compile(r'(\+|-)((0\d|1[0-3]):[0-5]\d|14:00)$') - class _FixedOffsetTZ(datetime_.tzinfo): - def __init__(self, offset, name): - self.__offset = datetime_.timedelta(minutes=offset) - self.__name = name - def utcoffset(self, dt): - return self.__offset - def tzname(self, dt): - return self.__name - def dst(self, dt): - return None - def gds_format_string(self, input_data, input_name=''): - return input_data - def gds_validate_string(self, input_data, node=None, input_name=''): - if not input_data: - return '' - else: - return input_data - def gds_format_base64(self, input_data, input_name=''): - return base64.b64encode(input_data) - def gds_validate_base64(self, input_data, node=None, input_name=''): - return input_data - def gds_format_integer(self, input_data, input_name=''): - return '%d' % input_data - def gds_validate_integer(self, input_data, node=None, input_name=''): - return input_data - def gds_format_integer_list(self, input_data, input_name=''): - return '%s' % ' '.join(input_data) - def gds_validate_integer_list( - self, input_data, node=None, input_name=''): - values = input_data.split() - for value in values: - try: - int(value) - except (TypeError, ValueError): - raise_parse_error(node, 'Requires sequence of integers') - return values - def gds_format_float(self, input_data, input_name=''): - return ('%.15f' % input_data).rstrip('0') - def gds_validate_float(self, input_data, node=None, input_name=''): - return input_data - def gds_format_float_list(self, input_data, input_name=''): - return '%s' % ' '.join(input_data) - def gds_validate_float_list( - self, input_data, node=None, input_name=''): - values = input_data.split() - for value in values: - try: - float(value) - except (TypeError, ValueError): - raise_parse_error(node, 'Requires sequence of floats') - return values - def gds_format_double(self, input_data, input_name=''): - return '%e' % input_data - def gds_validate_double(self, input_data, node=None, input_name=''): - return input_data - def gds_format_double_list(self, input_data, input_name=''): - return '%s' % ' '.join(input_data) - def gds_validate_double_list( - self, input_data, node=None, input_name=''): - values = input_data.split() - for value in values: - try: - float(value) - except (TypeError, ValueError): - raise_parse_error(node, 'Requires sequence of doubles') - return values - def gds_format_boolean(self, input_data, input_name=''): - return ('%s' % input_data).lower() - def gds_validate_boolean(self, input_data, node=None, input_name=''): - return input_data - def gds_format_boolean_list(self, input_data, input_name=''): - return '%s' % ' '.join(input_data) - def gds_validate_boolean_list( - self, input_data, node=None, input_name=''): - values = input_data.split() - for value in values: - if value not in ('true', '1', 'false', '0', ): - raise_parse_error( - node, - 'Requires sequence of booleans ' - '("true", "1", "false", "0")') - return values - def gds_validate_datetime(self, input_data, node=None, input_name=''): - return input_data - def gds_format_datetime(self, input_data, input_name=''): - if input_data.microsecond == 0: - _svalue = '%04d-%02d-%02dT%02d:%02d:%02d' % ( - input_data.year, - input_data.month, - input_data.day, - input_data.hour, - input_data.minute, - input_data.second, - ) - else: - _svalue = '%04d-%02d-%02dT%02d:%02d:%02d.%s' % ( - input_data.year, - input_data.month, - input_data.day, - input_data.hour, - input_data.minute, - input_data.second, - ('%f' % (float(input_data.microsecond) / 1000000))[2:], - ) - if input_data.tzinfo is not None: - tzoff = input_data.tzinfo.utcoffset(input_data) - if tzoff is not None: - total_seconds = tzoff.seconds + (86400 * tzoff.days) - if total_seconds == 0: - _svalue += 'Z' - else: - if total_seconds < 0: - _svalue += '-' - total_seconds *= -1 - else: - _svalue += '+' - hours = total_seconds // 3600 - minutes = (total_seconds - (hours * 3600)) // 60 - _svalue += '{0:02d}:{1:02d}'.format(hours, minutes) - return _svalue - @classmethod - def gds_parse_datetime(cls, input_data): - tz = None - if input_data[-1] == 'Z': - tz = GeneratedsSuper._FixedOffsetTZ(0, 'UTC') - input_data = input_data[:-1] - else: - results = GeneratedsSuper.tzoff_pattern.search(input_data) - if results is not None: - tzoff_parts = results.group(2).split(':') - tzoff = int(tzoff_parts[0]) * 60 + int(tzoff_parts[1]) - if results.group(1) == '-': - tzoff *= -1 - tz = GeneratedsSuper._FixedOffsetTZ( - tzoff, results.group(0)) - input_data = input_data[:-6] - time_parts = input_data.split('.') - if len(time_parts) > 1: - micro_seconds = int(float('0.' + time_parts[1]) * 1000000) - input_data = '%s.%s' % ( - time_parts[0], "{}".format(micro_seconds).rjust(6, "0"), ) - dt = datetime_.datetime.strptime( - input_data, '%Y-%m-%dT%H:%M:%S.%f') - else: - dt = datetime_.datetime.strptime( - input_data, '%Y-%m-%dT%H:%M:%S') - dt = dt.replace(tzinfo=tz) - return dt - def gds_validate_date(self, input_data, node=None, input_name=''): - return input_data - def gds_format_date(self, input_data, input_name=''): - _svalue = '%04d-%02d-%02d' % ( - input_data.year, - input_data.month, - input_data.day, - ) - try: - if input_data.tzinfo is not None: - tzoff = input_data.tzinfo.utcoffset(input_data) - if tzoff is not None: - total_seconds = tzoff.seconds + (86400 * tzoff.days) - if total_seconds == 0: - _svalue += 'Z' - else: - if total_seconds < 0: - _svalue += '-' - total_seconds *= -1 - else: - _svalue += '+' - hours = total_seconds // 3600 - minutes = (total_seconds - (hours * 3600)) // 60 - _svalue += '{0:02d}:{1:02d}'.format( - hours, minutes) - except AttributeError: - pass - return _svalue - @classmethod - def gds_parse_date(cls, input_data): - tz = None - if input_data[-1] == 'Z': - tz = GeneratedsSuper._FixedOffsetTZ(0, 'UTC') - input_data = input_data[:-1] - else: - results = GeneratedsSuper.tzoff_pattern.search(input_data) - if results is not None: - tzoff_parts = results.group(2).split(':') - tzoff = int(tzoff_parts[0]) * 60 + int(tzoff_parts[1]) - if results.group(1) == '-': - tzoff *= -1 - tz = GeneratedsSuper._FixedOffsetTZ( - tzoff, results.group(0)) - input_data = input_data[:-6] - dt = datetime_.datetime.strptime(input_data, '%Y-%m-%d') - dt = dt.replace(tzinfo=tz) - return dt.date() - def gds_validate_time(self, input_data, node=None, input_name=''): - return input_data - def gds_format_time(self, input_data, input_name=''): - if input_data.microsecond == 0: - _svalue = '%02d:%02d:%02d' % ( - input_data.hour, - input_data.minute, - input_data.second, - ) - else: - _svalue = '%02d:%02d:%02d.%s' % ( - input_data.hour, - input_data.minute, - input_data.second, - ('%f' % (float(input_data.microsecond) / 1000000))[2:], - ) - if input_data.tzinfo is not None: - tzoff = input_data.tzinfo.utcoffset(input_data) - if tzoff is not None: - total_seconds = tzoff.seconds + (86400 * tzoff.days) - if total_seconds == 0: - _svalue += 'Z' - else: - if total_seconds < 0: - _svalue += '-' - total_seconds *= -1 - else: - _svalue += '+' - hours = total_seconds // 3600 - minutes = (total_seconds - (hours * 3600)) // 60 - _svalue += '{0:02d}:{1:02d}'.format(hours, minutes) - return _svalue - def gds_validate_simple_patterns(self, patterns, target): - # pat is a list of lists of strings/patterns. - # The target value must match at least one of the patterns - # in order for the test to succeed. - found1 = True - for patterns1 in patterns: - found2 = False - for patterns2 in patterns1: - mo = re_.search(patterns2, target) - if mo is not None and len(mo.group(0)) == len(target): - found2 = True - break - if not found2: - found1 = False - break - return found1 - @classmethod - def gds_parse_time(cls, input_data): - tz = None - if input_data[-1] == 'Z': - tz = GeneratedsSuper._FixedOffsetTZ(0, 'UTC') - input_data = input_data[:-1] - else: - results = GeneratedsSuper.tzoff_pattern.search(input_data) - if results is not None: - tzoff_parts = results.group(2).split(':') - tzoff = int(tzoff_parts[0]) * 60 + int(tzoff_parts[1]) - if results.group(1) == '-': - tzoff *= -1 - tz = GeneratedsSuper._FixedOffsetTZ( - tzoff, results.group(0)) - input_data = input_data[:-6] - if len(input_data.split('.')) > 1: - dt = datetime_.datetime.strptime(input_data, '%H:%M:%S.%f') - else: - dt = datetime_.datetime.strptime(input_data, '%H:%M:%S') - dt = dt.replace(tzinfo=tz) - return dt.time() - def gds_str_lower(self, instring): - return instring.lower() - def get_path_(self, node): - path_list = [] - self.get_path_list_(node, path_list) - path_list.reverse() - path = '/'.join(path_list) - return path - Tag_strip_pattern_ = re_.compile(r'\{.*\}') - def get_path_list_(self, node, path_list): - if node is None: - return - tag = GeneratedsSuper.Tag_strip_pattern_.sub('', node.tag) - if tag: - path_list.append(tag) - self.get_path_list_(node.getparent(), path_list) - def get_class_obj_(self, node, default_class=None): - class_obj1 = default_class - if 'xsi' in node.nsmap: - classname = node.get('{%s}type' % node.nsmap['xsi']) - if classname is not None: - names = classname.split(':') - if len(names) == 2: - classname = names[1] - class_obj2 = globals().get(classname) - if class_obj2 is not None: - class_obj1 = class_obj2 - return class_obj1 - def gds_build_any(self, node, type_name=None): - return None - @classmethod - def gds_reverse_node_mapping(cls, mapping): - return dict(((v, k) for k, v in mapping.items())) - @staticmethod - def gds_encode(instring): - if sys.version_info.major == 2: - if ExternalEncoding: - encoding = ExternalEncoding - else: - encoding = 'utf-8' - return instring.encode(encoding) - else: - return instring - @staticmethod - def convert_unicode(instring): - if isinstance(instring, str): - result = quote_xml(instring) - elif sys.version_info.major == 2 and isinstance(instring, unicode): - result = quote_xml(instring).encode('utf8') - else: - result = GeneratedsSuper.gds_encode(str(instring)) - return result - def __eq__(self, other): - if type(self) != type(other): - return False - return self.__dict__ == other.__dict__ - def __ne__(self, other): - return not self.__eq__(other) - - def getSubclassFromModule_(module, class_): - '''Get the subclass of a class from a specific module.''' - name = class_.__name__ + 'Sub' - if hasattr(module, name): - return getattr(module, name) - else: - return None - - -# -# If you have installed IPython you can uncomment and use the following. -# IPython is available from http://ipython.scipy.org/. -# - -## from IPython.Shell import IPShellEmbed -## args = '' -## ipshell = IPShellEmbed(args, -## banner = 'Dropping into IPython', -## exit_msg = 'Leaving Interpreter, back to program.') - -# Then use the following line where and when you want to drop into the -# IPython shell: -# ipshell(' -- Entering ipshell.\nHit Ctrl-D to exit') - -# -# Globals -# - -ExternalEncoding = '' -Tag_pattern_ = re_.compile(r'({.*})?(.*)') -String_cleanup_pat_ = re_.compile(r"[\n\r\s]+") -Namespace_extract_pat_ = re_.compile(r'{(.*)}(.*)') -CDATA_pattern_ = re_.compile(r"", re_.DOTALL) - -# Change this to redirect the generated superclass module to use a -# specific subclass module. -CurrentSubclassModule_ = None - -# -# Support/utility functions. -# - - -def showIndent(outfile, level, pretty_print=True): - if pretty_print: - for idx in range(level): - outfile.write(' ') - - -def quote_xml(inStr): - "Escape markup chars, but do not modify CDATA sections." - if not inStr: - return '' - s1 = (isinstance(inStr, BaseStrType_) and inStr or '%s' % inStr) - s2 = '' - pos = 0 - matchobjects = CDATA_pattern_.finditer(s1) - for mo in matchobjects: - s3 = s1[pos:mo.start()] - s2 += quote_xml_aux(s3) - s2 += s1[mo.start():mo.end()] - pos = mo.end() - s3 = s1[pos:] - s2 += quote_xml_aux(s3) - return s2 - - -def quote_xml_aux(inStr): - s1 = inStr.replace('&', '&') - s1 = s1.replace('<', '<') - s1 = s1.replace('>', '>') - return s1 - - -def quote_attrib(inStr): - s1 = (isinstance(inStr, BaseStrType_) and inStr or '%s' % inStr) - s1 = s1.replace('&', '&') - s1 = s1.replace('<', '<') - s1 = s1.replace('>', '>') - if '"' in s1: - if "'" in s1: - s1 = '"%s"' % s1.replace('"', """) - else: - s1 = "'%s'" % s1 - else: - s1 = '"%s"' % s1 - return s1 - - -def quote_python(inStr): - s1 = inStr - if s1.find("'") == -1: - if s1.find('\n') == -1: - return "'%s'" % s1 - else: - return "'''%s'''" % s1 - else: - if s1.find('"') != -1: - s1 = s1.replace('"', '\\"') - if s1.find('\n') == -1: - return '"%s"' % s1 - else: - return '"""%s"""' % s1 - - -def get_all_text_(node): - if node.text is not None: - text = node.text - else: - text = '' - for child in node: - if child.tail is not None: - text += child.tail - return text - - -def find_attr_value_(attr_name, node): - attrs = node.attrib - attr_parts = attr_name.split(':') - value = None - if len(attr_parts) == 1: - value = attrs.get(attr_name) - elif len(attr_parts) == 2: - prefix, name = attr_parts - namespace = node.nsmap.get(prefix) - if namespace is not None: - value = attrs.get('{%s}%s' % (namespace, name, )) - return value - - -class GDSParseError(Exception): - pass - - -def raise_parse_error(node, msg): - msg = '%s (element %s/line %d)' % (msg, node.tag, node.sourceline, ) - raise GDSParseError(msg) - - -class MixedContainer: - # Constants for category: - CategoryNone = 0 - CategoryText = 1 - CategorySimple = 2 - CategoryComplex = 3 - # Constants for content_type: - TypeNone = 0 - TypeText = 1 - TypeString = 2 - TypeInteger = 3 - TypeFloat = 4 - TypeDecimal = 5 - TypeDouble = 6 - TypeBoolean = 7 - TypeBase64 = 8 - def __init__(self, category, content_type, name, value): - self.category = category - self.content_type = content_type - self.name = name - self.value = value - def getCategory(self): - return self.category - def getContenttype(self, content_type): - return self.content_type - def getValue(self): - return self.value - def getName(self): - return self.name - def export(self, outfile, level, name, namespace, - pretty_print=True): - if self.category == MixedContainer.CategoryText: - # Prevent exporting empty content as empty lines. - if self.value.strip(): - outfile.write(self.value) - elif self.category == MixedContainer.CategorySimple: - self.exportSimple(outfile, level, name) - else: # category == MixedContainer.CategoryComplex - self.value.export( - outfile, level, namespace, name_=name, - pretty_print=pretty_print) - def exportSimple(self, outfile, level, name): - if self.content_type == MixedContainer.TypeString: - outfile.write('<%s>%s' % ( - self.name, self.value, self.name)) - elif self.content_type == MixedContainer.TypeInteger or \ - self.content_type == MixedContainer.TypeBoolean: - outfile.write('<%s>%d' % ( - self.name, self.value, self.name)) - elif self.content_type == MixedContainer.TypeFloat or \ - self.content_type == MixedContainer.TypeDecimal: - outfile.write('<%s>%f' % ( - self.name, self.value, self.name)) - elif self.content_type == MixedContainer.TypeDouble: - outfile.write('<%s>%g' % ( - self.name, self.value, self.name)) - elif self.content_type == MixedContainer.TypeBase64: - outfile.write('<%s>%s' % ( - self.name, - base64.b64encode(self.value), - self.name)) - def to_etree(self, element): - if self.category == MixedContainer.CategoryText: - # Prevent exporting empty content as empty lines. - if self.value.strip(): - if len(element) > 0: - if element[-1].tail is None: - element[-1].tail = self.value - else: - element[-1].tail += self.value - else: - if element.text is None: - element.text = self.value - else: - element.text += self.value - elif self.category == MixedContainer.CategorySimple: - subelement = etree_.SubElement( - element, '%s' % self.name) - subelement.text = self.to_etree_simple() - else: # category == MixedContainer.CategoryComplex - self.value.to_etree(element) - def to_etree_simple(self): - if self.content_type == MixedContainer.TypeString: - text = self.value - elif (self.content_type == MixedContainer.TypeInteger or - self.content_type == MixedContainer.TypeBoolean): - text = '%d' % self.value - elif (self.content_type == MixedContainer.TypeFloat or - self.content_type == MixedContainer.TypeDecimal): - text = '%f' % self.value - elif self.content_type == MixedContainer.TypeDouble: - text = '%g' % self.value - elif self.content_type == MixedContainer.TypeBase64: - text = '%s' % base64.b64encode(self.value) - return text - def exportLiteral(self, outfile, level, name): - if self.category == MixedContainer.CategoryText: - showIndent(outfile, level) - outfile.write( - 'model_.MixedContainer(%d, %d, "%s", "%s"),\n' % ( - self.category, self.content_type, - self.name, self.value)) - elif self.category == MixedContainer.CategorySimple: - showIndent(outfile, level) - outfile.write( - 'model_.MixedContainer(%d, %d, "%s", "%s"),\n' % ( - self.category, self.content_type, - self.name, self.value)) - else: # category == MixedContainer.CategoryComplex - showIndent(outfile, level) - outfile.write( - 'model_.MixedContainer(%d, %d, "%s",\n' % ( - self.category, self.content_type, self.name,)) - self.value.exportLiteral(outfile, level + 1) - showIndent(outfile, level) - outfile.write(')\n') - - -class MemberSpec_(object): - def __init__(self, name='', data_type='', container=0, - optional=0, child_attrs=None, choice=None): - self.name = name - self.data_type = data_type - self.container = container - self.child_attrs = child_attrs - self.choice = choice - self.optional = optional - def set_name(self, name): self.name = name - def get_name(self): return self.name - def set_data_type(self, data_type): self.data_type = data_type - def get_data_type_chain(self): return self.data_type - def get_data_type(self): - if isinstance(self.data_type, list): - if len(self.data_type) > 0: - return self.data_type[-1] - else: - return 'xs:string' - else: - return self.data_type - def set_container(self, container): self.container = container - def get_container(self): return self.container - def set_child_attrs(self, child_attrs): self.child_attrs = child_attrs - def get_child_attrs(self): return self.child_attrs - def set_choice(self, choice): self.choice = choice - def get_choice(self): return self.choice - def set_optional(self, optional): self.optional = optional - def get_optional(self): return self.optional - - -def _cast(typ, value): - if typ is None or value is None: - return value - return typ(value) - -# -# Data representation classes. -# - - -class BomFile(GeneratedsSuper): - subclass = None - superclass = None - def __init__(self, parts=None, **kwargs_): - self.original_tagname_ = None - self.parent_object_ = kwargs_.get('parent_object_') - self.parts = parts - def factory(*args_, **kwargs_): - if CurrentSubclassModule_ is not None: - subclass = getSubclassFromModule_( - CurrentSubclassModule_, BomFile) - if subclass is not None: - return subclass(*args_, **kwargs_) - if BomFile.subclass: - return BomFile.subclass(*args_, **kwargs_) - else: - return BomFile(*args_, **kwargs_) - factory = staticmethod(factory) - def get_parts(self): - return self.parts - def set_parts(self, parts): - self.parts = parts - partsProp = property(get_parts, set_parts) - def hasContent_(self): - if ( - self.parts is not None - ): - return True - else: - return False - def export(self, outfile, level, namespaceprefix_='', namespacedef_='', name_='BomFile', pretty_print=True): - imported_ns_def_ = GenerateDSNamespaceDefs_.get('BomFile') - if imported_ns_def_ is not None: - namespacedef_ = imported_ns_def_ - if pretty_print: - eol_ = '\n' - else: - eol_ = '' - if self.original_tagname_ is not None: - name_ = self.original_tagname_ - showIndent(outfile, level, pretty_print) - outfile.write('<%s%s%s' % (namespaceprefix_, name_, namespacedef_ and ' ' + namespacedef_ or '', )) - already_processed = set() - self.exportAttributes(outfile, level, already_processed, namespaceprefix_, name_='BomFile') - if self.hasContent_(): - outfile.write('>%s' % (eol_, )) - self.exportChildren(outfile, level + 1, namespaceprefix_, namespacedef_, name_='BomFile', pretty_print=pretty_print) - showIndent(outfile, level, pretty_print) - outfile.write('%s' % (namespaceprefix_, name_, eol_)) - else: - outfile.write('/>%s' % (eol_, )) - def exportAttributes(self, outfile, level, already_processed, namespaceprefix_='', name_='BomFile'): - pass - def exportChildren(self, outfile, level, namespaceprefix_='', namespacedef_='', name_='BomFile', fromsubclass_=False, pretty_print=True): - if pretty_print: - eol_ = '\n' - else: - eol_ = '' - if self.parts is not None: - self.parts.export(outfile, level, namespaceprefix_, namespacedef_='', name_='parts', pretty_print=pretty_print) - def build(self, node): - already_processed = set() - self.buildAttributes(node, node.attrib, already_processed) - for child in node: - nodeName_ = Tag_pattern_.match(child.tag).groups()[-1] - self.buildChildren(child, node, nodeName_) - return self - def buildAttributes(self, node, attrs, already_processed): - pass - def buildChildren(self, child_, node, nodeName_, fromsubclass_=False): - if nodeName_ == 'parts': - obj_ = PartList.factory(parent_object_=self) - obj_.build(child_) - self.parts = obj_ - obj_.original_tagname_ = 'parts' -# end class BomFile - - -class Part(GeneratedsSuper): - subclass = None - superclass = None - def __init__(self, id=None, schema_reference=None, part_type=None, part_numbers=None, distributor_info=None, facts=None, price_breaks=None, **kwargs_): - self.original_tagname_ = None - self.parent_object_ = kwargs_.get('parent_object_') - self.id = _cast(None, id) - self.schema_reference = schema_reference - self.part_type = part_type - self.part_numbers = part_numbers - self.distributor_info = distributor_info - self.facts = facts - self.price_breaks = price_breaks - def factory(*args_, **kwargs_): - if CurrentSubclassModule_ is not None: - subclass = getSubclassFromModule_( - CurrentSubclassModule_, Part) - if subclass is not None: - return subclass(*args_, **kwargs_) - if Part.subclass: - return Part.subclass(*args_, **kwargs_) - else: - return Part(*args_, **kwargs_) - factory = staticmethod(factory) - def get_schema_reference(self): - return self.schema_reference - def set_schema_reference(self, schema_reference): - self.schema_reference = schema_reference - schema_referenceProp = property(get_schema_reference, set_schema_reference) - def get_part_type(self): - return self.part_type - def set_part_type(self, part_type): - self.part_type = part_type - part_typeProp = property(get_part_type, set_part_type) - def get_part_numbers(self): - return self.part_numbers - def set_part_numbers(self, part_numbers): - self.part_numbers = part_numbers - part_numbersProp = property(get_part_numbers, set_part_numbers) - def get_distributor_info(self): - return self.distributor_info - def set_distributor_info(self, distributor_info): - self.distributor_info = distributor_info - distributor_infoProp = property(get_distributor_info, set_distributor_info) - def get_facts(self): - return self.facts - def set_facts(self, facts): - self.facts = facts - factsProp = property(get_facts, set_facts) - def get_price_breaks(self): - return self.price_breaks - def set_price_breaks(self, price_breaks): - self.price_breaks = price_breaks - price_breaksProp = property(get_price_breaks, set_price_breaks) - def get_id(self): - return self.id - def set_id(self, id): - self.id = id - idProp = property(get_id, set_id) - def hasContent_(self): - if ( - self.schema_reference is not None or - self.part_type is not None or - self.part_numbers is not None or - self.distributor_info is not None or - self.facts is not None or - self.price_breaks is not None - ): - return True - else: - return False - def export(self, outfile, level, namespaceprefix_='', namespacedef_='', name_='Part', pretty_print=True): - imported_ns_def_ = GenerateDSNamespaceDefs_.get('Part') - if imported_ns_def_ is not None: - namespacedef_ = imported_ns_def_ - if pretty_print: - eol_ = '\n' - else: - eol_ = '' - if self.original_tagname_ is not None: - name_ = self.original_tagname_ - showIndent(outfile, level, pretty_print) - outfile.write('<%s%s%s' % (namespaceprefix_, name_, namespacedef_ and ' ' + namespacedef_ or '', )) - already_processed = set() - self.exportAttributes(outfile, level, already_processed, namespaceprefix_, name_='Part') - if self.hasContent_(): - outfile.write('>%s' % (eol_, )) - self.exportChildren(outfile, level + 1, namespaceprefix_, namespacedef_, name_='Part', pretty_print=pretty_print) - showIndent(outfile, level, pretty_print) - outfile.write('%s' % (namespaceprefix_, name_, eol_)) - else: - outfile.write('/>%s' % (eol_, )) - def exportAttributes(self, outfile, level, already_processed, namespaceprefix_='', name_='Part'): - if self.id is not None and 'id' not in already_processed: - already_processed.add('id') - outfile.write(' id=%s' % (self.gds_encode(self.gds_format_string(quote_attrib(self.id), input_name='id')), )) - def exportChildren(self, outfile, level, namespaceprefix_='', namespacedef_='', name_='Part', fromsubclass_=False, pretty_print=True): - if pretty_print: - eol_ = '\n' - else: - eol_ = '' - if self.schema_reference is not None: - showIndent(outfile, level, pretty_print) - outfile.write('<%sschema-reference>%s%s' % (namespaceprefix_ , self.gds_encode(self.gds_format_string(quote_xml(self.schema_reference), input_name='schema-reference')), namespaceprefix_ , eol_)) - if self.part_type is not None: - showIndent(outfile, level, pretty_print) - outfile.write('<%spart-type>%s%s' % (namespaceprefix_ , self.gds_encode(self.gds_format_string(quote_xml(self.part_type), input_name='part-type')), namespaceprefix_ , eol_)) - if self.part_numbers is not None: - self.part_numbers.export(outfile, level, namespaceprefix_, namespacedef_='', name_='part-numbers', pretty_print=pretty_print) - if self.distributor_info is not None: - self.distributor_info.export(outfile, level, namespaceprefix_, namespacedef_='', name_='distributor-info', pretty_print=pretty_print) - if self.facts is not None: - self.facts.export(outfile, level, namespaceprefix_, namespacedef_='', name_='facts', pretty_print=pretty_print) - if self.price_breaks is not None: - self.price_breaks.export(outfile, level, namespaceprefix_, namespacedef_='', name_='price-breaks', pretty_print=pretty_print) - def build(self, node): - already_processed = set() - self.buildAttributes(node, node.attrib, already_processed) - for child in node: - nodeName_ = Tag_pattern_.match(child.tag).groups()[-1] - self.buildChildren(child, node, nodeName_) - return self - def buildAttributes(self, node, attrs, already_processed): - value = find_attr_value_('id', node) - if value is not None and 'id' not in already_processed: - already_processed.add('id') - self.id = value - def buildChildren(self, child_, node, nodeName_, fromsubclass_=False): - if nodeName_ == 'schema-reference': - schema_reference_ = child_.text - schema_reference_ = self.gds_validate_string(schema_reference_, node, 'schema_reference') - self.schema_reference = schema_reference_ - elif nodeName_ == 'part-type': - part_type_ = child_.text - part_type_ = self.gds_validate_string(part_type_, node, 'part_type') - self.part_type = part_type_ - elif nodeName_ == 'part-numbers': - obj_ = PartNumberList.factory(parent_object_=self) - obj_.build(child_) - self.part_numbers = obj_ - obj_.original_tagname_ = 'part-numbers' - elif nodeName_ == 'distributor-info': - obj_ = DistributorInfo.factory(parent_object_=self) - obj_.build(child_) - self.distributor_info = obj_ - obj_.original_tagname_ = 'distributor-info' - elif nodeName_ == 'facts': - obj_ = FactList.factory(parent_object_=self) - obj_.build(child_) - self.facts = obj_ - obj_.original_tagname_ = 'facts' - elif nodeName_ == 'price-breaks': - obj_ = PriceBreakList.factory(parent_object_=self) - obj_.build(child_) - self.price_breaks = obj_ - obj_.original_tagname_ = 'price-breaks' -# end class Part - - -class PartList(GeneratedsSuper): - subclass = None - superclass = None - def __init__(self, part=None, **kwargs_): - self.original_tagname_ = None - self.parent_object_ = kwargs_.get('parent_object_') - if part is None: - self.part = [] - else: - self.part = part - def factory(*args_, **kwargs_): - if CurrentSubclassModule_ is not None: - subclass = getSubclassFromModule_( - CurrentSubclassModule_, PartList) - if subclass is not None: - return subclass(*args_, **kwargs_) - if PartList.subclass: - return PartList.subclass(*args_, **kwargs_) - else: - return PartList(*args_, **kwargs_) - factory = staticmethod(factory) - def get_part(self): - return self.part - def set_part(self, part): - self.part = part - def add_part(self, value): - self.part.append(value) - def add_part(self, value): - self.part.append(value) - def insert_part_at(self, index, value): - self.part.insert(index, value) - def replace_part_at(self, index, value): - self.part[index] = value - partProp = property(get_part, set_part) - def hasContent_(self): - if ( - self.part - ): - return True - else: - return False - def export(self, outfile, level, namespaceprefix_='', namespacedef_='', name_='PartList', pretty_print=True): - imported_ns_def_ = GenerateDSNamespaceDefs_.get('PartList') - if imported_ns_def_ is not None: - namespacedef_ = imported_ns_def_ - if pretty_print: - eol_ = '\n' - else: - eol_ = '' - if self.original_tagname_ is not None: - name_ = self.original_tagname_ - showIndent(outfile, level, pretty_print) - outfile.write('<%s%s%s' % (namespaceprefix_, name_, namespacedef_ and ' ' + namespacedef_ or '', )) - already_processed = set() - self.exportAttributes(outfile, level, already_processed, namespaceprefix_, name_='PartList') - if self.hasContent_(): - outfile.write('>%s' % (eol_, )) - self.exportChildren(outfile, level + 1, namespaceprefix_, namespacedef_, name_='PartList', pretty_print=pretty_print) - showIndent(outfile, level, pretty_print) - outfile.write('%s' % (namespaceprefix_, name_, eol_)) - else: - outfile.write('/>%s' % (eol_, )) - def exportAttributes(self, outfile, level, already_processed, namespaceprefix_='', name_='PartList'): - pass - def exportChildren(self, outfile, level, namespaceprefix_='', namespacedef_='', name_='PartList', fromsubclass_=False, pretty_print=True): - if pretty_print: - eol_ = '\n' - else: - eol_ = '' - for part_ in self.part: - part_.export(outfile, level, namespaceprefix_, namespacedef_='', name_='part', pretty_print=pretty_print) - def build(self, node): - already_processed = set() - self.buildAttributes(node, node.attrib, already_processed) - for child in node: - nodeName_ = Tag_pattern_.match(child.tag).groups()[-1] - self.buildChildren(child, node, nodeName_) - return self - def buildAttributes(self, node, attrs, already_processed): - pass - def buildChildren(self, child_, node, nodeName_, fromsubclass_=False): - if nodeName_ == 'part': - obj_ = Part.factory(parent_object_=self) - obj_.build(child_) - self.part.append(obj_) - obj_.original_tagname_ = 'part' -# end class PartList - - -class PartNumber(GeneratedsSuper): - subclass = None - superclass = None - def __init__(self, value=None, distributor=None, **kwargs_): - self.original_tagname_ = None - self.parent_object_ = kwargs_.get('parent_object_') - self.value = value - self.distributor = distributor - def factory(*args_, **kwargs_): - if CurrentSubclassModule_ is not None: - subclass = getSubclassFromModule_( - CurrentSubclassModule_, PartNumber) - if subclass is not None: - return subclass(*args_, **kwargs_) - if PartNumber.subclass: - return PartNumber.subclass(*args_, **kwargs_) - else: - return PartNumber(*args_, **kwargs_) - factory = staticmethod(factory) - def get_value(self): - return self.value - def set_value(self, value): - self.value = value - valueProp = property(get_value, set_value) - def get_distributor(self): - return self.distributor - def set_distributor(self, distributor): - self.distributor = distributor - distributorProp = property(get_distributor, set_distributor) - def hasContent_(self): - if ( - self.value is not None or - self.distributor is not None - ): - return True - else: - return False - def export(self, outfile, level, namespaceprefix_='', namespacedef_='', name_='PartNumber', pretty_print=True): - imported_ns_def_ = GenerateDSNamespaceDefs_.get('PartNumber') - if imported_ns_def_ is not None: - namespacedef_ = imported_ns_def_ - if pretty_print: - eol_ = '\n' - else: - eol_ = '' - if self.original_tagname_ is not None: - name_ = self.original_tagname_ - showIndent(outfile, level, pretty_print) - outfile.write('<%s%s%s' % (namespaceprefix_, name_, namespacedef_ and ' ' + namespacedef_ or '', )) - already_processed = set() - self.exportAttributes(outfile, level, already_processed, namespaceprefix_, name_='PartNumber') - if self.hasContent_(): - outfile.write('>%s' % (eol_, )) - self.exportChildren(outfile, level + 1, namespaceprefix_, namespacedef_, name_='PartNumber', pretty_print=pretty_print) - showIndent(outfile, level, pretty_print) - outfile.write('%s' % (namespaceprefix_, name_, eol_)) - else: - outfile.write('/>%s' % (eol_, )) - def exportAttributes(self, outfile, level, already_processed, namespaceprefix_='', name_='PartNumber'): - pass - def exportChildren(self, outfile, level, namespaceprefix_='', namespacedef_='', name_='PartNumber', fromsubclass_=False, pretty_print=True): - if pretty_print: - eol_ = '\n' - else: - eol_ = '' - if self.value is not None: - showIndent(outfile, level, pretty_print) - outfile.write('<%svalue>%s%s' % (namespaceprefix_ , self.gds_encode(self.gds_format_string(quote_xml(self.value), input_name='value')), namespaceprefix_ , eol_)) - if self.distributor is not None: - showIndent(outfile, level, pretty_print) - outfile.write('<%sdistributor>%s%s' % (namespaceprefix_ , self.gds_encode(self.gds_format_string(quote_xml(self.distributor), input_name='distributor')), namespaceprefix_ , eol_)) - def build(self, node): - already_processed = set() - self.buildAttributes(node, node.attrib, already_processed) - for child in node: - nodeName_ = Tag_pattern_.match(child.tag).groups()[-1] - self.buildChildren(child, node, nodeName_) - return self - def buildAttributes(self, node, attrs, already_processed): - pass - def buildChildren(self, child_, node, nodeName_, fromsubclass_=False): - if nodeName_ == 'value': - value_ = child_.text - value_ = self.gds_validate_string(value_, node, 'value') - self.value = value_ - elif nodeName_ == 'distributor': - distributor_ = child_.text - distributor_ = self.gds_validate_string(distributor_, node, 'distributor') - self.distributor = distributor_ -# end class PartNumber - - -class PartNumberList(GeneratedsSuper): - subclass = None - superclass = None - def __init__(self, part_number=None, **kwargs_): - self.original_tagname_ = None - self.parent_object_ = kwargs_.get('parent_object_') - if part_number is None: - self.part_number = [] - else: - self.part_number = part_number - def factory(*args_, **kwargs_): - if CurrentSubclassModule_ is not None: - subclass = getSubclassFromModule_( - CurrentSubclassModule_, PartNumberList) - if subclass is not None: - return subclass(*args_, **kwargs_) - if PartNumberList.subclass: - return PartNumberList.subclass(*args_, **kwargs_) - else: - return PartNumberList(*args_, **kwargs_) - factory = staticmethod(factory) - def get_part_number(self): - return self.part_number - def set_part_number(self, part_number): - self.part_number = part_number - def add_part_number(self, value): - self.part_number.append(value) - def add_part_number(self, value): - self.part_number.append(value) - def insert_part_number_at(self, index, value): - self.part_number.insert(index, value) - def replace_part_number_at(self, index, value): - self.part_number[index] = value - part_numberProp = property(get_part_number, set_part_number) - def hasContent_(self): - if ( - self.part_number - ): - return True - else: - return False - def export(self, outfile, level, namespaceprefix_='', namespacedef_='', name_='PartNumberList', pretty_print=True): - imported_ns_def_ = GenerateDSNamespaceDefs_.get('PartNumberList') - if imported_ns_def_ is not None: - namespacedef_ = imported_ns_def_ - if pretty_print: - eol_ = '\n' - else: - eol_ = '' - if self.original_tagname_ is not None: - name_ = self.original_tagname_ - showIndent(outfile, level, pretty_print) - outfile.write('<%s%s%s' % (namespaceprefix_, name_, namespacedef_ and ' ' + namespacedef_ or '', )) - already_processed = set() - self.exportAttributes(outfile, level, already_processed, namespaceprefix_, name_='PartNumberList') - if self.hasContent_(): - outfile.write('>%s' % (eol_, )) - self.exportChildren(outfile, level + 1, namespaceprefix_, namespacedef_, name_='PartNumberList', pretty_print=pretty_print) - showIndent(outfile, level, pretty_print) - outfile.write('%s' % (namespaceprefix_, name_, eol_)) - else: - outfile.write('/>%s' % (eol_, )) - def exportAttributes(self, outfile, level, already_processed, namespaceprefix_='', name_='PartNumberList'): - pass - def exportChildren(self, outfile, level, namespaceprefix_='', namespacedef_='', name_='PartNumberList', fromsubclass_=False, pretty_print=True): - if pretty_print: - eol_ = '\n' - else: - eol_ = '' - for part_number_ in self.part_number: - part_number_.export(outfile, level, namespaceprefix_, namespacedef_='', name_='part-number', pretty_print=pretty_print) - def build(self, node): - already_processed = set() - self.buildAttributes(node, node.attrib, already_processed) - for child in node: - nodeName_ = Tag_pattern_.match(child.tag).groups()[-1] - self.buildChildren(child, node, nodeName_) - return self - def buildAttributes(self, node, attrs, already_processed): - pass - def buildChildren(self, child_, node, nodeName_, fromsubclass_=False): - if nodeName_ == 'part-number': - obj_ = PartNumber.factory(parent_object_=self) - obj_.build(child_) - self.part_number.append(obj_) - obj_.original_tagname_ = 'part-number' -# end class PartNumberList - - -class Fact(GeneratedsSuper): - subclass = None - superclass = None - def __init__(self, key=None, label=None, value=None, **kwargs_): - self.original_tagname_ = None - self.parent_object_ = kwargs_.get('parent_object_') - self.key = key - self.label = label - self.value = value - def factory(*args_, **kwargs_): - if CurrentSubclassModule_ is not None: - subclass = getSubclassFromModule_( - CurrentSubclassModule_, Fact) - if subclass is not None: - return subclass(*args_, **kwargs_) - if Fact.subclass: - return Fact.subclass(*args_, **kwargs_) - else: - return Fact(*args_, **kwargs_) - factory = staticmethod(factory) - def get_key(self): - return self.key - def set_key(self, key): - self.key = key - keyProp = property(get_key, set_key) - def get_label(self): - return self.label - def set_label(self, label): - self.label = label - labelProp = property(get_label, set_label) - def get_value(self): - return self.value - def set_value(self, value): - self.value = value - valueProp = property(get_value, set_value) - def hasContent_(self): - if ( - self.key is not None or - self.label is not None or - self.value is not None - ): - return True - else: - return False - def export(self, outfile, level, namespaceprefix_='', namespacedef_='', name_='Fact', pretty_print=True): - imported_ns_def_ = GenerateDSNamespaceDefs_.get('Fact') - if imported_ns_def_ is not None: - namespacedef_ = imported_ns_def_ - if pretty_print: - eol_ = '\n' - else: - eol_ = '' - if self.original_tagname_ is not None: - name_ = self.original_tagname_ - showIndent(outfile, level, pretty_print) - outfile.write('<%s%s%s' % (namespaceprefix_, name_, namespacedef_ and ' ' + namespacedef_ or '', )) - already_processed = set() - self.exportAttributes(outfile, level, already_processed, namespaceprefix_, name_='Fact') - if self.hasContent_(): - outfile.write('>%s' % (eol_, )) - self.exportChildren(outfile, level + 1, namespaceprefix_, namespacedef_, name_='Fact', pretty_print=pretty_print) - showIndent(outfile, level, pretty_print) - outfile.write('%s' % (namespaceprefix_, name_, eol_)) - else: - outfile.write('/>%s' % (eol_, )) - def exportAttributes(self, outfile, level, already_processed, namespaceprefix_='', name_='Fact'): - pass - def exportChildren(self, outfile, level, namespaceprefix_='', namespacedef_='', name_='Fact', fromsubclass_=False, pretty_print=True): - if pretty_print: - eol_ = '\n' - else: - eol_ = '' - if self.key is not None: - showIndent(outfile, level, pretty_print) - outfile.write('<%skey>%s%s' % (namespaceprefix_ , self.gds_encode(self.gds_format_string(quote_xml(self.key), input_name='key')), namespaceprefix_ , eol_)) - if self.label is not None: - showIndent(outfile, level, pretty_print) - outfile.write('<%slabel>%s%s' % (namespaceprefix_ , self.gds_encode(self.gds_format_string(quote_xml(self.label), input_name='label')), namespaceprefix_ , eol_)) - if self.value is not None: - showIndent(outfile, level, pretty_print) - outfile.write('<%svalue>%s%s' % (namespaceprefix_ , self.gds_encode(self.gds_format_string(quote_xml(self.value), input_name='value')), namespaceprefix_ , eol_)) - def build(self, node): - already_processed = set() - self.buildAttributes(node, node.attrib, already_processed) - for child in node: - nodeName_ = Tag_pattern_.match(child.tag).groups()[-1] - self.buildChildren(child, node, nodeName_) - return self - def buildAttributes(self, node, attrs, already_processed): - pass - def buildChildren(self, child_, node, nodeName_, fromsubclass_=False): - if nodeName_ == 'key': - key_ = child_.text - key_ = self.gds_validate_string(key_, node, 'key') - self.key = key_ - elif nodeName_ == 'label': - label_ = child_.text - label_ = self.gds_validate_string(label_, node, 'label') - self.label = label_ - elif nodeName_ == 'value': - value_ = child_.text - value_ = self.gds_validate_string(value_, node, 'value') - self.value = value_ -# end class Fact - - -class FactList(GeneratedsSuper): - subclass = None - superclass = None - def __init__(self, fact=None, **kwargs_): - self.original_tagname_ = None - self.parent_object_ = kwargs_.get('parent_object_') - if fact is None: - self.fact = [] - else: - self.fact = fact - def factory(*args_, **kwargs_): - if CurrentSubclassModule_ is not None: - subclass = getSubclassFromModule_( - CurrentSubclassModule_, FactList) - if subclass is not None: - return subclass(*args_, **kwargs_) - if FactList.subclass: - return FactList.subclass(*args_, **kwargs_) - else: - return FactList(*args_, **kwargs_) - factory = staticmethod(factory) - def get_fact(self): - return self.fact - def set_fact(self, fact): - self.fact = fact - def add_fact(self, value): - self.fact.append(value) - def add_fact(self, value): - self.fact.append(value) - def insert_fact_at(self, index, value): - self.fact.insert(index, value) - def replace_fact_at(self, index, value): - self.fact[index] = value - factProp = property(get_fact, set_fact) - def hasContent_(self): - if ( - self.fact - ): - return True - else: - return False - def export(self, outfile, level, namespaceprefix_='', namespacedef_='', name_='FactList', pretty_print=True): - imported_ns_def_ = GenerateDSNamespaceDefs_.get('FactList') - if imported_ns_def_ is not None: - namespacedef_ = imported_ns_def_ - if pretty_print: - eol_ = '\n' - else: - eol_ = '' - if self.original_tagname_ is not None: - name_ = self.original_tagname_ - showIndent(outfile, level, pretty_print) - outfile.write('<%s%s%s' % (namespaceprefix_, name_, namespacedef_ and ' ' + namespacedef_ or '', )) - already_processed = set() - self.exportAttributes(outfile, level, already_processed, namespaceprefix_, name_='FactList') - if self.hasContent_(): - outfile.write('>%s' % (eol_, )) - self.exportChildren(outfile, level + 1, namespaceprefix_, namespacedef_, name_='FactList', pretty_print=pretty_print) - showIndent(outfile, level, pretty_print) - outfile.write('%s' % (namespaceprefix_, name_, eol_)) - else: - outfile.write('/>%s' % (eol_, )) - def exportAttributes(self, outfile, level, already_processed, namespaceprefix_='', name_='FactList'): - pass - def exportChildren(self, outfile, level, namespaceprefix_='', namespacedef_='', name_='FactList', fromsubclass_=False, pretty_print=True): - if pretty_print: - eol_ = '\n' - else: - eol_ = '' - for fact_ in self.fact: - fact_.export(outfile, level, namespaceprefix_, namespacedef_='', name_='fact', pretty_print=pretty_print) - def build(self, node): - already_processed = set() - self.buildAttributes(node, node.attrib, already_processed) - for child in node: - nodeName_ = Tag_pattern_.match(child.tag).groups()[-1] - self.buildChildren(child, node, nodeName_) - return self - def buildAttributes(self, node, attrs, already_processed): - pass - def buildChildren(self, child_, node, nodeName_, fromsubclass_=False): - if nodeName_ == 'fact': - obj_ = Fact.factory(parent_object_=self) - obj_.build(child_) - self.fact.append(obj_) - obj_.original_tagname_ = 'fact' -# end class FactList - - -class DistributorInfo(GeneratedsSuper): - subclass = None - superclass = None - def __init__(self, state=None, **kwargs_): - self.original_tagname_ = None - self.parent_object_ = kwargs_.get('parent_object_') - self.state = state - def factory(*args_, **kwargs_): - if CurrentSubclassModule_ is not None: - subclass = getSubclassFromModule_( - CurrentSubclassModule_, DistributorInfo) - if subclass is not None: - return subclass(*args_, **kwargs_) - if DistributorInfo.subclass: - return DistributorInfo.subclass(*args_, **kwargs_) - else: - return DistributorInfo(*args_, **kwargs_) - factory = staticmethod(factory) - def get_state(self): - return self.state - def set_state(self, state): - self.state = state - stateProp = property(get_state, set_state) - def hasContent_(self): - if ( - self.state is not None - ): - return True - else: - return False - def export(self, outfile, level, namespaceprefix_='', namespacedef_='', name_='DistributorInfo', pretty_print=True): - imported_ns_def_ = GenerateDSNamespaceDefs_.get('DistributorInfo') - if imported_ns_def_ is not None: - namespacedef_ = imported_ns_def_ - if pretty_print: - eol_ = '\n' - else: - eol_ = '' - if self.original_tagname_ is not None: - name_ = self.original_tagname_ - showIndent(outfile, level, pretty_print) - outfile.write('<%s%s%s' % (namespaceprefix_, name_, namespacedef_ and ' ' + namespacedef_ or '', )) - already_processed = set() - self.exportAttributes(outfile, level, already_processed, namespaceprefix_, name_='DistributorInfo') - if self.hasContent_(): - outfile.write('>%s' % (eol_, )) - self.exportChildren(outfile, level + 1, namespaceprefix_, namespacedef_, name_='DistributorInfo', pretty_print=pretty_print) - showIndent(outfile, level, pretty_print) - outfile.write('%s' % (namespaceprefix_, name_, eol_)) - else: - outfile.write('/>%s' % (eol_, )) - def exportAttributes(self, outfile, level, already_processed, namespaceprefix_='', name_='DistributorInfo'): - pass - def exportChildren(self, outfile, level, namespaceprefix_='', namespacedef_='', name_='DistributorInfo', fromsubclass_=False, pretty_print=True): - if pretty_print: - eol_ = '\n' - else: - eol_ = '' - if self.state is not None: - showIndent(outfile, level, pretty_print) - outfile.write('<%sstate>%s%s' % (namespaceprefix_ , self.gds_encode(self.gds_format_string(quote_xml(self.state), input_name='state')), namespaceprefix_ , eol_)) - def build(self, node): - already_processed = set() - self.buildAttributes(node, node.attrib, already_processed) - for child in node: - nodeName_ = Tag_pattern_.match(child.tag).groups()[-1] - self.buildChildren(child, node, nodeName_) - return self - def buildAttributes(self, node, attrs, already_processed): - pass - def buildChildren(self, child_, node, nodeName_, fromsubclass_=False): - if nodeName_ == 'state': - state_ = child_.text - state_ = self.gds_validate_string(state_, node, 'state') - self.state = state_ -# end class DistributorInfo - - -class Amount(GeneratedsSuper): - subclass = None - superclass = None - def __init__(self, value=None, currency=None, **kwargs_): - self.original_tagname_ = None - self.parent_object_ = kwargs_.get('parent_object_') - self.value = _cast(None, value) - self.currency = _cast(None, currency) - def factory(*args_, **kwargs_): - if CurrentSubclassModule_ is not None: - subclass = getSubclassFromModule_( - CurrentSubclassModule_, Amount) - if subclass is not None: - return subclass(*args_, **kwargs_) - if Amount.subclass: - return Amount.subclass(*args_, **kwargs_) - else: - return Amount(*args_, **kwargs_) - factory = staticmethod(factory) - def get_value(self): - return self.value - def set_value(self, value): - self.value = value - valueProp = property(get_value, set_value) - def get_currency(self): - return self.currency - def set_currency(self, currency): - self.currency = currency - currencyProp = property(get_currency, set_currency) - def hasContent_(self): - if ( - - ): - return True - else: - return False - def export(self, outfile, level, namespaceprefix_='', namespacedef_='', name_='Amount', pretty_print=True): - imported_ns_def_ = GenerateDSNamespaceDefs_.get('Amount') - if imported_ns_def_ is not None: - namespacedef_ = imported_ns_def_ - if pretty_print: - eol_ = '\n' - else: - eol_ = '' - if self.original_tagname_ is not None: - name_ = self.original_tagname_ - showIndent(outfile, level, pretty_print) - outfile.write('<%s%s%s' % (namespaceprefix_, name_, namespacedef_ and ' ' + namespacedef_ or '', )) - already_processed = set() - self.exportAttributes(outfile, level, already_processed, namespaceprefix_, name_='Amount') - if self.hasContent_(): - outfile.write('>%s' % (eol_, )) - self.exportChildren(outfile, level + 1, namespaceprefix_, namespacedef_, name_='Amount', pretty_print=pretty_print) - outfile.write('%s' % (namespaceprefix_, name_, eol_)) - else: - outfile.write('/>%s' % (eol_, )) - def exportAttributes(self, outfile, level, already_processed, namespaceprefix_='', name_='Amount'): - if self.value is not None and 'value' not in already_processed: - already_processed.add('value') - outfile.write(' value=%s' % (self.gds_encode(self.gds_format_string(quote_attrib(self.value), input_name='value')), )) - if self.currency is not None and 'currency' not in already_processed: - already_processed.add('currency') - outfile.write(' currency=%s' % (self.gds_encode(self.gds_format_string(quote_attrib(self.currency), input_name='currency')), )) - def exportChildren(self, outfile, level, namespaceprefix_='', namespacedef_='', name_='Amount', fromsubclass_=False, pretty_print=True): - pass - def build(self, node): - already_processed = set() - self.buildAttributes(node, node.attrib, already_processed) - for child in node: - nodeName_ = Tag_pattern_.match(child.tag).groups()[-1] - self.buildChildren(child, node, nodeName_) - return self - def buildAttributes(self, node, attrs, already_processed): - value = find_attr_value_('value', node) - if value is not None and 'value' not in already_processed: - already_processed.add('value') - self.value = value - value = find_attr_value_('currency', node) - if value is not None and 'currency' not in already_processed: - already_processed.add('currency') - self.currency = value - def buildChildren(self, child_, node, nodeName_, fromsubclass_=False): - pass -# end class Amount - - -class PriceBreak(GeneratedsSuper): - subclass = None - superclass = None - def __init__(self, quantity=None, amount=None, **kwargs_): - self.original_tagname_ = None - self.parent_object_ = kwargs_.get('parent_object_') - self.quantity = quantity - self.amount = amount - def factory(*args_, **kwargs_): - if CurrentSubclassModule_ is not None: - subclass = getSubclassFromModule_( - CurrentSubclassModule_, PriceBreak) - if subclass is not None: - return subclass(*args_, **kwargs_) - if PriceBreak.subclass: - return PriceBreak.subclass(*args_, **kwargs_) - else: - return PriceBreak(*args_, **kwargs_) - factory = staticmethod(factory) - def get_quantity(self): - return self.quantity - def set_quantity(self, quantity): - self.quantity = quantity - quantityProp = property(get_quantity, set_quantity) - def get_amount(self): - return self.amount - def set_amount(self, amount): - self.amount = amount - amountProp = property(get_amount, set_amount) - def hasContent_(self): - if ( - self.quantity is not None or - self.amount is not None - ): - return True - else: - return False - def export(self, outfile, level, namespaceprefix_='', namespacedef_='', name_='PriceBreak', pretty_print=True): - imported_ns_def_ = GenerateDSNamespaceDefs_.get('PriceBreak') - if imported_ns_def_ is not None: - namespacedef_ = imported_ns_def_ - if pretty_print: - eol_ = '\n' - else: - eol_ = '' - if self.original_tagname_ is not None: - name_ = self.original_tagname_ - showIndent(outfile, level, pretty_print) - outfile.write('<%s%s%s' % (namespaceprefix_, name_, namespacedef_ and ' ' + namespacedef_ or '', )) - already_processed = set() - self.exportAttributes(outfile, level, already_processed, namespaceprefix_, name_='PriceBreak') - if self.hasContent_(): - outfile.write('>%s' % (eol_, )) - self.exportChildren(outfile, level + 1, namespaceprefix_, namespacedef_, name_='PriceBreak', pretty_print=pretty_print) - showIndent(outfile, level, pretty_print) - outfile.write('%s' % (namespaceprefix_, name_, eol_)) - else: - outfile.write('/>%s' % (eol_, )) - def exportAttributes(self, outfile, level, already_processed, namespaceprefix_='', name_='PriceBreak'): - pass - def exportChildren(self, outfile, level, namespaceprefix_='', namespacedef_='', name_='PriceBreak', fromsubclass_=False, pretty_print=True): - if pretty_print: - eol_ = '\n' - else: - eol_ = '' - if self.quantity is not None: - showIndent(outfile, level, pretty_print) - outfile.write('<%squantity>%s%s' % (namespaceprefix_ , self.gds_encode(self.gds_format_string(quote_xml(self.quantity), input_name='quantity')), namespaceprefix_ , eol_)) - if self.amount is not None: - self.amount.export(outfile, level, namespaceprefix_, namespacedef_='', name_='amount', pretty_print=pretty_print) - def build(self, node): - already_processed = set() - self.buildAttributes(node, node.attrib, already_processed) - for child in node: - nodeName_ = Tag_pattern_.match(child.tag).groups()[-1] - self.buildChildren(child, node, nodeName_) - return self - def buildAttributes(self, node, attrs, already_processed): - pass - def buildChildren(self, child_, node, nodeName_, fromsubclass_=False): - if nodeName_ == 'quantity': - quantity_ = child_.text - quantity_ = self.gds_validate_string(quantity_, node, 'quantity') - self.quantity = quantity_ - elif nodeName_ == 'amount': - obj_ = Amount.factory(parent_object_=self) - obj_.build(child_) - self.amount = obj_ - obj_.original_tagname_ = 'amount' -# end class PriceBreak - - -class PriceBreakList(GeneratedsSuper): - subclass = None - superclass = None - def __init__(self, price_break=None, **kwargs_): - self.original_tagname_ = None - self.parent_object_ = kwargs_.get('parent_object_') - if price_break is None: - self.price_break = [] - else: - self.price_break = price_break - def factory(*args_, **kwargs_): - if CurrentSubclassModule_ is not None: - subclass = getSubclassFromModule_( - CurrentSubclassModule_, PriceBreakList) - if subclass is not None: - return subclass(*args_, **kwargs_) - if PriceBreakList.subclass: - return PriceBreakList.subclass(*args_, **kwargs_) - else: - return PriceBreakList(*args_, **kwargs_) - factory = staticmethod(factory) - def get_price_break(self): - return self.price_break - def set_price_break(self, price_break): - self.price_break = price_break - def add_price_break(self, value): - self.price_break.append(value) - def add_price_break(self, value): - self.price_break.append(value) - def insert_price_break_at(self, index, value): - self.price_break.insert(index, value) - def replace_price_break_at(self, index, value): - self.price_break[index] = value - price_breakProp = property(get_price_break, set_price_break) - def hasContent_(self): - if ( - self.price_break - ): - return True - else: - return False - def export(self, outfile, level, namespaceprefix_='', namespacedef_='', name_='PriceBreakList', pretty_print=True): - imported_ns_def_ = GenerateDSNamespaceDefs_.get('PriceBreakList') - if imported_ns_def_ is not None: - namespacedef_ = imported_ns_def_ - if pretty_print: - eol_ = '\n' - else: - eol_ = '' - if self.original_tagname_ is not None: - name_ = self.original_tagname_ - showIndent(outfile, level, pretty_print) - outfile.write('<%s%s%s' % (namespaceprefix_, name_, namespacedef_ and ' ' + namespacedef_ or '', )) - already_processed = set() - self.exportAttributes(outfile, level, already_processed, namespaceprefix_, name_='PriceBreakList') - if self.hasContent_(): - outfile.write('>%s' % (eol_, )) - self.exportChildren(outfile, level + 1, namespaceprefix_, namespacedef_, name_='PriceBreakList', pretty_print=pretty_print) - showIndent(outfile, level, pretty_print) - outfile.write('%s' % (namespaceprefix_, name_, eol_)) - else: - outfile.write('/>%s' % (eol_, )) - def exportAttributes(self, outfile, level, already_processed, namespaceprefix_='', name_='PriceBreakList'): - pass - def exportChildren(self, outfile, level, namespaceprefix_='', namespacedef_='', name_='PriceBreakList', fromsubclass_=False, pretty_print=True): - if pretty_print: - eol_ = '\n' - else: - eol_ = '' - for price_break_ in self.price_break: - price_break_.export(outfile, level, namespaceprefix_, namespacedef_='', name_='price-break', pretty_print=pretty_print) - def build(self, node): - already_processed = set() - self.buildAttributes(node, node.attrib, already_processed) - for child in node: - nodeName_ = Tag_pattern_.match(child.tag).groups()[-1] - self.buildChildren(child, node, nodeName_) - return self - def buildAttributes(self, node, attrs, already_processed): - pass - def buildChildren(self, child_, node, nodeName_, fromsubclass_=False): - if nodeName_ == 'price-break': - obj_ = PriceBreak.factory(parent_object_=self) - obj_.build(child_) - self.price_break.append(obj_) - obj_.original_tagname_ = 'price-break' -# end class PriceBreakList - - -GDSClassesMapping = { - 'bom-file': BomFile, - 'part': Part, -} - - -USAGE_TEXT = """ -Usage: python .py [ -s ] -""" - - -def usage(): - print(USAGE_TEXT) - sys.exit(1) - - -def get_root_tag(node): - tag = Tag_pattern_.match(node.tag).groups()[-1] - rootClass = GDSClassesMapping.get(tag) - if rootClass is None: - rootClass = globals().get(tag) - return tag, rootClass - - -def parse(inFileName, silence=False): - parser = None - doc = parsexml_(inFileName, parser) - rootNode = doc.getroot() - rootTag, rootClass = get_root_tag(rootNode) - if rootClass is None: - rootTag = 'BomFile' - rootClass = BomFile - rootObj = rootClass.factory() - rootObj.build(rootNode) - # Enable Python to collect the space used by the DOM. - doc = None - if not silence: - sys.stdout.write('\n') - rootObj.export( - sys.stdout, 0, name_=rootTag, - namespacedef_='', - pretty_print=True) - return rootObj - - -def parseEtree(inFileName, silence=False): - parser = None - doc = parsexml_(inFileName, parser) - rootNode = doc.getroot() - rootTag, rootClass = get_root_tag(rootNode) - if rootClass is None: - rootTag = 'BomFile' - rootClass = BomFile - rootObj = rootClass.factory() - rootObj.build(rootNode) - # Enable Python to collect the space used by the DOM. - doc = None - mapping = {} - rootElement = rootObj.to_etree(None, name_=rootTag, mapping_=mapping) - reverse_mapping = rootObj.gds_reverse_node_mapping(mapping) - if not silence: - content = etree_.tostring( - rootElement, pretty_print=True, - xml_declaration=True, encoding="utf-8") - sys.stdout.write(content) - sys.stdout.write('\n') - return rootObj, rootElement, mapping, reverse_mapping - - -def parseString(inString, silence=False): - '''Parse a string, create the object tree, and export it. - - Arguments: - - inString -- A string. This XML fragment should not start - with an XML declaration containing an encoding. - - silence -- A boolean. If False, export the object. - Returns -- The root object in the tree. - ''' - parser = None - rootNode= parsexmlstring_(inString, parser) - rootTag, rootClass = get_root_tag(rootNode) - if rootClass is None: - rootTag = 'BomFile' - rootClass = BomFile - rootObj = rootClass.factory() - rootObj.build(rootNode) - # Enable Python to collect the space used by the DOM. - if not silence: - sys.stdout.write('\n') - rootObj.export( - sys.stdout, 0, name_=rootTag, - namespacedef_='') - return rootObj - - -def parseLiteral(inFileName, silence=False): - parser = None - doc = parsexml_(inFileName, parser) - rootNode = doc.getroot() - rootTag, rootClass = get_root_tag(rootNode) - if rootClass is None: - rootTag = 'BomFile' - rootClass = BomFile - rootObj = rootClass.factory() - rootObj.build(rootNode) - # Enable Python to collect the space used by the DOM. - doc = None - if not silence: - sys.stdout.write('#from bomFile import *\n\n') - sys.stdout.write('import bomFile as model_\n\n') - sys.stdout.write('rootObj = model_.rootClass(\n') - rootObj.exportLiteral(sys.stdout, 0, name_=rootTag) - sys.stdout.write(')\n') - return rootObj - - -def main(): - args = sys.argv[1:] - if len(args) == 1: - parse(args[0]) - else: - usage() - - -if __name__ == '__main__': - #import pdb; pdb.set_trace() - main() - - -__all__ = [ - "Amount", - "BomFile", - "DistributorInfo", - "Fact", - "FactList", - "Part", - "PartList", - "PartNumber", - "PartNumberList", - "PriceBreak", - "PriceBreakList" -] diff --git a/src/ee/xml/bom_file_utils.py b/src/ee/xml/bom_file_utils.py index 063a7bd..59a9b0e 100644 --- a/src/ee/xml/bom_file_utils.py +++ b/src/ee/xml/bom_file_utils.py @@ -1,6 +1,6 @@ from typing import List, Optional -from ee.xml import bomFile, indexFile +from ee.xml import types __all__ = [ "facts", @@ -11,16 +11,11 @@ __all__ = [ def find_root_tag(root): - tag = next((tag for tag, klass in bomFile.GDSClassesMapping.items() if klass == type(root)), None) + return next((tag for tag, klass in types.GDSClassesMapping.items() if klass == type(root)), None) - if tag is not None: - return tag - return next((tag for tag, klass in indexFile.GDSClassesMapping.items() if klass == type(root))) - - -def part_numbers(part: bomFile.Part) -> List[bomFile.PartNumber]: - pns = part.part_numbersProp # type: bomFile.PartNumberList +def part_numbers(part: types.Part) -> List[types.PartNumber]: + pns = part.part_numbersProp # type: types.PartNumberList if pns is None: return [] @@ -28,20 +23,20 @@ def part_numbers(part: bomFile.Part) -> List[bomFile.PartNumber]: return pns.part_numberProp -def find_pn(part: bomFile.Part) -> Optional[str]: +def find_pn(part: types.Part) -> Optional[str]: for pn in part_numbers(part): if pn.distributor is None: return pn.value -def find_dpn(part: bomFile.Part, distributor: str) -> Optional[str]: +def find_dpn(part: types.Part, distributor: str) -> Optional[str]: for pn in part_numbers(part): if pn.distributor == distributor: return pn.value -def facts(part: bomFile.Part, create=False) -> Optional[bomFile.FactList]: - fs: bomFile.FactList = part.factsProp +def facts(part: types.Part, create=False) -> Optional[types.FactList]: + fs: types.FactList = part.factsProp if fs is not None: return fs @@ -49,6 +44,6 @@ def facts(part: bomFile.Part, create=False) -> Optional[bomFile.FactList]: if not create: return - fs = bomFile.FactList() + fs = types.FactList() part.factsProp = fs return fs diff --git a/src/ee/xml/indexFile.py b/src/ee/xml/indexFile.py deleted file mode 100644 index d460db3..0000000 --- a/src/ee/xml/indexFile.py +++ /dev/null @@ -1,1101 +0,0 @@ -#!/usr/bin/env python -# -*- coding: utf-8 -*- - -# -# Generated by generateDS.py. -# Python 3.7.2+ (default, Feb 2 2019, 14:31:48) [GCC 8.2.0] -# -# Command line options: -# ('-f', '') -# ('--no-dates', '') -# ('--no-versions', '') -# ('--output-directory', 'src/ee/xml') -# ('-o', 'src/ee/xml/indexFile.py') -# ('-m', '') -# -# Command line arguments: -# xsd/ee-index.xsd -# -# Command line: -# env/bin/generateDS.py -f --no-dates --no-versions --output-directory="src/ee/xml" -o "src/ee/xml/indexFile.py" -m xsd/ee-index.xsd -# -# Current working directory (os.getcwd()): -# ee-python -# - -import sys -import re as re_ -import base64 -import datetime as datetime_ -import warnings as warnings_ -try: - from lxml import etree as etree_ -except ImportError: - from xml.etree import ElementTree as etree_ - - -Validate_simpletypes_ = True -if sys.version_info.major == 2: - BaseStrType_ = basestring -else: - BaseStrType_ = str - - -def parsexml_(infile, parser=None, **kwargs): - if parser is None: - # Use the lxml ElementTree compatible parser so that, e.g., - # we ignore comments. - try: - parser = etree_.ETCompatXMLParser() - except AttributeError: - # fallback to xml.etree - parser = etree_.XMLParser() - doc = etree_.parse(infile, parser=parser, **kwargs) - return doc - -def parsexmlstring_(instring, parser=None, **kwargs): - if parser is None: - # Use the lxml ElementTree compatible parser so that, e.g., - # we ignore comments. - try: - parser = etree_.ETCompatXMLParser() - except AttributeError: - # fallback to xml.etree - parser = etree_.XMLParser() - element = etree_.fromstring(instring, parser=parser, **kwargs) - return element - -# -# 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 -# in a module named generatedssuper.py. - -try: - from generatedssuper import GeneratedsSuper -except ImportError as exp: - - class GeneratedsSuper(object): - tzoff_pattern = re_.compile(r'(\+|-)((0\d|1[0-3]):[0-5]\d|14:00)$') - class _FixedOffsetTZ(datetime_.tzinfo): - def __init__(self, offset, name): - self.__offset = datetime_.timedelta(minutes=offset) - self.__name = name - def utcoffset(self, dt): - return self.__offset - def tzname(self, dt): - return self.__name - def dst(self, dt): - return None - def gds_format_string(self, input_data, input_name=''): - return input_data - def gds_validate_string(self, input_data, node=None, input_name=''): - if not input_data: - return '' - else: - return input_data - def gds_format_base64(self, input_data, input_name=''): - return base64.b64encode(input_data) - def gds_validate_base64(self, input_data, node=None, input_name=''): - return input_data - def gds_format_integer(self, input_data, input_name=''): - return '%d' % input_data - def gds_validate_integer(self, input_data, node=None, input_name=''): - return input_data - def gds_format_integer_list(self, input_data, input_name=''): - return '%s' % ' '.join(input_data) - def gds_validate_integer_list( - self, input_data, node=None, input_name=''): - values = input_data.split() - for value in values: - try: - int(value) - except (TypeError, ValueError): - raise_parse_error(node, 'Requires sequence of integers') - return values - def gds_format_float(self, input_data, input_name=''): - return ('%.15f' % input_data).rstrip('0') - def gds_validate_float(self, input_data, node=None, input_name=''): - return input_data - def gds_format_float_list(self, input_data, input_name=''): - return '%s' % ' '.join(input_data) - def gds_validate_float_list( - self, input_data, node=None, input_name=''): - values = input_data.split() - for value in values: - try: - float(value) - except (TypeError, ValueError): - raise_parse_error(node, 'Requires sequence of floats') - return values - def gds_format_double(self, input_data, input_name=''): - return '%e' % input_data - def gds_validate_double(self, input_data, node=None, input_name=''): - return input_data - def gds_format_double_list(self, input_data, input_name=''): - return '%s' % ' '.join(input_data) - def gds_validate_double_list( - self, input_data, node=None, input_name=''): - values = input_data.split() - for value in values: - try: - float(value) - except (TypeError, ValueError): - raise_parse_error(node, 'Requires sequence of doubles') - return values - def gds_format_boolean(self, input_data, input_name=''): - return ('%s' % input_data).lower() - def gds_validate_boolean(self, input_data, node=None, input_name=''): - return input_data - def gds_format_boolean_list(self, input_data, input_name=''): - return '%s' % ' '.join(input_data) - def gds_validate_boolean_list( - self, input_data, node=None, input_name=''): - values = input_data.split() - for value in values: - if value not in ('true', '1', 'false', '0', ): - raise_parse_error( - node, - 'Requires sequence of booleans ' - '("true", "1", "false", "0")') - return values - def gds_validate_datetime(self, input_data, node=None, input_name=''): - return input_data - def gds_format_datetime(self, input_data, input_name=''): - if input_data.microsecond == 0: - _svalue = '%04d-%02d-%02dT%02d:%02d:%02d' % ( - input_data.year, - input_data.month, - input_data.day, - input_data.hour, - input_data.minute, - input_data.second, - ) - else: - _svalue = '%04d-%02d-%02dT%02d:%02d:%02d.%s' % ( - input_data.year, - input_data.month, - input_data.day, - input_data.hour, - input_data.minute, - input_data.second, - ('%f' % (float(input_data.microsecond) / 1000000))[2:], - ) - if input_data.tzinfo is not None: - tzoff = input_data.tzinfo.utcoffset(input_data) - if tzoff is not None: - total_seconds = tzoff.seconds + (86400 * tzoff.days) - if total_seconds == 0: - _svalue += 'Z' - else: - if total_seconds < 0: - _svalue += '-' - total_seconds *= -1 - else: - _svalue += '+' - hours = total_seconds // 3600 - minutes = (total_seconds - (hours * 3600)) // 60 - _svalue += '{0:02d}:{1:02d}'.format(hours, minutes) - return _svalue - @classmethod - def gds_parse_datetime(cls, input_data): - tz = None - if input_data[-1] == 'Z': - tz = GeneratedsSuper._FixedOffsetTZ(0, 'UTC') - input_data = input_data[:-1] - else: - results = GeneratedsSuper.tzoff_pattern.search(input_data) - if results is not None: - tzoff_parts = results.group(2).split(':') - tzoff = int(tzoff_parts[0]) * 60 + int(tzoff_parts[1]) - if results.group(1) == '-': - tzoff *= -1 - tz = GeneratedsSuper._FixedOffsetTZ( - tzoff, results.group(0)) - input_data = input_data[:-6] - time_parts = input_data.split('.') - if len(time_parts) > 1: - micro_seconds = int(float('0.' + time_parts[1]) * 1000000) - input_data = '%s.%s' % ( - time_parts[0], "{}".format(micro_seconds).rjust(6, "0"), ) - dt = datetime_.datetime.strptime( - input_data, '%Y-%m-%dT%H:%M:%S.%f') - else: - dt = datetime_.datetime.strptime( - input_data, '%Y-%m-%dT%H:%M:%S') - dt = dt.replace(tzinfo=tz) - return dt - def gds_validate_date(self, input_data, node=None, input_name=''): - return input_data - def gds_format_date(self, input_data, input_name=''): - _svalue = '%04d-%02d-%02d' % ( - input_data.year, - input_data.month, - input_data.day, - ) - try: - if input_data.tzinfo is not None: - tzoff = input_data.tzinfo.utcoffset(input_data) - if tzoff is not None: - total_seconds = tzoff.seconds + (86400 * tzoff.days) - if total_seconds == 0: - _svalue += 'Z' - else: - if total_seconds < 0: - _svalue += '-' - total_seconds *= -1 - else: - _svalue += '+' - hours = total_seconds // 3600 - minutes = (total_seconds - (hours * 3600)) // 60 - _svalue += '{0:02d}:{1:02d}'.format( - hours, minutes) - except AttributeError: - pass - return _svalue - @classmethod - def gds_parse_date(cls, input_data): - tz = None - if input_data[-1] == 'Z': - tz = GeneratedsSuper._FixedOffsetTZ(0, 'UTC') - input_data = input_data[:-1] - else: - results = GeneratedsSuper.tzoff_pattern.search(input_data) - if results is not None: - tzoff_parts = results.group(2).split(':') - tzoff = int(tzoff_parts[0]) * 60 + int(tzoff_parts[1]) - if results.group(1) == '-': - tzoff *= -1 - tz = GeneratedsSuper._FixedOffsetTZ( - tzoff, results.group(0)) - input_data = input_data[:-6] - dt = datetime_.datetime.strptime(input_data, '%Y-%m-%d') - dt = dt.replace(tzinfo=tz) - return dt.date() - def gds_validate_time(self, input_data, node=None, input_name=''): - return input_data - def gds_format_time(self, input_data, input_name=''): - if input_data.microsecond == 0: - _svalue = '%02d:%02d:%02d' % ( - input_data.hour, - input_data.minute, - input_data.second, - ) - else: - _svalue = '%02d:%02d:%02d.%s' % ( - input_data.hour, - input_data.minute, - input_data.second, - ('%f' % (float(input_data.microsecond) / 1000000))[2:], - ) - if input_data.tzinfo is not None: - tzoff = input_data.tzinfo.utcoffset(input_data) - if tzoff is not None: - total_seconds = tzoff.seconds + (86400 * tzoff.days) - if total_seconds == 0: - _svalue += 'Z' - else: - if total_seconds < 0: - _svalue += '-' - total_seconds *= -1 - else: - _svalue += '+' - hours = total_seconds // 3600 - minutes = (total_seconds - (hours * 3600)) // 60 - _svalue += '{0:02d}:{1:02d}'.format(hours, minutes) - return _svalue - def gds_validate_simple_patterns(self, patterns, target): - # pat is a list of lists of strings/patterns. - # The target value must match at least one of the patterns - # in order for the test to succeed. - found1 = True - for patterns1 in patterns: - found2 = False - for patterns2 in patterns1: - mo = re_.search(patterns2, target) - if mo is not None and len(mo.group(0)) == len(target): - found2 = True - break - if not found2: - found1 = False - break - return found1 - @classmethod - def gds_parse_time(cls, input_data): - tz = None - if input_data[-1] == 'Z': - tz = GeneratedsSuper._FixedOffsetTZ(0, 'UTC') - input_data = input_data[:-1] - else: - results = GeneratedsSuper.tzoff_pattern.search(input_data) - if results is not None: - tzoff_parts = results.group(2).split(':') - tzoff = int(tzoff_parts[0]) * 60 + int(tzoff_parts[1]) - if results.group(1) == '-': - tzoff *= -1 - tz = GeneratedsSuper._FixedOffsetTZ( - tzoff, results.group(0)) - input_data = input_data[:-6] - if len(input_data.split('.')) > 1: - dt = datetime_.datetime.strptime(input_data, '%H:%M:%S.%f') - else: - dt = datetime_.datetime.strptime(input_data, '%H:%M:%S') - dt = dt.replace(tzinfo=tz) - return dt.time() - def gds_str_lower(self, instring): - return instring.lower() - def get_path_(self, node): - path_list = [] - self.get_path_list_(node, path_list) - path_list.reverse() - path = '/'.join(path_list) - return path - Tag_strip_pattern_ = re_.compile(r'\{.*\}') - def get_path_list_(self, node, path_list): - if node is None: - return - tag = GeneratedsSuper.Tag_strip_pattern_.sub('', node.tag) - if tag: - path_list.append(tag) - self.get_path_list_(node.getparent(), path_list) - def get_class_obj_(self, node, default_class=None): - class_obj1 = default_class - if 'xsi' in node.nsmap: - classname = node.get('{%s}type' % node.nsmap['xsi']) - if classname is not None: - names = classname.split(':') - if len(names) == 2: - classname = names[1] - class_obj2 = globals().get(classname) - if class_obj2 is not None: - class_obj1 = class_obj2 - return class_obj1 - def gds_build_any(self, node, type_name=None): - return None - @classmethod - def gds_reverse_node_mapping(cls, mapping): - return dict(((v, k) for k, v in mapping.items())) - @staticmethod - def gds_encode(instring): - if sys.version_info.major == 2: - if ExternalEncoding: - encoding = ExternalEncoding - else: - encoding = 'utf-8' - return instring.encode(encoding) - else: - return instring - @staticmethod - def convert_unicode(instring): - if isinstance(instring, str): - result = quote_xml(instring) - elif sys.version_info.major == 2 and isinstance(instring, unicode): - result = quote_xml(instring).encode('utf8') - else: - result = GeneratedsSuper.gds_encode(str(instring)) - return result - def __eq__(self, other): - if type(self) != type(other): - return False - return self.__dict__ == other.__dict__ - def __ne__(self, other): - return not self.__eq__(other) - - def getSubclassFromModule_(module, class_): - '''Get the subclass of a class from a specific module.''' - name = class_.__name__ + 'Sub' - if hasattr(module, name): - return getattr(module, name) - else: - return None - - -# -# If you have installed IPython you can uncomment and use the following. -# IPython is available from http://ipython.scipy.org/. -# - -## from IPython.Shell import IPShellEmbed -## args = '' -## ipshell = IPShellEmbed(args, -## banner = 'Dropping into IPython', -## exit_msg = 'Leaving Interpreter, back to program.') - -# Then use the following line where and when you want to drop into the -# IPython shell: -# ipshell(' -- Entering ipshell.\nHit Ctrl-D to exit') - -# -# Globals -# - -ExternalEncoding = '' -Tag_pattern_ = re_.compile(r'({.*})?(.*)') -String_cleanup_pat_ = re_.compile(r"[\n\r\s]+") -Namespace_extract_pat_ = re_.compile(r'{(.*)}(.*)') -CDATA_pattern_ = re_.compile(r"", re_.DOTALL) - -# Change this to redirect the generated superclass module to use a -# specific subclass module. -CurrentSubclassModule_ = None - -# -# Support/utility functions. -# - - -def showIndent(outfile, level, pretty_print=True): - if pretty_print: - for idx in range(level): - outfile.write(' ') - - -def quote_xml(inStr): - "Escape markup chars, but do not modify CDATA sections." - if not inStr: - return '' - s1 = (isinstance(inStr, BaseStrType_) and inStr or '%s' % inStr) - s2 = '' - pos = 0 - matchobjects = CDATA_pattern_.finditer(s1) - for mo in matchobjects: - s3 = s1[pos:mo.start()] - s2 += quote_xml_aux(s3) - s2 += s1[mo.start():mo.end()] - pos = mo.end() - s3 = s1[pos:] - s2 += quote_xml_aux(s3) - return s2 - - -def quote_xml_aux(inStr): - s1 = inStr.replace('&', '&') - s1 = s1.replace('<', '<') - s1 = s1.replace('>', '>') - return s1 - - -def quote_attrib(inStr): - s1 = (isinstance(inStr, BaseStrType_) and inStr or '%s' % inStr) - s1 = s1.replace('&', '&') - s1 = s1.replace('<', '<') - s1 = s1.replace('>', '>') - if '"' in s1: - if "'" in s1: - s1 = '"%s"' % s1.replace('"', """) - else: - s1 = "'%s'" % s1 - else: - s1 = '"%s"' % s1 - return s1 - - -def quote_python(inStr): - s1 = inStr - if s1.find("'") == -1: - if s1.find('\n') == -1: - return "'%s'" % s1 - else: - return "'''%s'''" % s1 - else: - if s1.find('"') != -1: - s1 = s1.replace('"', '\\"') - if s1.find('\n') == -1: - return '"%s"' % s1 - else: - return '"""%s"""' % s1 - - -def get_all_text_(node): - if node.text is not None: - text = node.text - else: - text = '' - for child in node: - if child.tail is not None: - text += child.tail - return text - - -def find_attr_value_(attr_name, node): - attrs = node.attrib - attr_parts = attr_name.split(':') - value = None - if len(attr_parts) == 1: - value = attrs.get(attr_name) - elif len(attr_parts) == 2: - prefix, name = attr_parts - namespace = node.nsmap.get(prefix) - if namespace is not None: - value = attrs.get('{%s}%s' % (namespace, name, )) - return value - - -class GDSParseError(Exception): - pass - - -def raise_parse_error(node, msg): - msg = '%s (element %s/line %d)' % (msg, node.tag, node.sourceline, ) - raise GDSParseError(msg) - - -class MixedContainer: - # Constants for category: - CategoryNone = 0 - CategoryText = 1 - CategorySimple = 2 - CategoryComplex = 3 - # Constants for content_type: - TypeNone = 0 - TypeText = 1 - TypeString = 2 - TypeInteger = 3 - TypeFloat = 4 - TypeDecimal = 5 - TypeDouble = 6 - TypeBoolean = 7 - TypeBase64 = 8 - def __init__(self, category, content_type, name, value): - self.category = category - self.content_type = content_type - self.name = name - self.value = value - def getCategory(self): - return self.category - def getContenttype(self, content_type): - return self.content_type - def getValue(self): - return self.value - def getName(self): - return self.name - def export(self, outfile, level, name, namespace, - pretty_print=True): - if self.category == MixedContainer.CategoryText: - # Prevent exporting empty content as empty lines. - if self.value.strip(): - outfile.write(self.value) - elif self.category == MixedContainer.CategorySimple: - self.exportSimple(outfile, level, name) - else: # category == MixedContainer.CategoryComplex - self.value.export( - outfile, level, namespace, name_=name, - pretty_print=pretty_print) - def exportSimple(self, outfile, level, name): - if self.content_type == MixedContainer.TypeString: - outfile.write('<%s>%s' % ( - self.name, self.value, self.name)) - elif self.content_type == MixedContainer.TypeInteger or \ - self.content_type == MixedContainer.TypeBoolean: - outfile.write('<%s>%d' % ( - self.name, self.value, self.name)) - elif self.content_type == MixedContainer.TypeFloat or \ - self.content_type == MixedContainer.TypeDecimal: - outfile.write('<%s>%f' % ( - self.name, self.value, self.name)) - elif self.content_type == MixedContainer.TypeDouble: - outfile.write('<%s>%g' % ( - self.name, self.value, self.name)) - elif self.content_type == MixedContainer.TypeBase64: - outfile.write('<%s>%s' % ( - self.name, - base64.b64encode(self.value), - self.name)) - def to_etree(self, element): - if self.category == MixedContainer.CategoryText: - # Prevent exporting empty content as empty lines. - if self.value.strip(): - if len(element) > 0: - if element[-1].tail is None: - element[-1].tail = self.value - else: - element[-1].tail += self.value - else: - if element.text is None: - element.text = self.value - else: - element.text += self.value - elif self.category == MixedContainer.CategorySimple: - subelement = etree_.SubElement( - element, '%s' % self.name) - subelement.text = self.to_etree_simple() - else: # category == MixedContainer.CategoryComplex - self.value.to_etree(element) - def to_etree_simple(self): - if self.content_type == MixedContainer.TypeString: - text = self.value - elif (self.content_type == MixedContainer.TypeInteger or - self.content_type == MixedContainer.TypeBoolean): - text = '%d' % self.value - elif (self.content_type == MixedContainer.TypeFloat or - self.content_type == MixedContainer.TypeDecimal): - text = '%f' % self.value - elif self.content_type == MixedContainer.TypeDouble: - text = '%g' % self.value - elif self.content_type == MixedContainer.TypeBase64: - text = '%s' % base64.b64encode(self.value) - return text - def exportLiteral(self, outfile, level, name): - if self.category == MixedContainer.CategoryText: - showIndent(outfile, level) - outfile.write( - 'model_.MixedContainer(%d, %d, "%s", "%s"),\n' % ( - self.category, self.content_type, - self.name, self.value)) - elif self.category == MixedContainer.CategorySimple: - showIndent(outfile, level) - outfile.write( - 'model_.MixedContainer(%d, %d, "%s", "%s"),\n' % ( - self.category, self.content_type, - self.name, self.value)) - else: # category == MixedContainer.CategoryComplex - showIndent(outfile, level) - outfile.write( - 'model_.MixedContainer(%d, %d, "%s",\n' % ( - self.category, self.content_type, self.name,)) - self.value.exportLiteral(outfile, level + 1) - showIndent(outfile, level) - outfile.write(')\n') - - -class MemberSpec_(object): - def __init__(self, name='', data_type='', container=0, - optional=0, child_attrs=None, choice=None): - self.name = name - self.data_type = data_type - self.container = container - self.child_attrs = child_attrs - self.choice = choice - self.optional = optional - def set_name(self, name): self.name = name - def get_name(self): return self.name - def set_data_type(self, data_type): self.data_type = data_type - def get_data_type_chain(self): return self.data_type - def get_data_type(self): - if isinstance(self.data_type, list): - if len(self.data_type) > 0: - return self.data_type[-1] - else: - return 'xs:string' - else: - return self.data_type - def set_container(self, container): self.container = container - def get_container(self): return self.container - def set_child_attrs(self, child_attrs): self.child_attrs = child_attrs - def get_child_attrs(self): return self.child_attrs - def set_choice(self, choice): self.choice = choice - def get_choice(self): return self.choice - def set_optional(self, optional): self.optional = optional - def get_optional(self): return self.optional - - -def _cast(typ, value): - if typ is None or value is None: - return value - return typ(value) - -# -# Data representation classes. -# - - -class IndexFile(GeneratedsSuper): - subclass = None - superclass = None - def __init__(self, files=None, **kwargs_): - self.original_tagname_ = None - self.parent_object_ = kwargs_.get('parent_object_') - self.files = files - def factory(*args_, **kwargs_): - if CurrentSubclassModule_ is not None: - subclass = getSubclassFromModule_( - CurrentSubclassModule_, IndexFile) - if subclass is not None: - return subclass(*args_, **kwargs_) - if IndexFile.subclass: - return IndexFile.subclass(*args_, **kwargs_) - else: - return IndexFile(*args_, **kwargs_) - factory = staticmethod(factory) - def get_files(self): - return self.files - def set_files(self, files): - self.files = files - filesProp = property(get_files, set_files) - def hasContent_(self): - if ( - self.files is not None - ): - return True - else: - return False - def export(self, outfile, level, namespaceprefix_='', namespacedef_='', name_='IndexFile', pretty_print=True): - imported_ns_def_ = GenerateDSNamespaceDefs_.get('IndexFile') - if imported_ns_def_ is not None: - namespacedef_ = imported_ns_def_ - if pretty_print: - eol_ = '\n' - else: - eol_ = '' - if self.original_tagname_ is not None: - name_ = self.original_tagname_ - showIndent(outfile, level, pretty_print) - outfile.write('<%s%s%s' % (namespaceprefix_, name_, namespacedef_ and ' ' + namespacedef_ or '', )) - already_processed = set() - self.exportAttributes(outfile, level, already_processed, namespaceprefix_, name_='IndexFile') - if self.hasContent_(): - outfile.write('>%s' % (eol_, )) - self.exportChildren(outfile, level + 1, namespaceprefix_, namespacedef_, name_='IndexFile', pretty_print=pretty_print) - showIndent(outfile, level, pretty_print) - outfile.write('%s' % (namespaceprefix_, name_, eol_)) - else: - outfile.write('/>%s' % (eol_, )) - def exportAttributes(self, outfile, level, already_processed, namespaceprefix_='', name_='IndexFile'): - pass - def exportChildren(self, outfile, level, namespaceprefix_='', namespacedef_='', name_='IndexFile', fromsubclass_=False, pretty_print=True): - if pretty_print: - eol_ = '\n' - else: - eol_ = '' - if self.files is not None: - self.files.export(outfile, level, namespaceprefix_, namespacedef_='', name_='files', pretty_print=pretty_print) - def build(self, node): - already_processed = set() - self.buildAttributes(node, node.attrib, already_processed) - for child in node: - nodeName_ = Tag_pattern_.match(child.tag).groups()[-1] - self.buildChildren(child, node, nodeName_) - return self - def buildAttributes(self, node, attrs, already_processed): - pass - def buildChildren(self, child_, node, nodeName_, fromsubclass_=False): - if nodeName_ == 'files': - obj_ = FileList.factory(parent_object_=self) - obj_.build(child_) - self.files = obj_ - obj_.original_tagname_ = 'files' -# end class IndexFile - - -class File(GeneratedsSuper): - subclass = None - superclass = None - def __init__(self, path=None, **kwargs_): - self.original_tagname_ = None - self.parent_object_ = kwargs_.get('parent_object_') - self.path = _cast(None, path) - def factory(*args_, **kwargs_): - if CurrentSubclassModule_ is not None: - subclass = getSubclassFromModule_( - CurrentSubclassModule_, File) - if subclass is not None: - return subclass(*args_, **kwargs_) - if File.subclass: - return File.subclass(*args_, **kwargs_) - else: - return File(*args_, **kwargs_) - factory = staticmethod(factory) - def get_path(self): - return self.path - def set_path(self, path): - self.path = path - pathProp = property(get_path, set_path) - def hasContent_(self): - if ( - - ): - return True - else: - return False - def export(self, outfile, level, namespaceprefix_='', namespacedef_='', name_='File', pretty_print=True): - imported_ns_def_ = GenerateDSNamespaceDefs_.get('File') - if imported_ns_def_ is not None: - namespacedef_ = imported_ns_def_ - if pretty_print: - eol_ = '\n' - else: - eol_ = '' - if self.original_tagname_ is not None: - name_ = self.original_tagname_ - showIndent(outfile, level, pretty_print) - outfile.write('<%s%s%s' % (namespaceprefix_, name_, namespacedef_ and ' ' + namespacedef_ or '', )) - already_processed = set() - self.exportAttributes(outfile, level, already_processed, namespaceprefix_, name_='File') - if self.hasContent_(): - outfile.write('>%s' % (eol_, )) - self.exportChildren(outfile, level + 1, namespaceprefix_, namespacedef_, name_='File', pretty_print=pretty_print) - outfile.write('%s' % (namespaceprefix_, name_, eol_)) - else: - outfile.write('/>%s' % (eol_, )) - def exportAttributes(self, outfile, level, already_processed, namespaceprefix_='', name_='File'): - if self.path is not None and 'path' not in already_processed: - already_processed.add('path') - outfile.write(' path=%s' % (self.gds_encode(self.gds_format_string(quote_attrib(self.path), input_name='path')), )) - def exportChildren(self, outfile, level, namespaceprefix_='', namespacedef_='', name_='File', fromsubclass_=False, pretty_print=True): - pass - def build(self, node): - already_processed = set() - self.buildAttributes(node, node.attrib, already_processed) - for child in node: - nodeName_ = Tag_pattern_.match(child.tag).groups()[-1] - self.buildChildren(child, node, nodeName_) - return self - def buildAttributes(self, node, attrs, already_processed): - value = find_attr_value_('path', node) - if value is not None and 'path' not in already_processed: - already_processed.add('path') - self.path = value - def buildChildren(self, child_, node, nodeName_, fromsubclass_=False): - pass -# end class File - - -class FileList(GeneratedsSuper): - subclass = None - superclass = None - def __init__(self, file=None, **kwargs_): - self.original_tagname_ = None - self.parent_object_ = kwargs_.get('parent_object_') - if file is None: - self.file = [] - else: - self.file = file - def factory(*args_, **kwargs_): - if CurrentSubclassModule_ is not None: - subclass = getSubclassFromModule_( - CurrentSubclassModule_, FileList) - if subclass is not None: - return subclass(*args_, **kwargs_) - if FileList.subclass: - return FileList.subclass(*args_, **kwargs_) - else: - return FileList(*args_, **kwargs_) - factory = staticmethod(factory) - def get_file(self): - return self.file - def set_file(self, file): - self.file = file - def add_file(self, value): - self.file.append(value) - def add_file(self, value): - self.file.append(value) - def insert_file_at(self, index, value): - self.file.insert(index, value) - def replace_file_at(self, index, value): - self.file[index] = value - fileProp = property(get_file, set_file) - def hasContent_(self): - if ( - self.file - ): - return True - else: - return False - def export(self, outfile, level, namespaceprefix_='', namespacedef_='', name_='FileList', pretty_print=True): - imported_ns_def_ = GenerateDSNamespaceDefs_.get('FileList') - if imported_ns_def_ is not None: - namespacedef_ = imported_ns_def_ - if pretty_print: - eol_ = '\n' - else: - eol_ = '' - if self.original_tagname_ is not None: - name_ = self.original_tagname_ - showIndent(outfile, level, pretty_print) - outfile.write('<%s%s%s' % (namespaceprefix_, name_, namespacedef_ and ' ' + namespacedef_ or '', )) - already_processed = set() - self.exportAttributes(outfile, level, already_processed, namespaceprefix_, name_='FileList') - if self.hasContent_(): - outfile.write('>%s' % (eol_, )) - self.exportChildren(outfile, level + 1, namespaceprefix_, namespacedef_, name_='FileList', pretty_print=pretty_print) - showIndent(outfile, level, pretty_print) - outfile.write('%s' % (namespaceprefix_, name_, eol_)) - else: - outfile.write('/>%s' % (eol_, )) - def exportAttributes(self, outfile, level, already_processed, namespaceprefix_='', name_='FileList'): - pass - def exportChildren(self, outfile, level, namespaceprefix_='', namespacedef_='', name_='FileList', fromsubclass_=False, pretty_print=True): - if pretty_print: - eol_ = '\n' - else: - eol_ = '' - for file_ in self.file: - file_.export(outfile, level, namespaceprefix_, namespacedef_='', name_='file', pretty_print=pretty_print) - def build(self, node): - already_processed = set() - self.buildAttributes(node, node.attrib, already_processed) - for child in node: - nodeName_ = Tag_pattern_.match(child.tag).groups()[-1] - self.buildChildren(child, node, nodeName_) - return self - def buildAttributes(self, node, attrs, already_processed): - pass - def buildChildren(self, child_, node, nodeName_, fromsubclass_=False): - if nodeName_ == 'file': - obj_ = File.factory(parent_object_=self) - obj_.build(child_) - self.file.append(obj_) - obj_.original_tagname_ = 'file' -# end class FileList - - -GDSClassesMapping = { - 'file-index': IndexFile, -} - - -USAGE_TEXT = """ -Usage: python .py [ -s ] -""" - - -def usage(): - print(USAGE_TEXT) - sys.exit(1) - - -def get_root_tag(node): - tag = Tag_pattern_.match(node.tag).groups()[-1] - rootClass = GDSClassesMapping.get(tag) - if rootClass is None: - rootClass = globals().get(tag) - return tag, rootClass - - -def parse(inFileName, silence=False): - parser = None - doc = parsexml_(inFileName, parser) - rootNode = doc.getroot() - rootTag, rootClass = get_root_tag(rootNode) - if rootClass is None: - rootTag = 'IndexFile' - rootClass = IndexFile - rootObj = rootClass.factory() - rootObj.build(rootNode) - # Enable Python to collect the space used by the DOM. - doc = None - if not silence: - sys.stdout.write('\n') - rootObj.export( - sys.stdout, 0, name_=rootTag, - namespacedef_='', - pretty_print=True) - return rootObj - - -def parseEtree(inFileName, silence=False): - parser = None - doc = parsexml_(inFileName, parser) - rootNode = doc.getroot() - rootTag, rootClass = get_root_tag(rootNode) - if rootClass is None: - rootTag = 'IndexFile' - rootClass = IndexFile - rootObj = rootClass.factory() - rootObj.build(rootNode) - # Enable Python to collect the space used by the DOM. - doc = None - mapping = {} - rootElement = rootObj.to_etree(None, name_=rootTag, mapping_=mapping) - reverse_mapping = rootObj.gds_reverse_node_mapping(mapping) - if not silence: - content = etree_.tostring( - rootElement, pretty_print=True, - xml_declaration=True, encoding="utf-8") - sys.stdout.write(content) - sys.stdout.write('\n') - return rootObj, rootElement, mapping, reverse_mapping - - -def parseString(inString, silence=False): - '''Parse a string, create the object tree, and export it. - - Arguments: - - inString -- A string. This XML fragment should not start - with an XML declaration containing an encoding. - - silence -- A boolean. If False, export the object. - Returns -- The root object in the tree. - ''' - parser = None - rootNode= parsexmlstring_(inString, parser) - rootTag, rootClass = get_root_tag(rootNode) - if rootClass is None: - rootTag = 'IndexFile' - rootClass = IndexFile - rootObj = rootClass.factory() - rootObj.build(rootNode) - # Enable Python to collect the space used by the DOM. - if not silence: - sys.stdout.write('\n') - rootObj.export( - sys.stdout, 0, name_=rootTag, - namespacedef_='') - return rootObj - - -def parseLiteral(inFileName, silence=False): - parser = None - doc = parsexml_(inFileName, parser) - rootNode = doc.getroot() - rootTag, rootClass = get_root_tag(rootNode) - if rootClass is None: - rootTag = 'IndexFile' - rootClass = IndexFile - rootObj = rootClass.factory() - rootObj.build(rootNode) - # Enable Python to collect the space used by the DOM. - doc = None - if not silence: - sys.stdout.write('#from indexFile import *\n\n') - sys.stdout.write('import indexFile as model_\n\n') - sys.stdout.write('rootObj = model_.rootClass(\n') - rootObj.exportLiteral(sys.stdout, 0, name_=rootTag) - sys.stdout.write(')\n') - return rootObj - - -def main(): - args = sys.argv[1:] - if len(args) == 1: - parse(args[0]) - else: - usage() - - -if __name__ == '__main__': - #import pdb; pdb.set_trace() - main() - - -__all__ = [ - "File", - "FileList", - "IndexFile" -] diff --git a/src/ee/xml/types.py b/src/ee/xml/types.py new file mode 100644 index 0000000..356b520 --- /dev/null +++ b/src/ee/xml/types.py @@ -0,0 +1,2161 @@ +#!/usr/bin/env python +# -*- coding: utf-8 -*- + +# +# Generated by generateDS.py. +# Python 3.7.2+ (default, Feb 27 2019, 15:41:59) [GCC 8.2.0] +# +# Command line options: +# ('-f', '') +# ('--no-dates', '') +# ('--no-versions', '') +# ('--output-directory', 'src/ee/xml') +# ('-o', 'src/ee/xml/types.py') +# ('-m', '') +# +# Command line arguments: +# xsd/ee.xsd +# +# Command line: +# env/bin/generateDS.py -f --no-dates --no-versions --output-directory="src/ee/xml" -o "src/ee/xml/types.py" -m xsd/ee.xsd +# +# Current working directory (os.getcwd()): +# ee-python +# + +import sys +import re as re_ +import base64 +import datetime as datetime_ +import warnings as warnings_ +try: + from lxml import etree as etree_ +except ImportError: + from xml.etree import ElementTree as etree_ + + +Validate_simpletypes_ = True +if sys.version_info.major == 2: + BaseStrType_ = basestring +else: + BaseStrType_ = str + + +def parsexml_(infile, parser=None, **kwargs): + if parser is None: + # Use the lxml ElementTree compatible parser so that, e.g., + # we ignore comments. + try: + parser = etree_.ETCompatXMLParser() + except AttributeError: + # fallback to xml.etree + parser = etree_.XMLParser() + doc = etree_.parse(infile, parser=parser, **kwargs) + return doc + +def parsexmlstring_(instring, parser=None, **kwargs): + if parser is None: + # Use the lxml ElementTree compatible parser so that, e.g., + # we ignore comments. + try: + parser = etree_.ETCompatXMLParser() + except AttributeError: + # fallback to xml.etree + parser = etree_.XMLParser() + element = etree_.fromstring(instring, parser=parser, **kwargs) + return element + +# +# 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 +# in a module named generatedssuper.py. + +try: + from generatedssuper import GeneratedsSuper +except ImportError as exp: + + class GeneratedsSuper(object): + tzoff_pattern = re_.compile(r'(\+|-)((0\d|1[0-3]):[0-5]\d|14:00)$') + class _FixedOffsetTZ(datetime_.tzinfo): + def __init__(self, offset, name): + self.__offset = datetime_.timedelta(minutes=offset) + self.__name = name + def utcoffset(self, dt): + return self.__offset + def tzname(self, dt): + return self.__name + def dst(self, dt): + return None + def gds_format_string(self, input_data, input_name=''): + return input_data + def gds_validate_string(self, input_data, node=None, input_name=''): + if not input_data: + return '' + else: + return input_data + def gds_format_base64(self, input_data, input_name=''): + return base64.b64encode(input_data) + def gds_validate_base64(self, input_data, node=None, input_name=''): + return input_data + def gds_format_integer(self, input_data, input_name=''): + return '%d' % input_data + def gds_validate_integer(self, input_data, node=None, input_name=''): + return input_data + def gds_format_integer_list(self, input_data, input_name=''): + return '%s' % ' '.join(input_data) + def gds_validate_integer_list( + self, input_data, node=None, input_name=''): + values = input_data.split() + for value in values: + try: + int(value) + except (TypeError, ValueError): + raise_parse_error(node, 'Requires sequence of integers') + return values + def gds_format_float(self, input_data, input_name=''): + return ('%.15f' % input_data).rstrip('0') + def gds_validate_float(self, input_data, node=None, input_name=''): + return input_data + def gds_format_float_list(self, input_data, input_name=''): + return '%s' % ' '.join(input_data) + def gds_validate_float_list( + self, input_data, node=None, input_name=''): + values = input_data.split() + for value in values: + try: + float(value) + except (TypeError, ValueError): + raise_parse_error(node, 'Requires sequence of floats') + return values + def gds_format_double(self, input_data, input_name=''): + return '%e' % input_data + def gds_validate_double(self, input_data, node=None, input_name=''): + return input_data + def gds_format_double_list(self, input_data, input_name=''): + return '%s' % ' '.join(input_data) + def gds_validate_double_list( + self, input_data, node=None, input_name=''): + values = input_data.split() + for value in values: + try: + float(value) + except (TypeError, ValueError): + raise_parse_error(node, 'Requires sequence of doubles') + return values + def gds_format_boolean(self, input_data, input_name=''): + return ('%s' % input_data).lower() + def gds_validate_boolean(self, input_data, node=None, input_name=''): + return input_data + def gds_format_boolean_list(self, input_data, input_name=''): + return '%s' % ' '.join(input_data) + def gds_validate_boolean_list( + self, input_data, node=None, input_name=''): + values = input_data.split() + for value in values: + if value not in ('true', '1', 'false', '0', ): + raise_parse_error( + node, + 'Requires sequence of booleans ' + '("true", "1", "false", "0")') + return values + def gds_validate_datetime(self, input_data, node=None, input_name=''): + return input_data + def gds_format_datetime(self, input_data, input_name=''): + if input_data.microsecond == 0: + _svalue = '%04d-%02d-%02dT%02d:%02d:%02d' % ( + input_data.year, + input_data.month, + input_data.day, + input_data.hour, + input_data.minute, + input_data.second, + ) + else: + _svalue = '%04d-%02d-%02dT%02d:%02d:%02d.%s' % ( + input_data.year, + input_data.month, + input_data.day, + input_data.hour, + input_data.minute, + input_data.second, + ('%f' % (float(input_data.microsecond) / 1000000))[2:], + ) + if input_data.tzinfo is not None: + tzoff = input_data.tzinfo.utcoffset(input_data) + if tzoff is not None: + total_seconds = tzoff.seconds + (86400 * tzoff.days) + if total_seconds == 0: + _svalue += 'Z' + else: + if total_seconds < 0: + _svalue += '-' + total_seconds *= -1 + else: + _svalue += '+' + hours = total_seconds // 3600 + minutes = (total_seconds - (hours * 3600)) // 60 + _svalue += '{0:02d}:{1:02d}'.format(hours, minutes) + return _svalue + @classmethod + def gds_parse_datetime(cls, input_data): + tz = None + if input_data[-1] == 'Z': + tz = GeneratedsSuper._FixedOffsetTZ(0, 'UTC') + input_data = input_data[:-1] + else: + results = GeneratedsSuper.tzoff_pattern.search(input_data) + if results is not None: + tzoff_parts = results.group(2).split(':') + tzoff = int(tzoff_parts[0]) * 60 + int(tzoff_parts[1]) + if results.group(1) == '-': + tzoff *= -1 + tz = GeneratedsSuper._FixedOffsetTZ( + tzoff, results.group(0)) + input_data = input_data[:-6] + time_parts = input_data.split('.') + if len(time_parts) > 1: + micro_seconds = int(float('0.' + time_parts[1]) * 1000000) + input_data = '%s.%s' % ( + time_parts[0], "{}".format(micro_seconds).rjust(6, "0"), ) + dt = datetime_.datetime.strptime( + input_data, '%Y-%m-%dT%H:%M:%S.%f') + else: + dt = datetime_.datetime.strptime( + input_data, '%Y-%m-%dT%H:%M:%S') + dt = dt.replace(tzinfo=tz) + return dt + def gds_validate_date(self, input_data, node=None, input_name=''): + return input_data + def gds_format_date(self, input_data, input_name=''): + _svalue = '%04d-%02d-%02d' % ( + input_data.year, + input_data.month, + input_data.day, + ) + try: + if input_data.tzinfo is not None: + tzoff = input_data.tzinfo.utcoffset(input_data) + if tzoff is not None: + total_seconds = tzoff.seconds + (86400 * tzoff.days) + if total_seconds == 0: + _svalue += 'Z' + else: + if total_seconds < 0: + _svalue += '-' + total_seconds *= -1 + else: + _svalue += '+' + hours = total_seconds // 3600 + minutes = (total_seconds - (hours * 3600)) // 60 + _svalue += '{0:02d}:{1:02d}'.format( + hours, minutes) + except AttributeError: + pass + return _svalue + @classmethod + def gds_parse_date(cls, input_data): + tz = None + if input_data[-1] == 'Z': + tz = GeneratedsSuper._FixedOffsetTZ(0, 'UTC') + input_data = input_data[:-1] + else: + results = GeneratedsSuper.tzoff_pattern.search(input_data) + if results is not None: + tzoff_parts = results.group(2).split(':') + tzoff = int(tzoff_parts[0]) * 60 + int(tzoff_parts[1]) + if results.group(1) == '-': + tzoff *= -1 + tz = GeneratedsSuper._FixedOffsetTZ( + tzoff, results.group(0)) + input_data = input_data[:-6] + dt = datetime_.datetime.strptime(input_data, '%Y-%m-%d') + dt = dt.replace(tzinfo=tz) + return dt.date() + def gds_validate_time(self, input_data, node=None, input_name=''): + return input_data + def gds_format_time(self, input_data, input_name=''): + if input_data.microsecond == 0: + _svalue = '%02d:%02d:%02d' % ( + input_data.hour, + input_data.minute, + input_data.second, + ) + else: + _svalue = '%02d:%02d:%02d.%s' % ( + input_data.hour, + input_data.minute, + input_data.second, + ('%f' % (float(input_data.microsecond) / 1000000))[2:], + ) + if input_data.tzinfo is not None: + tzoff = input_data.tzinfo.utcoffset(input_data) + if tzoff is not None: + total_seconds = tzoff.seconds + (86400 * tzoff.days) + if total_seconds == 0: + _svalue += 'Z' + else: + if total_seconds < 0: + _svalue += '-' + total_seconds *= -1 + else: + _svalue += '+' + hours = total_seconds // 3600 + minutes = (total_seconds - (hours * 3600)) // 60 + _svalue += '{0:02d}:{1:02d}'.format(hours, minutes) + return _svalue + def gds_validate_simple_patterns(self, patterns, target): + # pat is a list of lists of strings/patterns. + # The target value must match at least one of the patterns + # in order for the test to succeed. + found1 = True + for patterns1 in patterns: + found2 = False + for patterns2 in patterns1: + mo = re_.search(patterns2, target) + if mo is not None and len(mo.group(0)) == len(target): + found2 = True + break + if not found2: + found1 = False + break + return found1 + @classmethod + def gds_parse_time(cls, input_data): + tz = None + if input_data[-1] == 'Z': + tz = GeneratedsSuper._FixedOffsetTZ(0, 'UTC') + input_data = input_data[:-1] + else: + results = GeneratedsSuper.tzoff_pattern.search(input_data) + if results is not None: + tzoff_parts = results.group(2).split(':') + tzoff = int(tzoff_parts[0]) * 60 + int(tzoff_parts[1]) + if results.group(1) == '-': + tzoff *= -1 + tz = GeneratedsSuper._FixedOffsetTZ( + tzoff, results.group(0)) + input_data = input_data[:-6] + if len(input_data.split('.')) > 1: + dt = datetime_.datetime.strptime(input_data, '%H:%M:%S.%f') + else: + dt = datetime_.datetime.strptime(input_data, '%H:%M:%S') + dt = dt.replace(tzinfo=tz) + return dt.time() + def gds_str_lower(self, instring): + return instring.lower() + def get_path_(self, node): + path_list = [] + self.get_path_list_(node, path_list) + path_list.reverse() + path = '/'.join(path_list) + return path + Tag_strip_pattern_ = re_.compile(r'\{.*\}') + def get_path_list_(self, node, path_list): + if node is None: + return + tag = GeneratedsSuper.Tag_strip_pattern_.sub('', node.tag) + if tag: + path_list.append(tag) + self.get_path_list_(node.getparent(), path_list) + def get_class_obj_(self, node, default_class=None): + class_obj1 = default_class + if 'xsi' in node.nsmap: + classname = node.get('{%s}type' % node.nsmap['xsi']) + if classname is not None: + names = classname.split(':') + if len(names) == 2: + classname = names[1] + class_obj2 = globals().get(classname) + if class_obj2 is not None: + class_obj1 = class_obj2 + return class_obj1 + def gds_build_any(self, node, type_name=None): + return None + @classmethod + def gds_reverse_node_mapping(cls, mapping): + return dict(((v, k) for k, v in mapping.items())) + @staticmethod + def gds_encode(instring): + if sys.version_info.major == 2: + if ExternalEncoding: + encoding = ExternalEncoding + else: + encoding = 'utf-8' + return instring.encode(encoding) + else: + return instring + @staticmethod + def convert_unicode(instring): + if isinstance(instring, str): + result = quote_xml(instring) + elif sys.version_info.major == 2 and isinstance(instring, unicode): + result = quote_xml(instring).encode('utf8') + else: + result = GeneratedsSuper.gds_encode(str(instring)) + return result + def __eq__(self, other): + if type(self) != type(other): + return False + return self.__dict__ == other.__dict__ + def __ne__(self, other): + return not self.__eq__(other) + + def getSubclassFromModule_(module, class_): + '''Get the subclass of a class from a specific module.''' + name = class_.__name__ + 'Sub' + if hasattr(module, name): + return getattr(module, name) + else: + return None + + +# +# If you have installed IPython you can uncomment and use the following. +# IPython is available from http://ipython.scipy.org/. +# + +## from IPython.Shell import IPShellEmbed +## args = '' +## ipshell = IPShellEmbed(args, +## banner = 'Dropping into IPython', +## exit_msg = 'Leaving Interpreter, back to program.') + +# Then use the following line where and when you want to drop into the +# IPython shell: +# ipshell(' -- Entering ipshell.\nHit Ctrl-D to exit') + +# +# Globals +# + +ExternalEncoding = '' +Tag_pattern_ = re_.compile(r'({.*})?(.*)') +String_cleanup_pat_ = re_.compile(r"[\n\r\s]+") +Namespace_extract_pat_ = re_.compile(r'{(.*)}(.*)') +CDATA_pattern_ = re_.compile(r"", re_.DOTALL) + +# Change this to redirect the generated superclass module to use a +# specific subclass module. +CurrentSubclassModule_ = None + +# +# Support/utility functions. +# + + +def showIndent(outfile, level, pretty_print=True): + if pretty_print: + for idx in range(level): + outfile.write(' ') + + +def quote_xml(inStr): + "Escape markup chars, but do not modify CDATA sections." + if not inStr: + return '' + s1 = (isinstance(inStr, BaseStrType_) and inStr or '%s' % inStr) + s2 = '' + pos = 0 + matchobjects = CDATA_pattern_.finditer(s1) + for mo in matchobjects: + s3 = s1[pos:mo.start()] + s2 += quote_xml_aux(s3) + s2 += s1[mo.start():mo.end()] + pos = mo.end() + s3 = s1[pos:] + s2 += quote_xml_aux(s3) + return s2 + + +def quote_xml_aux(inStr): + s1 = inStr.replace('&', '&') + s1 = s1.replace('<', '<') + s1 = s1.replace('>', '>') + return s1 + + +def quote_attrib(inStr): + s1 = (isinstance(inStr, BaseStrType_) and inStr or '%s' % inStr) + s1 = s1.replace('&', '&') + s1 = s1.replace('<', '<') + s1 = s1.replace('>', '>') + if '"' in s1: + if "'" in s1: + s1 = '"%s"' % s1.replace('"', """) + else: + s1 = "'%s'" % s1 + else: + s1 = '"%s"' % s1 + return s1 + + +def quote_python(inStr): + s1 = inStr + if s1.find("'") == -1: + if s1.find('\n') == -1: + return "'%s'" % s1 + else: + return "'''%s'''" % s1 + else: + if s1.find('"') != -1: + s1 = s1.replace('"', '\\"') + if s1.find('\n') == -1: + return '"%s"' % s1 + else: + return '"""%s"""' % s1 + + +def get_all_text_(node): + if node.text is not None: + text = node.text + else: + text = '' + for child in node: + if child.tail is not None: + text += child.tail + return text + + +def find_attr_value_(attr_name, node): + attrs = node.attrib + attr_parts = attr_name.split(':') + value = None + if len(attr_parts) == 1: + value = attrs.get(attr_name) + elif len(attr_parts) == 2: + prefix, name = attr_parts + namespace = node.nsmap.get(prefix) + if namespace is not None: + value = attrs.get('{%s}%s' % (namespace, name, )) + return value + + +class GDSParseError(Exception): + pass + + +def raise_parse_error(node, msg): + msg = '%s (element %s/line %d)' % (msg, node.tag, node.sourceline, ) + raise GDSParseError(msg) + + +class MixedContainer: + # Constants for category: + CategoryNone = 0 + CategoryText = 1 + CategorySimple = 2 + CategoryComplex = 3 + # Constants for content_type: + TypeNone = 0 + TypeText = 1 + TypeString = 2 + TypeInteger = 3 + TypeFloat = 4 + TypeDecimal = 5 + TypeDouble = 6 + TypeBoolean = 7 + TypeBase64 = 8 + def __init__(self, category, content_type, name, value): + self.category = category + self.content_type = content_type + self.name = name + self.value = value + def getCategory(self): + return self.category + def getContenttype(self, content_type): + return self.content_type + def getValue(self): + return self.value + def getName(self): + return self.name + def export(self, outfile, level, name, namespace, + pretty_print=True): + if self.category == MixedContainer.CategoryText: + # Prevent exporting empty content as empty lines. + if self.value.strip(): + outfile.write(self.value) + elif self.category == MixedContainer.CategorySimple: + self.exportSimple(outfile, level, name) + else: # category == MixedContainer.CategoryComplex + self.value.export( + outfile, level, namespace, name_=name, + pretty_print=pretty_print) + def exportSimple(self, outfile, level, name): + if self.content_type == MixedContainer.TypeString: + outfile.write('<%s>%s' % ( + self.name, self.value, self.name)) + elif self.content_type == MixedContainer.TypeInteger or \ + self.content_type == MixedContainer.TypeBoolean: + outfile.write('<%s>%d' % ( + self.name, self.value, self.name)) + elif self.content_type == MixedContainer.TypeFloat or \ + self.content_type == MixedContainer.TypeDecimal: + outfile.write('<%s>%f' % ( + self.name, self.value, self.name)) + elif self.content_type == MixedContainer.TypeDouble: + outfile.write('<%s>%g' % ( + self.name, self.value, self.name)) + elif self.content_type == MixedContainer.TypeBase64: + outfile.write('<%s>%s' % ( + self.name, + base64.b64encode(self.value), + self.name)) + def to_etree(self, element): + if self.category == MixedContainer.CategoryText: + # Prevent exporting empty content as empty lines. + if self.value.strip(): + if len(element) > 0: + if element[-1].tail is None: + element[-1].tail = self.value + else: + element[-1].tail += self.value + else: + if element.text is None: + element.text = self.value + else: + element.text += self.value + elif self.category == MixedContainer.CategorySimple: + subelement = etree_.SubElement( + element, '%s' % self.name) + subelement.text = self.to_etree_simple() + else: # category == MixedContainer.CategoryComplex + self.value.to_etree(element) + def to_etree_simple(self): + if self.content_type == MixedContainer.TypeString: + text = self.value + elif (self.content_type == MixedContainer.TypeInteger or + self.content_type == MixedContainer.TypeBoolean): + text = '%d' % self.value + elif (self.content_type == MixedContainer.TypeFloat or + self.content_type == MixedContainer.TypeDecimal): + text = '%f' % self.value + elif self.content_type == MixedContainer.TypeDouble: + text = '%g' % self.value + elif self.content_type == MixedContainer.TypeBase64: + text = '%s' % base64.b64encode(self.value) + return text + def exportLiteral(self, outfile, level, name): + if self.category == MixedContainer.CategoryText: + showIndent(outfile, level) + outfile.write( + 'model_.MixedContainer(%d, %d, "%s", "%s"),\n' % ( + self.category, self.content_type, + self.name, self.value)) + elif self.category == MixedContainer.CategorySimple: + showIndent(outfile, level) + outfile.write( + 'model_.MixedContainer(%d, %d, "%s", "%s"),\n' % ( + self.category, self.content_type, + self.name, self.value)) + else: # category == MixedContainer.CategoryComplex + showIndent(outfile, level) + outfile.write( + 'model_.MixedContainer(%d, %d, "%s",\n' % ( + self.category, self.content_type, self.name,)) + self.value.exportLiteral(outfile, level + 1) + showIndent(outfile, level) + outfile.write(')\n') + + +class MemberSpec_(object): + def __init__(self, name='', data_type='', container=0, + optional=0, child_attrs=None, choice=None): + self.name = name + self.data_type = data_type + self.container = container + self.child_attrs = child_attrs + self.choice = choice + self.optional = optional + def set_name(self, name): self.name = name + def get_name(self): return self.name + def set_data_type(self, data_type): self.data_type = data_type + def get_data_type_chain(self): return self.data_type + def get_data_type(self): + if isinstance(self.data_type, list): + if len(self.data_type) > 0: + return self.data_type[-1] + else: + return 'xs:string' + else: + return self.data_type + def set_container(self, container): self.container = container + def get_container(self): return self.container + def set_child_attrs(self, child_attrs): self.child_attrs = child_attrs + def get_child_attrs(self): return self.child_attrs + def set_choice(self, choice): self.choice = choice + def get_choice(self): return self.choice + def set_optional(self, optional): self.optional = optional + def get_optional(self): return self.optional + + +def _cast(typ, value): + if typ is None or value is None: + return value + return typ(value) + +# +# Data representation classes. +# + + +class PartCollection(GeneratedsSuper): + subclass = None + superclass = None + def __init__(self, parts=None, **kwargs_): + self.original_tagname_ = None + self.parent_object_ = kwargs_.get('parent_object_') + self.parts = parts + def factory(*args_, **kwargs_): + if CurrentSubclassModule_ is not None: + subclass = getSubclassFromModule_( + CurrentSubclassModule_, PartCollection) + if subclass is not None: + return subclass(*args_, **kwargs_) + if PartCollection.subclass: + return PartCollection.subclass(*args_, **kwargs_) + else: + return PartCollection(*args_, **kwargs_) + factory = staticmethod(factory) + def get_parts(self): + return self.parts + def set_parts(self, parts): + self.parts = parts + partsProp = property(get_parts, set_parts) + def hasContent_(self): + if ( + self.parts is not None + ): + return True + else: + return False + def export(self, outfile, level, namespaceprefix_='', namespacedef_='', name_='PartCollection', pretty_print=True): + imported_ns_def_ = GenerateDSNamespaceDefs_.get('PartCollection') + if imported_ns_def_ is not None: + namespacedef_ = imported_ns_def_ + if pretty_print: + eol_ = '\n' + else: + eol_ = '' + if self.original_tagname_ is not None: + name_ = self.original_tagname_ + showIndent(outfile, level, pretty_print) + outfile.write('<%s%s%s' % (namespaceprefix_, name_, namespacedef_ and ' ' + namespacedef_ or '', )) + already_processed = set() + self.exportAttributes(outfile, level, already_processed, namespaceprefix_, name_='PartCollection') + if self.hasContent_(): + outfile.write('>%s' % (eol_, )) + self.exportChildren(outfile, level + 1, namespaceprefix_, namespacedef_, name_='PartCollection', pretty_print=pretty_print) + showIndent(outfile, level, pretty_print) + outfile.write('%s' % (namespaceprefix_, name_, eol_)) + else: + outfile.write('/>%s' % (eol_, )) + def exportAttributes(self, outfile, level, already_processed, namespaceprefix_='', name_='PartCollection'): + pass + def exportChildren(self, outfile, level, namespaceprefix_='', namespacedef_='', name_='PartCollection', fromsubclass_=False, pretty_print=True): + if pretty_print: + eol_ = '\n' + else: + eol_ = '' + if self.parts is not None: + self.parts.export(outfile, level, namespaceprefix_, namespacedef_='', name_='parts', pretty_print=pretty_print) + def build(self, node): + already_processed = set() + self.buildAttributes(node, node.attrib, already_processed) + for child in node: + nodeName_ = Tag_pattern_.match(child.tag).groups()[-1] + self.buildChildren(child, node, nodeName_) + return self + def buildAttributes(self, node, attrs, already_processed): + pass + def buildChildren(self, child_, node, nodeName_, fromsubclass_=False): + if nodeName_ == 'parts': + obj_ = PartList.factory(parent_object_=self) + obj_.build(child_) + self.parts = obj_ + obj_.original_tagname_ = 'parts' +# end class PartCollection + + +class Part(GeneratedsSuper): + subclass = None + superclass = None + def __init__(self, id=None, schema_reference=None, part_type=None, part_numbers=None, distributor_info=None, facts=None, price_breaks=None, **kwargs_): + self.original_tagname_ = None + self.parent_object_ = kwargs_.get('parent_object_') + self.id = _cast(None, id) + self.schema_reference = schema_reference + self.part_type = part_type + self.part_numbers = part_numbers + self.distributor_info = distributor_info + self.facts = facts + self.price_breaks = price_breaks + def factory(*args_, **kwargs_): + if CurrentSubclassModule_ is not None: + subclass = getSubclassFromModule_( + CurrentSubclassModule_, Part) + if subclass is not None: + return subclass(*args_, **kwargs_) + if Part.subclass: + return Part.subclass(*args_, **kwargs_) + else: + return Part(*args_, **kwargs_) + factory = staticmethod(factory) + def get_schema_reference(self): + return self.schema_reference + def set_schema_reference(self, schema_reference): + self.schema_reference = schema_reference + schema_referenceProp = property(get_schema_reference, set_schema_reference) + def get_part_type(self): + return self.part_type + def set_part_type(self, part_type): + self.part_type = part_type + part_typeProp = property(get_part_type, set_part_type) + def get_part_numbers(self): + return self.part_numbers + def set_part_numbers(self, part_numbers): + self.part_numbers = part_numbers + part_numbersProp = property(get_part_numbers, set_part_numbers) + def get_distributor_info(self): + return self.distributor_info + def set_distributor_info(self, distributor_info): + self.distributor_info = distributor_info + distributor_infoProp = property(get_distributor_info, set_distributor_info) + def get_facts(self): + return self.facts + def set_facts(self, facts): + self.facts = facts + factsProp = property(get_facts, set_facts) + def get_price_breaks(self): + return self.price_breaks + def set_price_breaks(self, price_breaks): + self.price_breaks = price_breaks + price_breaksProp = property(get_price_breaks, set_price_breaks) + def get_id(self): + return self.id + def set_id(self, id): + self.id = id + idProp = property(get_id, set_id) + def hasContent_(self): + if ( + self.schema_reference is not None or + self.part_type is not None or + self.part_numbers is not None or + self.distributor_info is not None or + self.facts is not None or + self.price_breaks is not None + ): + return True + else: + return False + def export(self, outfile, level, namespaceprefix_='', namespacedef_='', name_='Part', pretty_print=True): + imported_ns_def_ = GenerateDSNamespaceDefs_.get('Part') + if imported_ns_def_ is not None: + namespacedef_ = imported_ns_def_ + if pretty_print: + eol_ = '\n' + else: + eol_ = '' + if self.original_tagname_ is not None: + name_ = self.original_tagname_ + showIndent(outfile, level, pretty_print) + outfile.write('<%s%s%s' % (namespaceprefix_, name_, namespacedef_ and ' ' + namespacedef_ or '', )) + already_processed = set() + self.exportAttributes(outfile, level, already_processed, namespaceprefix_, name_='Part') + if self.hasContent_(): + outfile.write('>%s' % (eol_, )) + self.exportChildren(outfile, level + 1, namespaceprefix_, namespacedef_, name_='Part', pretty_print=pretty_print) + showIndent(outfile, level, pretty_print) + outfile.write('%s' % (namespaceprefix_, name_, eol_)) + else: + outfile.write('/>%s' % (eol_, )) + def exportAttributes(self, outfile, level, already_processed, namespaceprefix_='', name_='Part'): + if self.id is not None and 'id' not in already_processed: + already_processed.add('id') + outfile.write(' id=%s' % (self.gds_encode(self.gds_format_string(quote_attrib(self.id), input_name='id')), )) + def exportChildren(self, outfile, level, namespaceprefix_='', namespacedef_='', name_='Part', fromsubclass_=False, pretty_print=True): + if pretty_print: + eol_ = '\n' + else: + eol_ = '' + if self.schema_reference is not None: + showIndent(outfile, level, pretty_print) + outfile.write('<%sschema-reference>%s%s' % (namespaceprefix_ , self.gds_encode(self.gds_format_string(quote_xml(self.schema_reference), input_name='schema-reference')), namespaceprefix_ , eol_)) + if self.part_type is not None: + showIndent(outfile, level, pretty_print) + outfile.write('<%spart-type>%s%s' % (namespaceprefix_ , self.gds_encode(self.gds_format_string(quote_xml(self.part_type), input_name='part-type')), namespaceprefix_ , eol_)) + if self.part_numbers is not None: + self.part_numbers.export(outfile, level, namespaceprefix_, namespacedef_='', name_='part-numbers', pretty_print=pretty_print) + if self.distributor_info is not None: + self.distributor_info.export(outfile, level, namespaceprefix_, namespacedef_='', name_='distributor-info', pretty_print=pretty_print) + if self.facts is not None: + self.facts.export(outfile, level, namespaceprefix_, namespacedef_='', name_='facts', pretty_print=pretty_print) + if self.price_breaks is not None: + self.price_breaks.export(outfile, level, namespaceprefix_, namespacedef_='', name_='price-breaks', pretty_print=pretty_print) + def build(self, node): + already_processed = set() + self.buildAttributes(node, node.attrib, already_processed) + for child in node: + nodeName_ = Tag_pattern_.match(child.tag).groups()[-1] + self.buildChildren(child, node, nodeName_) + return self + def buildAttributes(self, node, attrs, already_processed): + value = find_attr_value_('id', node) + if value is not None and 'id' not in already_processed: + already_processed.add('id') + self.id = value + def buildChildren(self, child_, node, nodeName_, fromsubclass_=False): + if nodeName_ == 'schema-reference': + schema_reference_ = child_.text + schema_reference_ = self.gds_validate_string(schema_reference_, node, 'schema_reference') + self.schema_reference = schema_reference_ + elif nodeName_ == 'part-type': + part_type_ = child_.text + part_type_ = self.gds_validate_string(part_type_, node, 'part_type') + self.part_type = part_type_ + elif nodeName_ == 'part-numbers': + obj_ = PartNumberList.factory(parent_object_=self) + obj_.build(child_) + self.part_numbers = obj_ + obj_.original_tagname_ = 'part-numbers' + elif nodeName_ == 'distributor-info': + obj_ = DistributorInfo.factory(parent_object_=self) + obj_.build(child_) + self.distributor_info = obj_ + obj_.original_tagname_ = 'distributor-info' + elif nodeName_ == 'facts': + obj_ = FactList.factory(parent_object_=self) + obj_.build(child_) + self.facts = obj_ + obj_.original_tagname_ = 'facts' + elif nodeName_ == 'price-breaks': + obj_ = PriceBreakList.factory(parent_object_=self) + obj_.build(child_) + self.price_breaks = obj_ + obj_.original_tagname_ = 'price-breaks' +# end class Part + + +class PartList(GeneratedsSuper): + subclass = None + superclass = None + def __init__(self, part=None, **kwargs_): + self.original_tagname_ = None + self.parent_object_ = kwargs_.get('parent_object_') + if part is None: + self.part = [] + else: + self.part = part + def factory(*args_, **kwargs_): + if CurrentSubclassModule_ is not None: + subclass = getSubclassFromModule_( + CurrentSubclassModule_, PartList) + if subclass is not None: + return subclass(*args_, **kwargs_) + if PartList.subclass: + return PartList.subclass(*args_, **kwargs_) + else: + return PartList(*args_, **kwargs_) + factory = staticmethod(factory) + def get_part(self): + return self.part + def set_part(self, part): + self.part = part + def add_part(self, value): + self.part.append(value) + def add_part(self, value): + self.part.append(value) + def insert_part_at(self, index, value): + self.part.insert(index, value) + def replace_part_at(self, index, value): + self.part[index] = value + partProp = property(get_part, set_part) + def hasContent_(self): + if ( + self.part + ): + return True + else: + return False + def export(self, outfile, level, namespaceprefix_='', namespacedef_='', name_='PartList', pretty_print=True): + imported_ns_def_ = GenerateDSNamespaceDefs_.get('PartList') + if imported_ns_def_ is not None: + namespacedef_ = imported_ns_def_ + if pretty_print: + eol_ = '\n' + else: + eol_ = '' + if self.original_tagname_ is not None: + name_ = self.original_tagname_ + showIndent(outfile, level, pretty_print) + outfile.write('<%s%s%s' % (namespaceprefix_, name_, namespacedef_ and ' ' + namespacedef_ or '', )) + already_processed = set() + self.exportAttributes(outfile, level, already_processed, namespaceprefix_, name_='PartList') + if self.hasContent_(): + outfile.write('>%s' % (eol_, )) + self.exportChildren(outfile, level + 1, namespaceprefix_, namespacedef_, name_='PartList', pretty_print=pretty_print) + showIndent(outfile, level, pretty_print) + outfile.write('%s' % (namespaceprefix_, name_, eol_)) + else: + outfile.write('/>%s' % (eol_, )) + def exportAttributes(self, outfile, level, already_processed, namespaceprefix_='', name_='PartList'): + pass + def exportChildren(self, outfile, level, namespaceprefix_='', namespacedef_='', name_='PartList', fromsubclass_=False, pretty_print=True): + if pretty_print: + eol_ = '\n' + else: + eol_ = '' + for part_ in self.part: + part_.export(outfile, level, namespaceprefix_, namespacedef_='', name_='part', pretty_print=pretty_print) + def build(self, node): + already_processed = set() + self.buildAttributes(node, node.attrib, already_processed) + for child in node: + nodeName_ = Tag_pattern_.match(child.tag).groups()[-1] + self.buildChildren(child, node, nodeName_) + return self + def buildAttributes(self, node, attrs, already_processed): + pass + def buildChildren(self, child_, node, nodeName_, fromsubclass_=False): + if nodeName_ == 'part': + obj_ = Part.factory(parent_object_=self) + obj_.build(child_) + self.part.append(obj_) + obj_.original_tagname_ = 'part' +# end class PartList + + +class PartNumber(GeneratedsSuper): + subclass = None + superclass = None + def __init__(self, value=None, distributor=None, **kwargs_): + self.original_tagname_ = None + self.parent_object_ = kwargs_.get('parent_object_') + self.value = value + self.distributor = distributor + def factory(*args_, **kwargs_): + if CurrentSubclassModule_ is not None: + subclass = getSubclassFromModule_( + CurrentSubclassModule_, PartNumber) + if subclass is not None: + return subclass(*args_, **kwargs_) + if PartNumber.subclass: + return PartNumber.subclass(*args_, **kwargs_) + else: + return PartNumber(*args_, **kwargs_) + factory = staticmethod(factory) + def get_value(self): + return self.value + def set_value(self, value): + self.value = value + valueProp = property(get_value, set_value) + def get_distributor(self): + return self.distributor + def set_distributor(self, distributor): + self.distributor = distributor + distributorProp = property(get_distributor, set_distributor) + def hasContent_(self): + if ( + self.value is not None or + self.distributor is not None + ): + return True + else: + return False + def export(self, outfile, level, namespaceprefix_='', namespacedef_='', name_='PartNumber', pretty_print=True): + imported_ns_def_ = GenerateDSNamespaceDefs_.get('PartNumber') + if imported_ns_def_ is not None: + namespacedef_ = imported_ns_def_ + if pretty_print: + eol_ = '\n' + else: + eol_ = '' + if self.original_tagname_ is not None: + name_ = self.original_tagname_ + showIndent(outfile, level, pretty_print) + outfile.write('<%s%s%s' % (namespaceprefix_, name_, namespacedef_ and ' ' + namespacedef_ or '', )) + already_processed = set() + self.exportAttributes(outfile, level, already_processed, namespaceprefix_, name_='PartNumber') + if self.hasContent_(): + outfile.write('>%s' % (eol_, )) + self.exportChildren(outfile, level + 1, namespaceprefix_, namespacedef_, name_='PartNumber', pretty_print=pretty_print) + showIndent(outfile, level, pretty_print) + outfile.write('%s' % (namespaceprefix_, name_, eol_)) + else: + outfile.write('/>%s' % (eol_, )) + def exportAttributes(self, outfile, level, already_processed, namespaceprefix_='', name_='PartNumber'): + pass + def exportChildren(self, outfile, level, namespaceprefix_='', namespacedef_='', name_='PartNumber', fromsubclass_=False, pretty_print=True): + if pretty_print: + eol_ = '\n' + else: + eol_ = '' + if self.value is not None: + showIndent(outfile, level, pretty_print) + outfile.write('<%svalue>%s%s' % (namespaceprefix_ , self.gds_encode(self.gds_format_string(quote_xml(self.value), input_name='value')), namespaceprefix_ , eol_)) + if self.distributor is not None: + showIndent(outfile, level, pretty_print) + outfile.write('<%sdistributor>%s%s' % (namespaceprefix_ , self.gds_encode(self.gds_format_string(quote_xml(self.distributor), input_name='distributor')), namespaceprefix_ , eol_)) + def build(self, node): + already_processed = set() + self.buildAttributes(node, node.attrib, already_processed) + for child in node: + nodeName_ = Tag_pattern_.match(child.tag).groups()[-1] + self.buildChildren(child, node, nodeName_) + return self + def buildAttributes(self, node, attrs, already_processed): + pass + def buildChildren(self, child_, node, nodeName_, fromsubclass_=False): + if nodeName_ == 'value': + value_ = child_.text + value_ = self.gds_validate_string(value_, node, 'value') + self.value = value_ + elif nodeName_ == 'distributor': + distributor_ = child_.text + distributor_ = self.gds_validate_string(distributor_, node, 'distributor') + self.distributor = distributor_ +# end class PartNumber + + +class PartNumberList(GeneratedsSuper): + subclass = None + superclass = None + def __init__(self, part_number=None, **kwargs_): + self.original_tagname_ = None + self.parent_object_ = kwargs_.get('parent_object_') + if part_number is None: + self.part_number = [] + else: + self.part_number = part_number + def factory(*args_, **kwargs_): + if CurrentSubclassModule_ is not None: + subclass = getSubclassFromModule_( + CurrentSubclassModule_, PartNumberList) + if subclass is not None: + return subclass(*args_, **kwargs_) + if PartNumberList.subclass: + return PartNumberList.subclass(*args_, **kwargs_) + else: + return PartNumberList(*args_, **kwargs_) + factory = staticmethod(factory) + def get_part_number(self): + return self.part_number + def set_part_number(self, part_number): + self.part_number = part_number + def add_part_number(self, value): + self.part_number.append(value) + def add_part_number(self, value): + self.part_number.append(value) + def insert_part_number_at(self, index, value): + self.part_number.insert(index, value) + def replace_part_number_at(self, index, value): + self.part_number[index] = value + part_numberProp = property(get_part_number, set_part_number) + def hasContent_(self): + if ( + self.part_number + ): + return True + else: + return False + def export(self, outfile, level, namespaceprefix_='', namespacedef_='', name_='PartNumberList', pretty_print=True): + imported_ns_def_ = GenerateDSNamespaceDefs_.get('PartNumberList') + if imported_ns_def_ is not None: + namespacedef_ = imported_ns_def_ + if pretty_print: + eol_ = '\n' + else: + eol_ = '' + if self.original_tagname_ is not None: + name_ = self.original_tagname_ + showIndent(outfile, level, pretty_print) + outfile.write('<%s%s%s' % (namespaceprefix_, name_, namespacedef_ and ' ' + namespacedef_ or '', )) + already_processed = set() + self.exportAttributes(outfile, level, already_processed, namespaceprefix_, name_='PartNumberList') + if self.hasContent_(): + outfile.write('>%s' % (eol_, )) + self.exportChildren(outfile, level + 1, namespaceprefix_, namespacedef_, name_='PartNumberList', pretty_print=pretty_print) + showIndent(outfile, level, pretty_print) + outfile.write('%s' % (namespaceprefix_, name_, eol_)) + else: + outfile.write('/>%s' % (eol_, )) + def exportAttributes(self, outfile, level, already_processed, namespaceprefix_='', name_='PartNumberList'): + pass + def exportChildren(self, outfile, level, namespaceprefix_='', namespacedef_='', name_='PartNumberList', fromsubclass_=False, pretty_print=True): + if pretty_print: + eol_ = '\n' + else: + eol_ = '' + for part_number_ in self.part_number: + part_number_.export(outfile, level, namespaceprefix_, namespacedef_='', name_='part-number', pretty_print=pretty_print) + def build(self, node): + already_processed = set() + self.buildAttributes(node, node.attrib, already_processed) + for child in node: + nodeName_ = Tag_pattern_.match(child.tag).groups()[-1] + self.buildChildren(child, node, nodeName_) + return self + def buildAttributes(self, node, attrs, already_processed): + pass + def buildChildren(self, child_, node, nodeName_, fromsubclass_=False): + if nodeName_ == 'part-number': + obj_ = PartNumber.factory(parent_object_=self) + obj_.build(child_) + self.part_number.append(obj_) + obj_.original_tagname_ = 'part-number' +# end class PartNumberList + + +class Fact(GeneratedsSuper): + subclass = None + superclass = None + def __init__(self, key=None, label=None, value=None, **kwargs_): + self.original_tagname_ = None + self.parent_object_ = kwargs_.get('parent_object_') + self.key = key + self.label = label + self.value = value + def factory(*args_, **kwargs_): + if CurrentSubclassModule_ is not None: + subclass = getSubclassFromModule_( + CurrentSubclassModule_, Fact) + if subclass is not None: + return subclass(*args_, **kwargs_) + if Fact.subclass: + return Fact.subclass(*args_, **kwargs_) + else: + return Fact(*args_, **kwargs_) + factory = staticmethod(factory) + def get_key(self): + return self.key + def set_key(self, key): + self.key = key + keyProp = property(get_key, set_key) + def get_label(self): + return self.label + def set_label(self, label): + self.label = label + labelProp = property(get_label, set_label) + def get_value(self): + return self.value + def set_value(self, value): + self.value = value + valueProp = property(get_value, set_value) + def hasContent_(self): + if ( + self.key is not None or + self.label is not None or + self.value is not None + ): + return True + else: + return False + def export(self, outfile, level, namespaceprefix_='', namespacedef_='', name_='Fact', pretty_print=True): + imported_ns_def_ = GenerateDSNamespaceDefs_.get('Fact') + if imported_ns_def_ is not None: + namespacedef_ = imported_ns_def_ + if pretty_print: + eol_ = '\n' + else: + eol_ = '' + if self.original_tagname_ is not None: + name_ = self.original_tagname_ + showIndent(outfile, level, pretty_print) + outfile.write('<%s%s%s' % (namespaceprefix_, name_, namespacedef_ and ' ' + namespacedef_ or '', )) + already_processed = set() + self.exportAttributes(outfile, level, already_processed, namespaceprefix_, name_='Fact') + if self.hasContent_(): + outfile.write('>%s' % (eol_, )) + self.exportChildren(outfile, level + 1, namespaceprefix_, namespacedef_, name_='Fact', pretty_print=pretty_print) + showIndent(outfile, level, pretty_print) + outfile.write('%s' % (namespaceprefix_, name_, eol_)) + else: + outfile.write('/>%s' % (eol_, )) + def exportAttributes(self, outfile, level, already_processed, namespaceprefix_='', name_='Fact'): + pass + def exportChildren(self, outfile, level, namespaceprefix_='', namespacedef_='', name_='Fact', fromsubclass_=False, pretty_print=True): + if pretty_print: + eol_ = '\n' + else: + eol_ = '' + if self.key is not None: + showIndent(outfile, level, pretty_print) + outfile.write('<%skey>%s%s' % (namespaceprefix_ , self.gds_encode(self.gds_format_string(quote_xml(self.key), input_name='key')), namespaceprefix_ , eol_)) + if self.label is not None: + showIndent(outfile, level, pretty_print) + outfile.write('<%slabel>%s%s' % (namespaceprefix_ , self.gds_encode(self.gds_format_string(quote_xml(self.label), input_name='label')), namespaceprefix_ , eol_)) + if self.value is not None: + showIndent(outfile, level, pretty_print) + outfile.write('<%svalue>%s%s' % (namespaceprefix_ , self.gds_encode(self.gds_format_string(quote_xml(self.value), input_name='value')), namespaceprefix_ , eol_)) + def build(self, node): + already_processed = set() + self.buildAttributes(node, node.attrib, already_processed) + for child in node: + nodeName_ = Tag_pattern_.match(child.tag).groups()[-1] + self.buildChildren(child, node, nodeName_) + return self + def buildAttributes(self, node, attrs, already_processed): + pass + def buildChildren(self, child_, node, nodeName_, fromsubclass_=False): + if nodeName_ == 'key': + key_ = child_.text + key_ = self.gds_validate_string(key_, node, 'key') + self.key = key_ + elif nodeName_ == 'label': + label_ = child_.text + label_ = self.gds_validate_string(label_, node, 'label') + self.label = label_ + elif nodeName_ == 'value': + value_ = child_.text + value_ = self.gds_validate_string(value_, node, 'value') + self.value = value_ +# end class Fact + + +class FactList(GeneratedsSuper): + subclass = None + superclass = None + def __init__(self, fact=None, **kwargs_): + self.original_tagname_ = None + self.parent_object_ = kwargs_.get('parent_object_') + if fact is None: + self.fact = [] + else: + self.fact = fact + def factory(*args_, **kwargs_): + if CurrentSubclassModule_ is not None: + subclass = getSubclassFromModule_( + CurrentSubclassModule_, FactList) + if subclass is not None: + return subclass(*args_, **kwargs_) + if FactList.subclass: + return FactList.subclass(*args_, **kwargs_) + else: + return FactList(*args_, **kwargs_) + factory = staticmethod(factory) + def get_fact(self): + return self.fact + def set_fact(self, fact): + self.fact = fact + def add_fact(self, value): + self.fact.append(value) + def add_fact(self, value): + self.fact.append(value) + def insert_fact_at(self, index, value): + self.fact.insert(index, value) + def replace_fact_at(self, index, value): + self.fact[index] = value + factProp = property(get_fact, set_fact) + def hasContent_(self): + if ( + self.fact + ): + return True + else: + return False + def export(self, outfile, level, namespaceprefix_='', namespacedef_='', name_='FactList', pretty_print=True): + imported_ns_def_ = GenerateDSNamespaceDefs_.get('FactList') + if imported_ns_def_ is not None: + namespacedef_ = imported_ns_def_ + if pretty_print: + eol_ = '\n' + else: + eol_ = '' + if self.original_tagname_ is not None: + name_ = self.original_tagname_ + showIndent(outfile, level, pretty_print) + outfile.write('<%s%s%s' % (namespaceprefix_, name_, namespacedef_ and ' ' + namespacedef_ or '', )) + already_processed = set() + self.exportAttributes(outfile, level, already_processed, namespaceprefix_, name_='FactList') + if self.hasContent_(): + outfile.write('>%s' % (eol_, )) + self.exportChildren(outfile, level + 1, namespaceprefix_, namespacedef_, name_='FactList', pretty_print=pretty_print) + showIndent(outfile, level, pretty_print) + outfile.write('%s' % (namespaceprefix_, name_, eol_)) + else: + outfile.write('/>%s' % (eol_, )) + def exportAttributes(self, outfile, level, already_processed, namespaceprefix_='', name_='FactList'): + pass + def exportChildren(self, outfile, level, namespaceprefix_='', namespacedef_='', name_='FactList', fromsubclass_=False, pretty_print=True): + if pretty_print: + eol_ = '\n' + else: + eol_ = '' + for fact_ in self.fact: + fact_.export(outfile, level, namespaceprefix_, namespacedef_='', name_='fact', pretty_print=pretty_print) + def build(self, node): + already_processed = set() + self.buildAttributes(node, node.attrib, already_processed) + for child in node: + nodeName_ = Tag_pattern_.match(child.tag).groups()[-1] + self.buildChildren(child, node, nodeName_) + return self + def buildAttributes(self, node, attrs, already_processed): + pass + def buildChildren(self, child_, node, nodeName_, fromsubclass_=False): + if nodeName_ == 'fact': + obj_ = Fact.factory(parent_object_=self) + obj_.build(child_) + self.fact.append(obj_) + obj_.original_tagname_ = 'fact' +# end class FactList + + +class DistributorInfo(GeneratedsSuper): + subclass = None + superclass = None + def __init__(self, state=None, **kwargs_): + self.original_tagname_ = None + self.parent_object_ = kwargs_.get('parent_object_') + self.state = state + def factory(*args_, **kwargs_): + if CurrentSubclassModule_ is not None: + subclass = getSubclassFromModule_( + CurrentSubclassModule_, DistributorInfo) + if subclass is not None: + return subclass(*args_, **kwargs_) + if DistributorInfo.subclass: + return DistributorInfo.subclass(*args_, **kwargs_) + else: + return DistributorInfo(*args_, **kwargs_) + factory = staticmethod(factory) + def get_state(self): + return self.state + def set_state(self, state): + self.state = state + stateProp = property(get_state, set_state) + def hasContent_(self): + if ( + self.state is not None + ): + return True + else: + return False + def export(self, outfile, level, namespaceprefix_='', namespacedef_='', name_='DistributorInfo', pretty_print=True): + imported_ns_def_ = GenerateDSNamespaceDefs_.get('DistributorInfo') + if imported_ns_def_ is not None: + namespacedef_ = imported_ns_def_ + if pretty_print: + eol_ = '\n' + else: + eol_ = '' + if self.original_tagname_ is not None: + name_ = self.original_tagname_ + showIndent(outfile, level, pretty_print) + outfile.write('<%s%s%s' % (namespaceprefix_, name_, namespacedef_ and ' ' + namespacedef_ or '', )) + already_processed = set() + self.exportAttributes(outfile, level, already_processed, namespaceprefix_, name_='DistributorInfo') + if self.hasContent_(): + outfile.write('>%s' % (eol_, )) + self.exportChildren(outfile, level + 1, namespaceprefix_, namespacedef_, name_='DistributorInfo', pretty_print=pretty_print) + showIndent(outfile, level, pretty_print) + outfile.write('%s' % (namespaceprefix_, name_, eol_)) + else: + outfile.write('/>%s' % (eol_, )) + def exportAttributes(self, outfile, level, already_processed, namespaceprefix_='', name_='DistributorInfo'): + pass + def exportChildren(self, outfile, level, namespaceprefix_='', namespacedef_='', name_='DistributorInfo', fromsubclass_=False, pretty_print=True): + if pretty_print: + eol_ = '\n' + else: + eol_ = '' + if self.state is not None: + showIndent(outfile, level, pretty_print) + outfile.write('<%sstate>%s%s' % (namespaceprefix_ , self.gds_encode(self.gds_format_string(quote_xml(self.state), input_name='state')), namespaceprefix_ , eol_)) + def build(self, node): + already_processed = set() + self.buildAttributes(node, node.attrib, already_processed) + for child in node: + nodeName_ = Tag_pattern_.match(child.tag).groups()[-1] + self.buildChildren(child, node, nodeName_) + return self + def buildAttributes(self, node, attrs, already_processed): + pass + def buildChildren(self, child_, node, nodeName_, fromsubclass_=False): + if nodeName_ == 'state': + state_ = child_.text + state_ = self.gds_validate_string(state_, node, 'state') + self.state = state_ +# end class DistributorInfo + + +class Amount(GeneratedsSuper): + subclass = None + superclass = None + def __init__(self, value=None, currency=None, **kwargs_): + self.original_tagname_ = None + self.parent_object_ = kwargs_.get('parent_object_') + self.value = _cast(None, value) + self.currency = _cast(None, currency) + def factory(*args_, **kwargs_): + if CurrentSubclassModule_ is not None: + subclass = getSubclassFromModule_( + CurrentSubclassModule_, Amount) + if subclass is not None: + return subclass(*args_, **kwargs_) + if Amount.subclass: + return Amount.subclass(*args_, **kwargs_) + else: + return Amount(*args_, **kwargs_) + factory = staticmethod(factory) + def get_value(self): + return self.value + def set_value(self, value): + self.value = value + valueProp = property(get_value, set_value) + def get_currency(self): + return self.currency + def set_currency(self, currency): + self.currency = currency + currencyProp = property(get_currency, set_currency) + def hasContent_(self): + if ( + + ): + return True + else: + return False + def export(self, outfile, level, namespaceprefix_='', namespacedef_='', name_='Amount', pretty_print=True): + imported_ns_def_ = GenerateDSNamespaceDefs_.get('Amount') + if imported_ns_def_ is not None: + namespacedef_ = imported_ns_def_ + if pretty_print: + eol_ = '\n' + else: + eol_ = '' + if self.original_tagname_ is not None: + name_ = self.original_tagname_ + showIndent(outfile, level, pretty_print) + outfile.write('<%s%s%s' % (namespaceprefix_, name_, namespacedef_ and ' ' + namespacedef_ or '', )) + already_processed = set() + self.exportAttributes(outfile, level, already_processed, namespaceprefix_, name_='Amount') + if self.hasContent_(): + outfile.write('>%s' % (eol_, )) + self.exportChildren(outfile, level + 1, namespaceprefix_, namespacedef_, name_='Amount', pretty_print=pretty_print) + outfile.write('%s' % (namespaceprefix_, name_, eol_)) + else: + outfile.write('/>%s' % (eol_, )) + def exportAttributes(self, outfile, level, already_processed, namespaceprefix_='', name_='Amount'): + if self.value is not None and 'value' not in already_processed: + already_processed.add('value') + outfile.write(' value=%s' % (self.gds_encode(self.gds_format_string(quote_attrib(self.value), input_name='value')), )) + if self.currency is not None and 'currency' not in already_processed: + already_processed.add('currency') + outfile.write(' currency=%s' % (self.gds_encode(self.gds_format_string(quote_attrib(self.currency), input_name='currency')), )) + def exportChildren(self, outfile, level, namespaceprefix_='', namespacedef_='', name_='Amount', fromsubclass_=False, pretty_print=True): + pass + def build(self, node): + already_processed = set() + self.buildAttributes(node, node.attrib, already_processed) + for child in node: + nodeName_ = Tag_pattern_.match(child.tag).groups()[-1] + self.buildChildren(child, node, nodeName_) + return self + def buildAttributes(self, node, attrs, already_processed): + value = find_attr_value_('value', node) + if value is not None and 'value' not in already_processed: + already_processed.add('value') + self.value = value + value = find_attr_value_('currency', node) + if value is not None and 'currency' not in already_processed: + already_processed.add('currency') + self.currency = value + def buildChildren(self, child_, node, nodeName_, fromsubclass_=False): + pass +# end class Amount + + +class PriceBreak(GeneratedsSuper): + subclass = None + superclass = None + def __init__(self, quantity=None, amount=None, **kwargs_): + self.original_tagname_ = None + self.parent_object_ = kwargs_.get('parent_object_') + self.quantity = quantity + self.amount = amount + def factory(*args_, **kwargs_): + if CurrentSubclassModule_ is not None: + subclass = getSubclassFromModule_( + CurrentSubclassModule_, PriceBreak) + if subclass is not None: + return subclass(*args_, **kwargs_) + if PriceBreak.subclass: + return PriceBreak.subclass(*args_, **kwargs_) + else: + return PriceBreak(*args_, **kwargs_) + factory = staticmethod(factory) + def get_quantity(self): + return self.quantity + def set_quantity(self, quantity): + self.quantity = quantity + quantityProp = property(get_quantity, set_quantity) + def get_amount(self): + return self.amount + def set_amount(self, amount): + self.amount = amount + amountProp = property(get_amount, set_amount) + def hasContent_(self): + if ( + self.quantity is not None or + self.amount is not None + ): + return True + else: + return False + def export(self, outfile, level, namespaceprefix_='', namespacedef_='', name_='PriceBreak', pretty_print=True): + imported_ns_def_ = GenerateDSNamespaceDefs_.get('PriceBreak') + if imported_ns_def_ is not None: + namespacedef_ = imported_ns_def_ + if pretty_print: + eol_ = '\n' + else: + eol_ = '' + if self.original_tagname_ is not None: + name_ = self.original_tagname_ + showIndent(outfile, level, pretty_print) + outfile.write('<%s%s%s' % (namespaceprefix_, name_, namespacedef_ and ' ' + namespacedef_ or '', )) + already_processed = set() + self.exportAttributes(outfile, level, already_processed, namespaceprefix_, name_='PriceBreak') + if self.hasContent_(): + outfile.write('>%s' % (eol_, )) + self.exportChildren(outfile, level + 1, namespaceprefix_, namespacedef_, name_='PriceBreak', pretty_print=pretty_print) + showIndent(outfile, level, pretty_print) + outfile.write('%s' % (namespaceprefix_, name_, eol_)) + else: + outfile.write('/>%s' % (eol_, )) + def exportAttributes(self, outfile, level, already_processed, namespaceprefix_='', name_='PriceBreak'): + pass + def exportChildren(self, outfile, level, namespaceprefix_='', namespacedef_='', name_='PriceBreak', fromsubclass_=False, pretty_print=True): + if pretty_print: + eol_ = '\n' + else: + eol_ = '' + if self.quantity is not None: + showIndent(outfile, level, pretty_print) + outfile.write('<%squantity>%s%s' % (namespaceprefix_ , self.gds_encode(self.gds_format_string(quote_xml(self.quantity), input_name='quantity')), namespaceprefix_ , eol_)) + if self.amount is not None: + self.amount.export(outfile, level, namespaceprefix_, namespacedef_='', name_='amount', pretty_print=pretty_print) + def build(self, node): + already_processed = set() + self.buildAttributes(node, node.attrib, already_processed) + for child in node: + nodeName_ = Tag_pattern_.match(child.tag).groups()[-1] + self.buildChildren(child, node, nodeName_) + return self + def buildAttributes(self, node, attrs, already_processed): + pass + def buildChildren(self, child_, node, nodeName_, fromsubclass_=False): + if nodeName_ == 'quantity': + quantity_ = child_.text + quantity_ = self.gds_validate_string(quantity_, node, 'quantity') + self.quantity = quantity_ + elif nodeName_ == 'amount': + obj_ = Amount.factory(parent_object_=self) + obj_.build(child_) + self.amount = obj_ + obj_.original_tagname_ = 'amount' +# end class PriceBreak + + +class PriceBreakList(GeneratedsSuper): + subclass = None + superclass = None + def __init__(self, price_break=None, **kwargs_): + self.original_tagname_ = None + self.parent_object_ = kwargs_.get('parent_object_') + if price_break is None: + self.price_break = [] + else: + self.price_break = price_break + def factory(*args_, **kwargs_): + if CurrentSubclassModule_ is not None: + subclass = getSubclassFromModule_( + CurrentSubclassModule_, PriceBreakList) + if subclass is not None: + return subclass(*args_, **kwargs_) + if PriceBreakList.subclass: + return PriceBreakList.subclass(*args_, **kwargs_) + else: + return PriceBreakList(*args_, **kwargs_) + factory = staticmethod(factory) + def get_price_break(self): + return self.price_break + def set_price_break(self, price_break): + self.price_break = price_break + def add_price_break(self, value): + self.price_break.append(value) + def add_price_break(self, value): + self.price_break.append(value) + def insert_price_break_at(self, index, value): + self.price_break.insert(index, value) + def replace_price_break_at(self, index, value): + self.price_break[index] = value + price_breakProp = property(get_price_break, set_price_break) + def hasContent_(self): + if ( + self.price_break + ): + return True + else: + return False + def export(self, outfile, level, namespaceprefix_='', namespacedef_='', name_='PriceBreakList', pretty_print=True): + imported_ns_def_ = GenerateDSNamespaceDefs_.get('PriceBreakList') + if imported_ns_def_ is not None: + namespacedef_ = imported_ns_def_ + if pretty_print: + eol_ = '\n' + else: + eol_ = '' + if self.original_tagname_ is not None: + name_ = self.original_tagname_ + showIndent(outfile, level, pretty_print) + outfile.write('<%s%s%s' % (namespaceprefix_, name_, namespacedef_ and ' ' + namespacedef_ or '', )) + already_processed = set() + self.exportAttributes(outfile, level, already_processed, namespaceprefix_, name_='PriceBreakList') + if self.hasContent_(): + outfile.write('>%s' % (eol_, )) + self.exportChildren(outfile, level + 1, namespaceprefix_, namespacedef_, name_='PriceBreakList', pretty_print=pretty_print) + showIndent(outfile, level, pretty_print) + outfile.write('%s' % (namespaceprefix_, name_, eol_)) + else: + outfile.write('/>%s' % (eol_, )) + def exportAttributes(self, outfile, level, already_processed, namespaceprefix_='', name_='PriceBreakList'): + pass + def exportChildren(self, outfile, level, namespaceprefix_='', namespacedef_='', name_='PriceBreakList', fromsubclass_=False, pretty_print=True): + if pretty_print: + eol_ = '\n' + else: + eol_ = '' + for price_break_ in self.price_break: + price_break_.export(outfile, level, namespaceprefix_, namespacedef_='', name_='price-break', pretty_print=pretty_print) + def build(self, node): + already_processed = set() + self.buildAttributes(node, node.attrib, already_processed) + for child in node: + nodeName_ = Tag_pattern_.match(child.tag).groups()[-1] + self.buildChildren(child, node, nodeName_) + return self + def buildAttributes(self, node, attrs, already_processed): + pass + def buildChildren(self, child_, node, nodeName_, fromsubclass_=False): + if nodeName_ == 'price-break': + obj_ = PriceBreak.factory(parent_object_=self) + obj_.build(child_) + self.price_break.append(obj_) + obj_.original_tagname_ = 'price-break' +# end class PriceBreakList + + +class IndexFile(GeneratedsSuper): + subclass = None + superclass = None + def __init__(self, files=None, **kwargs_): + self.original_tagname_ = None + self.parent_object_ = kwargs_.get('parent_object_') + self.files = files + def factory(*args_, **kwargs_): + if CurrentSubclassModule_ is not None: + subclass = getSubclassFromModule_( + CurrentSubclassModule_, IndexFile) + if subclass is not None: + return subclass(*args_, **kwargs_) + if IndexFile.subclass: + return IndexFile.subclass(*args_, **kwargs_) + else: + return IndexFile(*args_, **kwargs_) + factory = staticmethod(factory) + def get_files(self): + return self.files + def set_files(self, files): + self.files = files + filesProp = property(get_files, set_files) + def hasContent_(self): + if ( + self.files is not None + ): + return True + else: + return False + def export(self, outfile, level, namespaceprefix_='', namespacedef_='', name_='IndexFile', pretty_print=True): + imported_ns_def_ = GenerateDSNamespaceDefs_.get('IndexFile') + if imported_ns_def_ is not None: + namespacedef_ = imported_ns_def_ + if pretty_print: + eol_ = '\n' + else: + eol_ = '' + if self.original_tagname_ is not None: + name_ = self.original_tagname_ + showIndent(outfile, level, pretty_print) + outfile.write('<%s%s%s' % (namespaceprefix_, name_, namespacedef_ and ' ' + namespacedef_ or '', )) + already_processed = set() + self.exportAttributes(outfile, level, already_processed, namespaceprefix_, name_='IndexFile') + if self.hasContent_(): + outfile.write('>%s' % (eol_, )) + self.exportChildren(outfile, level + 1, namespaceprefix_, namespacedef_, name_='IndexFile', pretty_print=pretty_print) + showIndent(outfile, level, pretty_print) + outfile.write('%s' % (namespaceprefix_, name_, eol_)) + else: + outfile.write('/>%s' % (eol_, )) + def exportAttributes(self, outfile, level, already_processed, namespaceprefix_='', name_='IndexFile'): + pass + def exportChildren(self, outfile, level, namespaceprefix_='', namespacedef_='', name_='IndexFile', fromsubclass_=False, pretty_print=True): + if pretty_print: + eol_ = '\n' + else: + eol_ = '' + if self.files is not None: + self.files.export(outfile, level, namespaceprefix_, namespacedef_='', name_='files', pretty_print=pretty_print) + def build(self, node): + already_processed = set() + self.buildAttributes(node, node.attrib, already_processed) + for child in node: + nodeName_ = Tag_pattern_.match(child.tag).groups()[-1] + self.buildChildren(child, node, nodeName_) + return self + def buildAttributes(self, node, attrs, already_processed): + pass + def buildChildren(self, child_, node, nodeName_, fromsubclass_=False): + if nodeName_ == 'files': + obj_ = FileList.factory(parent_object_=self) + obj_.build(child_) + self.files = obj_ + obj_.original_tagname_ = 'files' +# end class IndexFile + + +class File(GeneratedsSuper): + subclass = None + superclass = None + def __init__(self, path=None, **kwargs_): + self.original_tagname_ = None + self.parent_object_ = kwargs_.get('parent_object_') + self.path = _cast(None, path) + def factory(*args_, **kwargs_): + if CurrentSubclassModule_ is not None: + subclass = getSubclassFromModule_( + CurrentSubclassModule_, File) + if subclass is not None: + return subclass(*args_, **kwargs_) + if File.subclass: + return File.subclass(*args_, **kwargs_) + else: + return File(*args_, **kwargs_) + factory = staticmethod(factory) + def get_path(self): + return self.path + def set_path(self, path): + self.path = path + pathProp = property(get_path, set_path) + def hasContent_(self): + if ( + + ): + return True + else: + return False + def export(self, outfile, level, namespaceprefix_='', namespacedef_='', name_='File', pretty_print=True): + imported_ns_def_ = GenerateDSNamespaceDefs_.get('File') + if imported_ns_def_ is not None: + namespacedef_ = imported_ns_def_ + if pretty_print: + eol_ = '\n' + else: + eol_ = '' + if self.original_tagname_ is not None: + name_ = self.original_tagname_ + showIndent(outfile, level, pretty_print) + outfile.write('<%s%s%s' % (namespaceprefix_, name_, namespacedef_ and ' ' + namespacedef_ or '', )) + already_processed = set() + self.exportAttributes(outfile, level, already_processed, namespaceprefix_, name_='File') + if self.hasContent_(): + outfile.write('>%s' % (eol_, )) + self.exportChildren(outfile, level + 1, namespaceprefix_, namespacedef_, name_='File', pretty_print=pretty_print) + outfile.write('%s' % (namespaceprefix_, name_, eol_)) + else: + outfile.write('/>%s' % (eol_, )) + def exportAttributes(self, outfile, level, already_processed, namespaceprefix_='', name_='File'): + if self.path is not None and 'path' not in already_processed: + already_processed.add('path') + outfile.write(' path=%s' % (self.gds_encode(self.gds_format_string(quote_attrib(self.path), input_name='path')), )) + def exportChildren(self, outfile, level, namespaceprefix_='', namespacedef_='', name_='File', fromsubclass_=False, pretty_print=True): + pass + def build(self, node): + already_processed = set() + self.buildAttributes(node, node.attrib, already_processed) + for child in node: + nodeName_ = Tag_pattern_.match(child.tag).groups()[-1] + self.buildChildren(child, node, nodeName_) + return self + def buildAttributes(self, node, attrs, already_processed): + value = find_attr_value_('path', node) + if value is not None and 'path' not in already_processed: + already_processed.add('path') + self.path = value + def buildChildren(self, child_, node, nodeName_, fromsubclass_=False): + pass +# end class File + + +class FileList(GeneratedsSuper): + subclass = None + superclass = None + def __init__(self, file=None, **kwargs_): + self.original_tagname_ = None + self.parent_object_ = kwargs_.get('parent_object_') + if file is None: + self.file = [] + else: + self.file = file + def factory(*args_, **kwargs_): + if CurrentSubclassModule_ is not None: + subclass = getSubclassFromModule_( + CurrentSubclassModule_, FileList) + if subclass is not None: + return subclass(*args_, **kwargs_) + if FileList.subclass: + return FileList.subclass(*args_, **kwargs_) + else: + return FileList(*args_, **kwargs_) + factory = staticmethod(factory) + def get_file(self): + return self.file + def set_file(self, file): + self.file = file + def add_file(self, value): + self.file.append(value) + def add_file(self, value): + self.file.append(value) + def insert_file_at(self, index, value): + self.file.insert(index, value) + def replace_file_at(self, index, value): + self.file[index] = value + fileProp = property(get_file, set_file) + def hasContent_(self): + if ( + self.file + ): + return True + else: + return False + def export(self, outfile, level, namespaceprefix_='', namespacedef_='', name_='FileList', pretty_print=True): + imported_ns_def_ = GenerateDSNamespaceDefs_.get('FileList') + if imported_ns_def_ is not None: + namespacedef_ = imported_ns_def_ + if pretty_print: + eol_ = '\n' + else: + eol_ = '' + if self.original_tagname_ is not None: + name_ = self.original_tagname_ + showIndent(outfile, level, pretty_print) + outfile.write('<%s%s%s' % (namespaceprefix_, name_, namespacedef_ and ' ' + namespacedef_ or '', )) + already_processed = set() + self.exportAttributes(outfile, level, already_processed, namespaceprefix_, name_='FileList') + if self.hasContent_(): + outfile.write('>%s' % (eol_, )) + self.exportChildren(outfile, level + 1, namespaceprefix_, namespacedef_, name_='FileList', pretty_print=pretty_print) + showIndent(outfile, level, pretty_print) + outfile.write('%s' % (namespaceprefix_, name_, eol_)) + else: + outfile.write('/>%s' % (eol_, )) + def exportAttributes(self, outfile, level, already_processed, namespaceprefix_='', name_='FileList'): + pass + def exportChildren(self, outfile, level, namespaceprefix_='', namespacedef_='', name_='FileList', fromsubclass_=False, pretty_print=True): + if pretty_print: + eol_ = '\n' + else: + eol_ = '' + for file_ in self.file: + file_.export(outfile, level, namespaceprefix_, namespacedef_='', name_='file', pretty_print=pretty_print) + def build(self, node): + already_processed = set() + self.buildAttributes(node, node.attrib, already_processed) + for child in node: + nodeName_ = Tag_pattern_.match(child.tag).groups()[-1] + self.buildChildren(child, node, nodeName_) + return self + def buildAttributes(self, node, attrs, already_processed): + pass + def buildChildren(self, child_, node, nodeName_, fromsubclass_=False): + if nodeName_ == 'file': + obj_ = File.factory(parent_object_=self) + obj_.build(child_) + self.file.append(obj_) + obj_.original_tagname_ = 'file' +# end class FileList + + +GDSClassesMapping = { + 'file-index': IndexFile, + 'part': Part, + 'part-collection': PartCollection, +} + + +USAGE_TEXT = """ +Usage: python .py [ -s ] +""" + + +def usage(): + print(USAGE_TEXT) + sys.exit(1) + + +def get_root_tag(node): + tag = Tag_pattern_.match(node.tag).groups()[-1] + rootClass = GDSClassesMapping.get(tag) + if rootClass is None: + rootClass = globals().get(tag) + return tag, rootClass + + +def parse(inFileName, silence=False): + parser = None + doc = parsexml_(inFileName, parser) + rootNode = doc.getroot() + rootTag, rootClass = get_root_tag(rootNode) + if rootClass is None: + rootTag = 'PartCollection' + rootClass = PartCollection + rootObj = rootClass.factory() + rootObj.build(rootNode) + # Enable Python to collect the space used by the DOM. + doc = None + if not silence: + sys.stdout.write('\n') + rootObj.export( + sys.stdout, 0, name_=rootTag, + namespacedef_='', + pretty_print=True) + return rootObj + + +def parseEtree(inFileName, silence=False): + parser = None + doc = parsexml_(inFileName, parser) + rootNode = doc.getroot() + rootTag, rootClass = get_root_tag(rootNode) + if rootClass is None: + rootTag = 'PartCollection' + rootClass = PartCollection + rootObj = rootClass.factory() + rootObj.build(rootNode) + # Enable Python to collect the space used by the DOM. + doc = None + mapping = {} + rootElement = rootObj.to_etree(None, name_=rootTag, mapping_=mapping) + reverse_mapping = rootObj.gds_reverse_node_mapping(mapping) + if not silence: + content = etree_.tostring( + rootElement, pretty_print=True, + xml_declaration=True, encoding="utf-8") + sys.stdout.write(content) + sys.stdout.write('\n') + return rootObj, rootElement, mapping, reverse_mapping + + +def parseString(inString, silence=False): + '''Parse a string, create the object tree, and export it. + + Arguments: + - inString -- A string. This XML fragment should not start + with an XML declaration containing an encoding. + - silence -- A boolean. If False, export the object. + Returns -- The root object in the tree. + ''' + parser = None + rootNode= parsexmlstring_(inString, parser) + rootTag, rootClass = get_root_tag(rootNode) + if rootClass is None: + rootTag = 'PartCollection' + rootClass = PartCollection + rootObj = rootClass.factory() + rootObj.build(rootNode) + # Enable Python to collect the space used by the DOM. + if not silence: + sys.stdout.write('\n') + rootObj.export( + sys.stdout, 0, name_=rootTag, + namespacedef_='') + return rootObj + + +def parseLiteral(inFileName, silence=False): + parser = None + doc = parsexml_(inFileName, parser) + rootNode = doc.getroot() + rootTag, rootClass = get_root_tag(rootNode) + if rootClass is None: + rootTag = 'PartCollection' + rootClass = PartCollection + rootObj = rootClass.factory() + rootObj.build(rootNode) + # Enable Python to collect the space used by the DOM. + doc = None + if not silence: + sys.stdout.write('#from types import *\n\n') + sys.stdout.write('import types as model_\n\n') + sys.stdout.write('rootObj = model_.rootClass(\n') + rootObj.exportLiteral(sys.stdout, 0, name_=rootTag) + sys.stdout.write(')\n') + return rootObj + + +def main(): + args = sys.argv[1:] + if len(args) == 1: + parse(args[0]) + else: + usage() + + +if __name__ == '__main__': + #import pdb; pdb.set_trace() + main() + + +__all__ = [ + "Amount", + "DistributorInfo", + "Fact", + "FactList", + "File", + "FileList", + "IndexFile", + "Part", + "PartCollection", + "PartList", + "PartNumber", + "PartNumberList", + "PriceBreak", + "PriceBreakList" +] -- cgit v1.2.3