def write_core_attribute_rule(self, lo_child=None): if lo_child is None: text = '{0} {1} object may have the optional SBML Level~3 ' \ 'Core attributes {2} and {3}. No other attributes from the ' \ 'SBML Level 3 Core namespaces are permitted on {4} {1}.'\ .format(self.indef_u, self.formatted_name, strFunctions.wrap_token('metaid'), strFunctions.wrap_token('sboTerm'), self.indef) ref = 'SBML Level~3 Version~1 Core, Section~3.2.' sev = 'ERROR' tc = '{0}{1}AllowedCoreAttributes'.format(self.up_package, self.name) lo = False else: lo_name = strFunctions.plural(lo_child['name']) text = 'A {0} object may have the optional SBML Level~3 ' \ 'Core attributes {1} and {2}. No other attributes from the ' \ 'SBML Level 3 Core namespaces are permitted on a {0} object.'\ .format(strFunctions.get_element_name(lo_child), strFunctions.wrap_token('metaid'), strFunctions.wrap_token('sboTerm')) ref = '{0}, {1}.'\ .format(self.pkg_ref, strFunctions.wrap_section(self.name)) sev = 'ERROR' tc = '{0}{1}LO{2}AllowedCoreAttributes'.format(self.up_package, self.name, lo_name) lo = True lib_sev = '{0}_SEV_ERROR'.format(global_variables.up_full_lib) short = 'Core attributes allowed on <{0}>.'.format(self.lower_name) lib_ref = 'L3V1 {0} V1 Section'.format(self.up_package) return dict({'number': self.number, 'text': text, 'reference': ref, 'severity': sev, 'typecode': tc, 'lib_sev': lib_sev, 'short': short, 'lib_ref': lib_ref, 'plugin': True, 'object': self.name, 'lo': lo, 'reqd': self.reqd_elem, 'opt': self.opt_elem})
def write_core_subobject_rule(self, lo_child=None): if lo_child is None: text = '{0} {1} object may have the optional SBML Level~3 ' \ 'Core subobjects for notes and annotations. No other ' \ 'elements from the SBML Level~3 Core namespaces are ' \ 'permitted on {2} {1}.'\ .format(self.indef_u, self.formatted_name, self.indef) ref = 'SBML Level~3 Version~1 Core, Section~3.2.' sev = 'ERROR' tc = '{0}{1}AllowedCoreElements'.format(self.up_package, self.name) lo = False else: if 'type' in lo_child: loname = strFunctions.get_element_name(lo_child) element = lo_child['element'] lo_name = strFunctions.plural(element) else: # we are in a plugin so have different fields loname = strFunctions.cap_list_of_name(lo_child['name']) element = lo_child['name'] lo_name = strFunctions.plural(element) text = 'Apart from the general notes and annotations subobjects ' \ 'permitted on all SBML objects, a \{0} container object ' \ 'may only contain \{1} objects.'\ .format(loname, element) add_extended = True if self.package == 'render': add_extended = False ref = '{0}, {1}.'\ .format(self.pkg_ref, strFunctions.wrap_section(self.name, True, add_extended)) sev = 'ERROR' tc = '{0}{1}LO{2}AllowedCoreElements'.format(self.up_package, self.name, lo_name) lo = True lib_sev = '{0}_SEV_ERROR'.format(global_variables.up_full_lib) short = 'Core elements allowed on <{0}>.'.format(self.lower_name) lib_ref = 'L3V1 {0} V1 Section'.format(self.up_package) return dict({'number': self.number, 'text': text, 'reference': ref, 'severity': sev, 'typecode': tc, 'lib_sev': lib_sev, 'short': short, 'lib_ref': lib_ref, 'plugin': True, 'object': self.name, 'lo': lo, 'reqd': self.reqd_elem, 'opt': self.opt_elem})
def write_core_subobject_rule(self, lo_child=None): if lo_child is None: text = '{0} {1} object may have the optional SBML Level~3 ' \ 'Core subobjects for notes and annotations. No other ' \ 'elements from the SBML Level 3 Core namespaces are ' \ 'permitted on {2} {1}.'\ .format(self.indef_u, self.formatted_name, self.indef) ref = 'SBML Level~3 Version~1 Core, Section~3.2.' sev = 'ERROR' tc = '{0}{1}AllowedCoreElements'.format(self.up_package, self.name) lo = False else: if 'type' in lo_child: loname = strFunctions.get_element_name(lo_child) element = lo_child['element'] lo_name = strFunctions.plural(element) else: # we are in a plugin so have different fields loname = strFunctions.cap_list_of_name(lo_child['name']) element = lo_child['name'] lo_name = strFunctions.plural(element) text = 'Apart from the general notes and annotations subobjects ' \ 'permitted on all SBML objects, a \{0} container object ' \ 'may only contain \{1} objects.'\ .format(loname, element) ref = '{0}, {1}.'\ .format(self.pkg_ref, strFunctions.wrap_section(self.name)) sev = 'ERROR' tc = '{0}{1}LO{2}AllowedCoreElements'.format(self.up_package, self.name, lo_name) lo = True lib_sev = '{0}_SEV_ERROR'.format(global_variables.up_full_lib) short = 'Core elements allowed on <{0}>.'.format(self.lower_name) lib_ref = 'L3V1 {0} V1 Section'.format(self.up_package) return dict({'number': self.number, 'text': text, 'reference': ref, 'severity': sev, 'typecode': tc, 'lib_sev': lib_sev, 'short': short, 'lib_ref': lib_ref, 'plugin': True, 'object': self.name, 'lo': lo, 'reqd': self.reqd_elem, 'opt': self.opt_elem})
def write_jsbml_list_enums(self): self.up_indent() # Still many things to do enums = self.enums_data for i in range(0, len(enums)): enum = enums[i] self.write_variable_comment() line = 'listOf{0},'.format(strFunctions.plural(enum['name'])) self.write_line(line) self.write_variable_comment() self.write_line('none;') self.down_indent()
def write_core_subobject_rule(self, lo_child=None): if lo_child is None: text = '{0} {1} object may have the optional SBML Level~3 ' \ 'Core subobjects for notes and annotations. No other ' \ 'elements from the SBML Level~3 Core namespaces are ' \ 'permitted on {2} {1}.'\ .format(self.indef_u, self.formatted_name, self.indef) ref = 'SBML Level~3 Version~1 Core, Section~3.2.' sev = 'ERROR' lib_sev = '{0}_SEV_ERROR'.format(global_variables.up_full_lib) tc = '{0}{1}AllowedCoreElements'.format(self.up_package, self.name) short = 'Core elements allowed on <{0}>.'.format(self.lower_name) lo = False else: loname = strFunctions.get_element_name_no_prefix(lo_child) temp = strFunctions.remove_prefix(lo_child['element']) lo_name = strFunctions.plural(temp) text = 'Apart from the general notes and annotations subobjects ' \ 'permitted on all SBML objects, a {0} container object ' \ 'may only contain \{1} objects.'\ .format(loname, temp) sec_name = 'listof' + lo_name.lower() ref = '{0}, {1}.'\ .format(self.pkg_ref, strFunctions.wrap_section(sec_name)) sev = 'ERROR' lib_sev = '{0}_SEV_ERROR'.format(global_variables.up_full_lib) tc = '{0}{1}LO{2}AllowedCoreElements'.format( self.up_package, self.name, lo_name) lo = True short = 'Core elements allowed on <listOf{0}>.'.format(lo_name) lib_ref = 'L3V1 {0} V1 Section'.format(self.up_package) return dict({ 'number': self.number, 'text': text, 'reference': ref, 'severity': sev, 'typecode': tc, 'lib_sev': lib_sev, 'short': short, 'lib_ref': lib_ref, 'plugin': False, 'object': self.name, 'lo': lo, 'reqd': self.reqd_elem, 'opt': self.opt_elem })
def __init__(self, language, is_cpp_api, is_list_of, class_object): self.language = language self.class_name = class_object['name'] self.is_cpp_api = is_cpp_api self.is_list_of = is_list_of if is_list_of: self.child_name = class_object['lo_child'] else: self.child_name = '' if is_cpp_api: self.object_name = self.class_name self.object_child_name = self.child_name else: if is_list_of: self.object_name = 'ListOf_t' else: self.object_name = self.class_name + '_t' self.object_child_name = self.child_name + '_t' self.concretes = class_object['concretes'] # useful variables if not self.is_cpp_api and self.is_list_of: self.struct_name = self.object_child_name else: self.struct_name = self.object_name self.plural = strFunctions.plural(self.child_name) self.indef_name = strFunctions.get_indefinite(self.object_child_name) self.abbrev_parent = strFunctions.abbrev_name(self.object_name) self.abbrev_child = strFunctions.abbrev_name(self.child_name) if self.is_cpp_api is False: self.true = '@c 1' self.false = '@c 0' else: self.true = '@c true' self.false = '@c false'
def __init__(self, language, is_java_api, is_list_of, class_object, jsbml_data_tree=None, jsbml_methods=None): self.language = language self.cap_language = language.upper() self.package = class_object['package'] self.class_name = class_object['name'] self.is_java_api = is_java_api self.is_list_of = is_list_of if is_list_of: self.child_name = class_object['lo_child'] else: self.child_name = '' if is_java_api: self.object_name = self.class_name self.object_child_name = self.child_name else: if is_list_of: self.object_name = 'ListOf' else: self.object_name = self.class_name self.object_child_name = self.child_name # class_attributes not suitable # self.attributes = class_object['class_attributes'] self.attributes = class_object['attribs'] self.child_elements = class_object['child_elements'] if 'num_versions' in class_object and class_object['num_versions'] > 1: self.has_multiple_versions = True else: self.has_multiple_versions = False self.document = False if 'document' in class_object: self.document = class_object['document'] # useful variables if not self.is_java_api and self.is_list_of: self.struct_name = self.object_child_name else: self.struct_name = self.object_name if self.is_java_api is False: self.true = '@c 1' self.false = '@c 0' else: self.true = '{@code true}' # For comments self.false = '{@code false}' self.plural = strFunctions.plural(self.child_name) self.indef_name = strFunctions.get_indefinite(self.object_child_name) self.abbrev_parent = strFunctions.abbrev_name(self.object_name) self.abbrev_child = strFunctions.abbrev_name(self.child_name) self.is_header = True if 'is_header' in class_object: self.is_header = class_object['is_header'] self.is_plugin = False if 'is_plugin' in class_object: self.is_plugin = class_object['is_plugin'] self.open_br = '{' self.close_br = '}' self.success = global_variables.ret_success self.failed = global_variables.ret_failed self.invalid_att = global_variables.ret_invalid_att self.invalid_obj = global_variables.ret_invalid_obj # JSBML unique helper data if jsbml_data_tree is not None: self.jsbml_data_tree = jsbml_data_tree if jsbml_methods is not None: self.jsbml_methods = jsbml_methods # Here it will hold mandatory functions informations self.mandatory_data = {} # The order the mandatory function have to be written self.write_order = self.determine_mandatory_methods()
def expand_attributes(self, attributes): for i in range(0, len(attributes)): capname = strFunctions.upper_first(attributes[i]['name']) attributes[i]['name'] = strFunctions.lower_first(capname) attributes[i]['capAttName'] = capname attributes[i]['memberName'] = 'm' + capname attributes[i]['pluralName'] = \ strFunctions.plural(attributes[i]['name']) attributes[i]['isEnum'] = False attributes[i]['isArray'] = False attributes[i]['isVector'] = False attributes[i]['children_overwrite'] = False att_type = attributes[i]['type'] if att_type == 'SId' or att_type == 'SIdRef' or att_type == 'IDREF': attributes[i]['attType'] = 'string' attributes[i]['attTypeCode'] = 'std::string&' attributes[i]['CType'] = 'const char *' attributes[i]['isNumber'] = False attributes[i]['default'] = '""' elif att_type == 'UnitSId' or att_type == 'UnitSIdRef': attributes[i]['attType'] = 'string' attributes[i]['attTypeCode'] = 'std::string&' attributes[i]['CType'] = 'const char *' attributes[i]['isNumber'] = False attributes[i]['default'] = '""' elif att_type == 'string': attributes[i]['attType'] = 'string' attributes[i]['attTypeCode'] = 'std::string&' attributes[i]['CType'] = 'const char *' attributes[i]['isNumber'] = False attributes[i]['default'] = '""' elif att_type == 'double': attributes[i]['attType'] = 'double' attributes[i]['attTypeCode'] = 'double' attributes[i]['CType'] = 'double' attributes[i]['isNumber'] = True attributes[i]['default'] = 'util_NaN()' elif att_type == 'int': attributes[i]['attType'] = 'integer' attributes[i]['attTypeCode'] = 'int' attributes[i]['CType'] = 'int' attributes[i]['isNumber'] = True attributes[i]['default'] = '{0}_INT_' \ 'MAX'.format(self.cap_language) elif att_type == 'uint': attributes[i]['attType'] = 'unsigned integer' attributes[i]['attTypeCode'] = 'unsigned int' attributes[i]['CType'] = 'unsigned int' attributes[i]['isNumber'] = True attributes[i]['default'] = '{0}_INT_' \ 'MAX'.format(self.cap_language) elif att_type == 'bool' or att_type == 'boolean': attributes[i]['attType'] = 'boolean' attributes[i]['attTypeCode'] = 'bool' attributes[i]['CType'] = 'int' attributes[i]['isNumber'] = False attributes[i]['default'] = 'false' elif att_type == 'enum': attributes[i]['isEnum'] = True attributes[i]['attType'] = 'enum' attributes[i]['attTypeCode'] = attributes[i]['element'] + '_t' attributes[i]['CType'] = attributes[i]['element'] + '_t' attributes[i]['isNumber'] = False attributes[i]['default'] = \ query.get_default_enum_value(attributes[i]) elif att_type == 'element': el_name = attributes[i]['element'] at_name = attributes[i]['name'] attributes[i]['attType'] = 'element' if attributes[i]['name'] == 'math': if global_variables.is_package: attributes[i]['attTypeCode'] = 'ASTNode*' attributes[i]['CType'] = 'ASTNode_t*' else: attributes[i]['attTypeCode'] = 'LIBSBML_CPP_NAMESPACE_QUALIFIER ASTNode*' attributes[i]['CType'] = 'LIBSBML_CPP_NAMESPACE_QUALIFIER ASTNode_t*' else: attributes[i]['attTypeCode'] = attributes[i]['element']+'*' attributes[i]['CType'] = attributes[i]['element']+'_t*' if attributes[i]['attTypeCode'] == 'XMLNode*' and not global_variables.is_package: attributes[i]['attTypeCode'] = 'LIBSBML_CPP_NAMESPACE_QUALIFIER {0}*'.format(attributes[i]['element']) attributes[i]['CType'] = 'LIBSBML_CPP_NAMESPACE_QUALIFIER {0}_t*'.format(attributes[i]['element']) attributes[i]['isNumber'] = False attributes[i]['default'] = 'NULL' if strFunctions.compare_no_case(strFunctions.remove_prefix(el_name), at_name): attributes[i]['children_overwrite'] = False else: attributes[i]['children_overwrite'] = True elif att_type == 'lo_element' or att_type == 'inline_lo_element': name = strFunctions.list_of_name(attributes[i]['element']) plural = strFunctions.plural_no_prefix(attributes[i]['element']) attributes[i]['attType'] = 'lo_element' attributes[i]['attTypeCode'] = name attributes[i]['CType'] = 'ListOf_t' attributes[i]['memberName'] = 'm' + plural attributes[i]['isNumber'] = False attributes[i]['default'] = 'NULL' elif att_type == 'array': attributes[i]['isArray'] = True attributes[i]['element'] = \ strFunctions.lower_first(attributes[i]['element']) attributes[i]['attType'] = 'array' attributes[i]['attTypeCode'] = attributes[i]['element'] + '*' attributes[i]['CType'] = attributes[i]['attTypeCode'] attributes[i]['isNumber'] = False attributes[i]['default'] = 'NULL' elif att_type == 'vector': attributes[i]['isVector'] = True attributes[i]['element'] = \ strFunctions.lower_first(attributes[i]['element']) attributes[i]['attType'] = 'vector' attributes[i]['attTypeCode'] = 'std::vector<{0}>'.format(attributes[i]['element']) attributes[i]['CType'] = attributes[i]['attTypeCode'] attributes[i]['isNumber'] = False attributes[i]['default'] = 'NULL' else: global_variables.code_returned \ = global_variables.return_codes['unknown type used'] attributes[i]['attType'] = 'FIXME_{0}'.format(att_type) attributes[i]['attTypeCode'] = 'FIXME_{0}'.format(att_type) attributes[i]['CType'] = 'FIXME_{0}'.format(att_type) attributes[i]['isNumber'] = False attributes[i]['default'] = 'FIXME_{0}'.format(att_type) return attributes
def plural_then_single(name): plural = sf.plural(name) return sf.singular(plural)
def write_get_num_objects(self): if not self.is_cpp_api: return elif self.is_list_of: return if len(self.elements) == 0: return # create comment parts params = [] return_lines = [] additional = [] title_line = 'Returns the number of \"elementName" in this {0}.' \ .format(self.class_name) params.append( '@param elementName, the name of the element to get number of.') return_lines.append('@return unsigned int number of elements.') # create the function declaration function = 'getNumObjects' return_type = 'unsigned int' arguments = ['const std::string& elementName'] code = [] if not self.has_elements_with_same_xml_name(): # create the function implementation first_line = ['unsigned int n = 0'] last_line = ['return n'] first = True block = [] if_block = [] for elem in self.elements: if not first: block.append('else if') else: first = False block.append('elementName == \"{0}\"'.format(elem['name'])) if elem in self.lo_elements: name = strFunctions.plural( strFunctions.upper_first(elem['name'])) block.append('return getNum{0}()'.format(name)) else: [elem_name, unused] = strFunctions.remove_hyphens(elem['name']) nested_if = [ 'isSet{0}()'.format( strFunctions.upper_first(elem_name)), 'return 1' ] nested_if_block = self.create_code_block('if', nested_if) block.append(nested_if_block) if len(block) > 2: if_block = self.create_code_block('else_if', block) else: if_block = self.create_code_block('if', block) code = [ self.create_code_block('line', first_line), if_block, self.create_code_block('line', last_line) ] else: code = [ self.create_code_block('comment', ['TO DO']), self.create_code_block('line', ['return 0']) ] # return the parts return dict({ 'title_line': title_line, 'params': params, 'return_lines': return_lines, 'additional': additional, 'function': function, 'return_type': return_type, 'arguments': arguments, 'constant': False, 'virtual': True, 'object_name': self.struct_name, 'implementation': code })
def write_remove_object(self): if not self.is_cpp_api: return elif self.is_list_of: return if len(self.elements) == 0: return # create comment parts params = [] return_lines = [] additional = [] title_line = 'Removes and returns the new "elementName" object with the given id in this {0}.' \ .format(self.class_name) params.append('@param elementName, the name of the element to remove.') params.append('@param id, the id of the element to remove.') return_lines.append('@return pointer to the element removed.') # create the function declaration function = 'removeChildObject' return_type = '{0}*'.format(global_variables.baseClass) arguments = ['const std::string& elementName', 'const std::string& id'] code = [] if not self.has_elements_with_same_xml_name(): # create the function implementation last_line = ['return NULL'] first = True block = [] if_block = [] for elem in self.elements: if elem['concrete']: for conc in elem['concrete']: if not first: block.append('else if') else: first = False elemName = elem['name'] if not elem['element'] or elem['element'] == elemName: elemElem = elemName else: elemElem = elem['element'] block.append('elementName == \"{0}\"'.format( conc['name'])) single = True if elem not in self.single_elements: thisClass = query.get_class( elemElem, self.classroot) single = False hasid = False for att in thisClass['attribs']: if att['name'] == 'id': hasid = True if hasid: block.append('return remove{0}(id)'.format( strFunctions.upper_first(elemName))) else: nested_if = self.create_code_block( 'if', [ 'get{0}(i)->getId() == id'.format( strFunctions.upper_first(elemName) ), 'return remove{0}(i)'.format( strFunctions.upper_first(elemName)) ]) nested_for = self.create_code_block( 'for', [ 'unsigned int i = 0; i < getNum{0}(); i++' ''.format( strFunctions.plural( strFunctions.upper_first( elemName))), nested_if ]) block.append(nested_for) else: [elem_name, unused] = strFunctions.remove_hyphens(elemName) block.append('{0} * obj = get{1}()'.format( elemElem, strFunctions.upper_first(elem_name))) block.append( 'if (unset{0}() == LIBSBML_OPERATION_SUCCESS) return obj' .format(strFunctions.upper_first(elem_name))) else: if not first: block.append('else if') else: first = False elemName = elem['name'] if not elem['element'] or elem['element'] == elemName: elemElem = elemName else: elemElem = elem['element'] block.append('elementName == \"{0}\"'.format(elem['name'])) single = True if elem not in self.single_elements: thisClass = query.get_class(elemElem, self.classroot) single = False hasid = False for att in thisClass['attribs']: if att['name'] == 'id': hasid = True if hasid: block.append('return remove{0}(id)'.format( strFunctions.upper_first(elemName))) else: nested_if = self.create_code_block( 'if', [ 'get{0}(i)->getId() == id'.format( strFunctions.upper_first(elemName)), 'return remove{0}(i)'.format( strFunctions.upper_first(elemName)) ]) nested_for = self.create_code_block( 'for', [ 'unsigned int i = 0; i < getNum{0}(); i++' ''.format( strFunctions.plural( strFunctions.upper_first( elemName))), nested_if ]) block.append(nested_for) else: [elem_name, unused] = strFunctions.remove_hyphens(elemName) block.append('{0} * obj = get{1}()'.format( elemElem, strFunctions.upper_first(elem_name))) block.append( 'if (unset{0}() == LIBSBML_OPERATION_SUCCESS) return obj' .format(strFunctions.upper_first(elem_name))) if single: if len(block) > 3: if_block = self.create_code_block('else_if', block) else: if_block = self.create_code_block('if', block) else: if len(block) > 2: if_block = self.create_code_block('else_if', block) else: if_block = self.create_code_block('if', block) code = [if_block, self.create_code_block('line', last_line)] else: code = [ self.create_code_block('comment', ['TO DO']), self.create_code_block('line', ['return NULL']) ] # return the parts return dict({ 'title_line': title_line, 'params': params, 'return_lines': return_lines, 'additional': additional, 'function': function, 'return_type': return_type, 'arguments': arguments, 'constant': False, 'virtual': True, 'object_name': self.struct_name, 'implementation': code })
def __init__(self, language, is_cpp_api, is_list_of, class_object, writing_test=False): self.is_cpp_api = is_cpp_api self.is_list_of = is_list_of if class_object['name'].startswith('SBML'): self.class_name = class_object['name'][4:] else: self.class_name = class_object['name'] self.base_class = class_object['baseClass'] if not writing_test: self.language = language self.cap_language = language.upper() self.package = class_object['package'] if is_list_of: self.child_name = class_object['lo_child'] else: self.child_name = '' if is_cpp_api: self.object_name = self.class_name self.object_child_name = self.child_name else: if is_list_of: self.object_name = 'ListOf_t' else: self.object_name = self.class_name + '_t' self.object_child_name = self.child_name + '_t' self.attributes = class_object['class_attributes'] self.classroot = None if 'root' in class_object: self.classroot = class_object['root'] self.elements = query.get_child_elements( class_object['child_elements'], class_object['child_lo_elements'], self.classroot) self.single_elements = query.get_child_elements( class_object['child_elements'], [], self.classroot) self.lo_elements = query.get_child_elements( [], class_object['child_lo_elements'], self.classroot) if 'num_versions' in class_object and class_object[ 'num_versions'] > 1: self.has_multiple_versions = True else: self.has_multiple_versions = False self.document = False if 'document' in class_object: self.document = class_object['document'] # useful variables if not self.is_cpp_api and self.is_list_of: self.struct_name = self.object_child_name else: self.struct_name = self.object_name if self.is_cpp_api is False: self.true = '@c 1' self.false = '@c 0' else: self.true = '@c true' self.false = '@c false' self.plural = strFunctions.plural(self.child_name) self.indef_name = strFunctions.get_indefinite( self.object_child_name) self.abbrev_parent = strFunctions.abbrev_name(self.object_name) self.abbrev_child = strFunctions.abbrev_name(self.child_name) self.is_header = True if 'is_header' in class_object: self.is_header = class_object['is_header'] self.is_plugin = False if 'is_plugin' in class_object: self.is_plugin = class_object['is_plugin'] self.open_br = '{' self.close_br = '}' self.success = global_variables.ret_success self.failed = global_variables.ret_failed self.invalid_att = global_variables.ret_invalid_att self.invalid_obj = global_variables.ret_invalid_obj self.tests = []
def write_lochild_attribute_rule(self, child, lo_info): child_class = query.get_class(child['element'], child['root']) if not child_class or len(child_class['lo_attribs']) == 0: return # if these are all elements we dont need this num = len(child_class['lo_attribs']) count = 0 for attrib in child_class['lo_attribs']: if self.is_element(attrib['type']): count += 1 if count == num: return attributes = [] if len(child_class['lo_class_name']) == 0: child_class['lo_class_name'] = strFunctions.list_of_name(child_class['name']) formatted_name = '\\' + child_class['lo_class_name'] name = child_class['name'] child_reqd = [] child_opt = [] for attrib in child_class['lo_attribs']: attributes.append(attrib) if attrib['reqd']: child_reqd.append(attrib) else: child_opt.append(attrib) lo_info.append(dict({'formatted_name': formatted_name, 'name': child_class['lo_class_name'], 'attributes': attributes})) reqd = self.parse_required(self, child_reqd) opt = self.parse_optional(self, child_opt) no_other_statement = 'No other attributes from the SBML Level 3 {0} ' \ 'namespaces are permitted on {1} {2} object. '\ .format(self.fullname, self.indef, formatted_name) if len(opt) == 0 and len(reqd) > 0: text = '{0} {1} object must have {2}. {3}'\ .format(self.indef_u, formatted_name, reqd, no_other_statement) elif len(reqd) == 0 and len(opt) > 0: text = '{0} {1} object may have {2}. {3}'\ .format(self.indef_u, formatted_name, opt, no_other_statement) else: text = '{0} {1} object must have {2}, and may have {3}. {4}'\ .format(self.indef_u, formatted_name, reqd, opt, no_other_statement) ref = '{0}, {1}.'\ .format(self.pkg_ref, strFunctions.wrap_section(child_class['lo_class_name'])) sev = 'ERROR' lib_sev = '{0}_SEV_ERROR'.format(global_variables.up_full_lib) short = 'Attributes allowed on <{0}>.'.format(strFunctions.lower_first(child_class['lo_class_name'])) lib_ref = 'L3V1 {0} V1 Section'.format(self.up_package) tc = '{0}{1}LO{2}AllowedAttributes'.format(self.up_package, self.name, strFunctions.plural(name)) return dict({'number': self.number, 'text': text, 'reference': ref, 'severity': sev, 'typecode': tc, 'lib_sev': lib_sev, 'short': short, 'lib_ref': lib_ref, 'plugin': False, 'object': self.name, 'lo': True, 'reqd': child_reqd, 'opt': child_opt, 'lo_object': lo_info[0]['name']})
def single_then_plural(name): singular = sf.singular(name) return sf.plural(singular)