diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000000000000000000000000000000000000..0d20b6487c61e7d1bde93acf4a14b7a89083a16d --- /dev/null +++ b/.gitignore @@ -0,0 +1 @@ +*.pyc diff --git a/commcore.py b/commcore.py new file mode 100644 index 0000000000000000000000000000000000000000..f312aff65a0cf775949713f7d6172879f3e3bb9a --- /dev/null +++ b/commcore.py @@ -0,0 +1,1095 @@ +#!/usr/bin/env python +# -*- coding: utf-8 -*- + +# +# Generated Mon Jun 8 19:20:10 2015 by generateDS.py version 2.13a. +# +# Command line options: +# ('-o', 'commcore.py') +# ('--namespacedef', 'xmlns="http://kwarc.info/sally/comm/core"') +# +# Command line arguments: +# core.xsd +# +# Command line: +# /usr/local/bin/generateDS.py -o "commcore.py" --namespacedef="xmlns="http://kwarc.info/sally/comm/core"" core.xsd +# +# Current working directory (os.getcwd()): +# client-python +# + +import sys +import getopt +import re as re_ +import base64 +import datetime as datetime_ + +etree_ = None +Verbose_import_ = False +( + XMLParser_import_none, XMLParser_import_lxml, + XMLParser_import_elementtree +) = range(3) +XMLParser_import_library = None +try: + # lxml + from lxml import etree as etree_ + XMLParser_import_library = XMLParser_import_lxml + if Verbose_import_: + print("running with lxml.etree") +except ImportError: + try: + # cElementTree from Python 2.5+ + import xml.etree.cElementTree as etree_ + XMLParser_import_library = XMLParser_import_elementtree + if Verbose_import_: + print("running with cElementTree on Python 2.5+") + except ImportError: + try: + # ElementTree from Python 2.5+ + import xml.etree.ElementTree as etree_ + XMLParser_import_library = XMLParser_import_elementtree + if Verbose_import_: + print("running with ElementTree on Python 2.5+") + except ImportError: + try: + # normal cElementTree install + import cElementTree as etree_ + XMLParser_import_library = XMLParser_import_elementtree + if Verbose_import_: + print("running with cElementTree") + except ImportError: + try: + # normal ElementTree install + import elementtree.ElementTree as etree_ + XMLParser_import_library = XMLParser_import_elementtree + if Verbose_import_: + print("running with ElementTree") + except ImportError: + raise ImportError( + "Failed to import ElementTree from any known place") + + +def parsexml_(*args, **kwargs): + if (XMLParser_import_library == XMLParser_import_lxml and + 'parser' not in kwargs): + # Use the lxml ElementTree compatible parser so that, e.g., + # we ignore comments. + kwargs['parser'] = etree_.ETCompatXMLParser() + doc = etree_.parse(*args, **kwargs) + return doc + +# +# User methods +# +# 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, 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, 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, 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, input_name=''): + return input_data + def gds_format_integer_list(self, input_data, input_name=''): + return '%s' % input_data + def gds_validate_integer_list(self, input_data, node, input_name=''): + values = input_data.split() + for value in values: + try: + float(value) + except (TypeError, ValueError): + raise_parse_error(node, 'Requires sequence of integers') + return input_data + def gds_format_float(self, input_data, input_name=''): + return ('%.15f' % input_data).rstrip('0') + def gds_validate_float(self, input_data, node, input_name=''): + return input_data + def gds_format_float_list(self, input_data, input_name=''): + return '%s' % input_data + def gds_validate_float_list(self, input_data, node, 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 input_data + def gds_format_double(self, input_data, input_name=''): + return '%e' % input_data + def gds_validate_double(self, input_data, node, input_name=''): + return input_data + def gds_format_double_list(self, input_data, input_name=''): + return '%s' % input_data + def gds_validate_double_list(self, input_data, node, 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 input_data + def gds_format_boolean(self, input_data, input_name=''): + return ('%s' % input_data).lower() + def gds_validate_boolean(self, input_data, node, input_name=''): + return input_data + def gds_format_boolean_list(self, input_data, input_name=''): + return '%s' % input_data + def gds_validate_boolean_list(self, input_data, node, 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 input_data + def gds_validate_datetime(self, input_data, node, 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], micro_seconds, ) + 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, 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, 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 + @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.iteritems())) + + +# +# 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('<some message> -- Entering ipshell.\nHit Ctrl-D to exit') + +# +# Globals +# + +ExternalEncoding = 'ascii' +Tag_pattern_ = re_.compile(r'({.*})?(.*)') +String_cleanup_pat_ = re_.compile(r"[\n\r\s]+") +Namespace_extract_pat_ = re_.compile(r'{(.*)}(.*)') + +# +# Support/utility functions. +# + + +def showIndent(outfile, level, pretty_print=True): + if pretty_print: + for idx in range(level): + outfile.write(' ') + + +def quote_xml(inStr): + if not inStr: + return '' + s1 = (isinstance(inStr, basestring) and inStr or + '%s' % inStr) + s1 = s1.replace('&', '&') + s1 = s1.replace('<', '<') + s1 = s1.replace('>', '>') + return s1 + + +def quote_attrib(inStr): + s1 = (isinstance(inStr, basestring) 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): + if XMLParser_import_library == XMLParser_import_lxml: + msg = '%s (element %s/line %d)' % ( + msg, node.tag, node.sourceline, ) + else: + msg = '%s (element %s)' % (msg, node.tag, ) + 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, pretty_print) + def exportSimple(self, outfile, level, name): + if self.content_type == MixedContainer.TypeString: + outfile.write('<%s>%s</%s>' % ( + self.name, self.value, self.name)) + elif self.content_type == MixedContainer.TypeInteger or \ + self.content_type == MixedContainer.TypeBoolean: + outfile.write('<%s>%d</%s>' % ( + self.name, self.value, self.name)) + elif self.content_type == MixedContainer.TypeFloat or \ + self.content_type == MixedContainer.TypeDecimal: + outfile.write('<%s>%f</%s>' % ( + self.name, self.value, self.name)) + elif self.content_type == MixedContainer.TypeDouble: + outfile.write('<%s>%g</%s>' % ( + self.name, self.value, self.name)) + elif self.content_type == MixedContainer.TypeBase64: + outfile.write('<%s>%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): + self.name = name + self.data_type = data_type + self.container = container + 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 _cast(typ, value): + if typ is None or value is None: + return value + return typ(value) + +# +# Data representation classes. +# + + +class RegisterClientRequest(GeneratedsSuper): + """The RegisterClientRequest is sent by an external application (called + client) such as an Alex or Theo to SALLY. This message should be + send to "/queue/sally_register" and as result will get a + RegisterClientResponse object.""" + subclass = None + superclass = None + def __init__(self, ListenQueue=None, Schemas=None, EnvironmentID=None): + self.original_tagname_ = None + self.ListenQueue = ListenQueue + if Schemas is None: + self.Schemas = [] + else: + self.Schemas = Schemas + self.EnvironmentID = EnvironmentID + def factory(*args_, **kwargs_): + if RegisterClientRequest.subclass: + return RegisterClientRequest.subclass(*args_, **kwargs_) + else: + return RegisterClientRequest(*args_, **kwargs_) + factory = staticmethod(factory) + def get_ListenQueue(self): return self.ListenQueue + def set_ListenQueue(self, ListenQueue): self.ListenQueue = ListenQueue + def get_Schemas(self): return self.Schemas + def set_Schemas(self, Schemas): self.Schemas = Schemas + def add_Schemas(self, value): self.Schemas.append(value) + def insert_Schemas_at(self, index, value): self.Schemas.insert(index, value) + def replace_Schemas_at(self, index, value): self.Schemas[index] = value + def get_EnvironmentID(self): return self.EnvironmentID + def set_EnvironmentID(self, EnvironmentID): self.EnvironmentID = EnvironmentID + def validate_ListenQueueType(self, value): + # Validate type ListenQueueType, a restriction on xs:string. + pass + def validate_EnvironmentIDType(self, value): + # Validate type EnvironmentIDType, a restriction on xs:string. + pass + def hasContent_(self): + if ( + self.ListenQueue is not None or + self.Schemas or + self.EnvironmentID is not None + ): + return True + else: + return False + def export(self, outfile, level, namespace_='', name_='RegisterClientRequest', namespacedef_='xmlns="http://kwarc.info/sally/comm/core"', pretty_print=True): + 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' % (namespace_, name_, namespacedef_ and ' ' + namespacedef_ or '', )) + already_processed = set() + self.exportAttributes(outfile, level, already_processed, namespace_, name_='RegisterClientRequest') + if self.hasContent_(): + outfile.write('>%s' % (eol_, )) + self.exportChildren(outfile, level + 1, namespace_='', name_='RegisterClientRequest', pretty_print=pretty_print) + showIndent(outfile, level, pretty_print) + outfile.write('</%s%s>%s' % (namespace_, name_, eol_)) + else: + outfile.write('/>%s' % (eol_, )) + def exportAttributes(self, outfile, level, already_processed, namespace_='', name_='RegisterClientRequest'): + pass + def exportChildren(self, outfile, level, namespace_='', name_='RegisterClientRequest', fromsubclass_=False, pretty_print=True): + if pretty_print: + eol_ = '\n' + else: + eol_ = '' + if self.ListenQueue is not None: + showIndent(outfile, level, pretty_print) + outfile.write('<%sListenQueue>%s</%sListenQueue>%s' % (namespace_, self.gds_format_string(quote_xml(self.ListenQueue).encode(ExternalEncoding), input_name='ListenQueue'), namespace_, eol_)) + for Schemas_ in self.Schemas: + showIndent(outfile, level, pretty_print) + outfile.write('<%sSchemas>%s</%sSchemas>%s' % (namespace_, self.gds_format_string(quote_xml(Schemas_).encode(ExternalEncoding), input_name='Schemas'), namespace_, eol_)) + if self.EnvironmentID is not None: + showIndent(outfile, level, pretty_print) + outfile.write('<%sEnvironmentID>%s</%sEnvironmentID>%s' % (namespace_, self.gds_format_string(quote_xml(self.EnvironmentID).encode(ExternalEncoding), input_name='EnvironmentID'), namespace_, eol_)) + def exportLiteral(self, outfile, level, name_='RegisterClientRequest'): + level += 1 + already_processed = set() + self.exportLiteralAttributes(outfile, level, already_processed, name_) + if self.hasContent_(): + self.exportLiteralChildren(outfile, level, name_) + def exportLiteralAttributes(self, outfile, level, already_processed, name_): + pass + def exportLiteralChildren(self, outfile, level, name_): + if self.ListenQueue is not None: + showIndent(outfile, level) + outfile.write('ListenQueue=%s,\n' % quote_python(self.ListenQueue).encode(ExternalEncoding)) + showIndent(outfile, level) + outfile.write('Schemas=[\n') + level += 1 + for Schemas_ in self.Schemas: + showIndent(outfile, level) + outfile.write('%s,\n' % quote_python(Schemas_).encode(ExternalEncoding)) + level -= 1 + showIndent(outfile, level) + outfile.write('],\n') + if self.EnvironmentID is not None: + showIndent(outfile, level) + outfile.write('EnvironmentID=%s,\n' % quote_python(self.EnvironmentID).encode(ExternalEncoding)) + 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_ == 'ListenQueue': + ListenQueue_ = child_.text + ListenQueue_ = self.gds_validate_string(ListenQueue_, node, 'ListenQueue') + self.ListenQueue = ListenQueue_ + self.validate_ListenQueueType(self.ListenQueue) # validate type ListenQueueType + elif nodeName_ == 'Schemas': + Schemas_ = child_.text + Schemas_ = self.gds_validate_string(Schemas_, node, 'Schemas') + self.Schemas.append(Schemas_) + elif nodeName_ == 'EnvironmentID': + EnvironmentID_ = child_.text + EnvironmentID_ = self.gds_validate_string(EnvironmentID_, node, 'EnvironmentID') + self.EnvironmentID = EnvironmentID_ + self.validate_EnvironmentIDType(self.EnvironmentID) # validate type EnvironmentIDType +# end class RegisterClientRequest + + +class RegisterClientResponse(GeneratedsSuper): + """After a successful registration, SALLY notifies the SALLY client of + the queue (in SendQueue) it should use for any further + communication.""" + subclass = None + superclass = None + def __init__(self, SendQueue=None): + self.original_tagname_ = None + self.SendQueue = SendQueue + def factory(*args_, **kwargs_): + if RegisterClientResponse.subclass: + return RegisterClientResponse.subclass(*args_, **kwargs_) + else: + return RegisterClientResponse(*args_, **kwargs_) + factory = staticmethod(factory) + def get_SendQueue(self): return self.SendQueue + def set_SendQueue(self, SendQueue): self.SendQueue = SendQueue + def hasContent_(self): + if ( + self.SendQueue is not None + ): + return True + else: + return False + def export(self, outfile, level, namespace_='', name_='RegisterClientResponse', namespacedef_='xmlns="http://kwarc.info/sally/comm/core"', pretty_print=True): + 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' % (namespace_, name_, namespacedef_ and ' ' + namespacedef_ or '', )) + already_processed = set() + self.exportAttributes(outfile, level, already_processed, namespace_, name_='RegisterClientResponse') + if self.hasContent_(): + outfile.write('>%s' % (eol_, )) + self.exportChildren(outfile, level + 1, namespace_='', name_='RegisterClientResponse', pretty_print=pretty_print) + showIndent(outfile, level, pretty_print) + outfile.write('</%s%s>%s' % (namespace_, name_, eol_)) + else: + outfile.write('/>%s' % (eol_, )) + def exportAttributes(self, outfile, level, already_processed, namespace_='', name_='RegisterClientResponse'): + pass + def exportChildren(self, outfile, level, namespace_='', name_='RegisterClientResponse', fromsubclass_=False, pretty_print=True): + if pretty_print: + eol_ = '\n' + else: + eol_ = '' + if self.SendQueue is not None: + showIndent(outfile, level, pretty_print) + outfile.write('<%sSendQueue>%s</%sSendQueue>%s' % (namespace_, self.gds_format_string(quote_xml(self.SendQueue).encode(ExternalEncoding), input_name='SendQueue'), namespace_, eol_)) + def exportLiteral(self, outfile, level, name_='RegisterClientResponse'): + level += 1 + already_processed = set() + self.exportLiteralAttributes(outfile, level, already_processed, name_) + if self.hasContent_(): + self.exportLiteralChildren(outfile, level, name_) + def exportLiteralAttributes(self, outfile, level, already_processed, name_): + pass + def exportLiteralChildren(self, outfile, level, name_): + if self.SendQueue is not None: + showIndent(outfile, level) + outfile.write('SendQueue=%s,\n' % quote_python(self.SendQueue).encode(ExternalEncoding)) + 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_ == 'SendQueue': + SendQueue_ = child_.text + SendQueue_ = self.gds_validate_string(SendQueue_, node, 'SendQueue') + self.SendQueue = SendQueue_ +# end class RegisterClientResponse + + +class HeartbeatRequest(GeneratedsSuper): + """After successful registration, SALLY will send a HeartbeatRequest + message to the registered SALLY client and expects to receive a + HeartbeatResponse message back after at most 20 sec. If this + operation times out, the SALLY client will be unregistered + automatically.""" + subclass = None + superclass = None + def __init__(self): + self.original_tagname_ = None + def factory(*args_, **kwargs_): + if HeartbeatRequest.subclass: + return HeartbeatRequest.subclass(*args_, **kwargs_) + else: + return HeartbeatRequest(*args_, **kwargs_) + factory = staticmethod(factory) + def hasContent_(self): + if ( + + ): + return True + else: + return False + def export(self, outfile, level, namespace_='', name_='HeartbeatRequest', namespacedef_='xmlns="http://kwarc.info/sally/comm/core"', pretty_print=True): + 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' % (namespace_, name_, namespacedef_ and ' ' + namespacedef_ or '', )) + already_processed = set() + self.exportAttributes(outfile, level, already_processed, namespace_, name_='HeartbeatRequest') + if self.hasContent_(): + outfile.write('>%s' % (eol_, )) + self.exportChildren(outfile, level + 1, namespace_='', name_='HeartbeatRequest', pretty_print=pretty_print) + outfile.write('</%s%s>%s' % (namespace_, name_, eol_)) + else: + outfile.write('/>%s' % (eol_, )) + def exportAttributes(self, outfile, level, already_processed, namespace_='', name_='HeartbeatRequest'): + pass + def exportChildren(self, outfile, level, namespace_='', name_='HeartbeatRequest', fromsubclass_=False, pretty_print=True): + pass + def exportLiteral(self, outfile, level, name_='HeartbeatRequest'): + level += 1 + already_processed = set() + self.exportLiteralAttributes(outfile, level, already_processed, name_) + if self.hasContent_(): + self.exportLiteralChildren(outfile, level, name_) + def exportLiteralAttributes(self, outfile, level, already_processed, name_): + pass + def exportLiteralChildren(self, outfile, level, name_): + 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): + pass + def buildChildren(self, child_, node, nodeName_, fromsubclass_=False): + pass +# end class HeartbeatRequest + + +class HeartbeatResponse(GeneratedsSuper): + subclass = None + superclass = None + def __init__(self): + self.original_tagname_ = None + def factory(*args_, **kwargs_): + if HeartbeatResponse.subclass: + return HeartbeatResponse.subclass(*args_, **kwargs_) + else: + return HeartbeatResponse(*args_, **kwargs_) + factory = staticmethod(factory) + def hasContent_(self): + if ( + + ): + return True + else: + return False + def export(self, outfile, level, namespace_='', name_='HeartbeatResponse', namespacedef_='xmlns="http://kwarc.info/sally/comm/core"', pretty_print=True): + 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' % (namespace_, name_, namespacedef_ and ' ' + namespacedef_ or '', )) + already_processed = set() + self.exportAttributes(outfile, level, already_processed, namespace_, name_='HeartbeatResponse') + if self.hasContent_(): + outfile.write('>%s' % (eol_, )) + self.exportChildren(outfile, level + 1, namespace_='', name_='HeartbeatResponse', pretty_print=pretty_print) + outfile.write('</%s%s>%s' % (namespace_, name_, eol_)) + else: + outfile.write('/>%s' % (eol_, )) + def exportAttributes(self, outfile, level, already_processed, namespace_='', name_='HeartbeatResponse'): + pass + def exportChildren(self, outfile, level, namespace_='', name_='HeartbeatResponse', fromsubclass_=False, pretty_print=True): + pass + def exportLiteral(self, outfile, level, name_='HeartbeatResponse'): + level += 1 + already_processed = set() + self.exportLiteralAttributes(outfile, level, already_processed, name_) + if self.hasContent_(): + self.exportLiteralChildren(outfile, level, name_) + def exportLiteralAttributes(self, outfile, level, already_processed, name_): + pass + def exportLiteralChildren(self, outfile, level, name_): + 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): + pass + def buildChildren(self, child_, node, nodeName_, fromsubclass_=False): + pass +# end class HeartbeatResponse + + +GDSClassesMapping = { +} + + +USAGE_TEXT = """ +Usage: python <Parser>.py [ -s ] <in_xml_file> +""" + + +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): + doc = parsexml_(inFileName) + rootNode = doc.getroot() + rootTag, rootClass = get_root_tag(rootNode) + if rootClass is None: + rootTag = 'RegisterClientRequest' + rootClass = RegisterClientRequest + rootObj = rootClass.factory() + rootObj.build(rootNode) + # Enable Python to collect the space used by the DOM. + doc = None + if not silence: + sys.stdout.write('<?xml version="1.0" ?>\n') + rootObj.export( + sys.stdout, 0, name_=rootTag, + namespacedef_='xmlns="http://kwarc.info/sally/comm/core"', + pretty_print=True) + return rootObj + + +def parseEtree(inFileName, silence=False): + doc = parsexml_(inFileName) + rootNode = doc.getroot() + rootTag, rootClass = get_root_tag(rootNode) + if rootClass is None: + rootTag = 'RegisterClientRequest' + rootClass = RegisterClientRequest + 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): + from StringIO import StringIO + doc = parsexml_(StringIO(inString)) + rootNode = doc.getroot() + rootTag, rootClass = get_root_tag(rootNode) + if rootClass is None: + rootTag = 'RegisterClientRequest' + rootClass = RegisterClientRequest + rootObj = rootClass.factory() + rootObj.build(rootNode) + # Enable Python to collect the space used by the DOM. + doc = None + if not silence: + sys.stdout.write('<?xml version="1.0" ?>\n') + rootObj.export( + sys.stdout, 0, name_=rootTag, + namespacedef_='xmlns="http://kwarc.info/sally/comm/core"') + return rootObj + + +def parseLiteral(inFileName, silence=False): + doc = parsexml_(inFileName) + rootNode = doc.getroot() + rootTag, rootClass = get_root_tag(rootNode) + if rootClass is None: + rootTag = 'RegisterClientRequest' + rootClass = RegisterClientRequest + 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 commcore import *\n\n') + sys.stdout.write('import commcore 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__ = [ + "HeartbeatRequest", + "HeartbeatResponse", + "RegisterClientRequest", + "RegisterClientResponse" +] diff --git a/core.xsd b/core.xsd new file mode 120000 index 0000000000000000000000000000000000000000..769ef05dcaf95cd73de6a06fb1206bd404bacc20 --- /dev/null +++ b/core.xsd @@ -0,0 +1 @@ +/home/cjucovschi/sally4-base/comm-core/src/main/resources/core.xsd \ No newline at end of file diff --git a/genfromxsd.sh b/genfromxsd.sh index 4ebf06cc000d28d6143de2545321175a0404e3e5..f9329669c4a1aab5459ec4b7cf5e2068e9a00ac1 100755 --- a/genfromxsd.sh +++ b/genfromxsd.sh @@ -1,2 +1,2 @@ generateDS.py -o commcore.py --namespacedef="xmlns=\"http://kwarc.info/sally/comm/core\"" core.xsd -generateDS.py -o commlmh.py --namespacedef="xmlns=\"http://kwarc.info/sally/comm/lmh\"" lmh.xsd +#generateDS.py -o commlmh.py --namespacedef="xmlns=\"http://kwarc.info/sally/comm/lmh\"" lmh.xsd