コード例 #1
0
    def _get_key_value(line):
        stripLine = line.strip()
        pos = -1
        for start_comment in InputParser._START_COMMENTS:
            pos = stripLine.find(start_comment)
            if pos >= 0:
                break

        if pos == 0:
            return (None, None)

        if pos > 0:
            stripLine = stripLine[:pos].strip()

        pos = stripLine.find(InputParser._PROPVALUE_SEPARATOR)
        if pos > 0:
            key = stripLine[0:pos].strip()
            value = stripLine[pos + 1:].strip()
            return (key, JSONSchema.get_value(value))

        return (None, None)
コード例 #2
0
    def _set_section_property(sections, section_name, property_name, value,
                              types):
        """
        Args:
            section_name (str): the name of the section, case insensitive
            property_name (str): the property name in the section
            value : property value
            types : schema valid types
        """
        section_name = JSONSchema.format_section_name(section_name).lower()
        property_name = JSONSchema.format_property_name(property_name)
        value = JSONSchema.get_value(value, types)

        if section_name not in sections:
            sections[section_name] = OrderedDict([(JSONSchema.NAME,
                                                   section_name)])

        if 'properties' not in sections[section_name]:
            sections[section_name]['properties'] = OrderedDict()

        # name should come first
        if JSONSchema.NAME == property_name and property_name not in sections[
                section_name]['properties']:
            new_dict = OrderedDict([(property_name, value)])
            new_dict.update(sections[section_name]['properties'])
            sections[section_name]['properties'] = new_dict
        else:
            sections[section_name]['properties'][property_name] = value

        # rebuild data
        contents = ''
        properties = sections[section_name]['properties']
        lastIndex = len(properties) - 1
        for i, (key, value) in enumerate(properties.items()):
            contents += '{}{}{}'.format(key, InputParser._PROPVALUE_SEPARATOR,
                                        value)
            if i < lastIndex:
                contents += '\n'

        sections[section_name]['data'] = contents