示例#1
0
    def _decode_variation(variation_node):
        '''
        Decode a <variation> element and return all of its readings as a
        list of :class:`Reading` objects.
        '''

        result = []
        cycles = domtools.attr(variation_node, 'cycles', ifMissing=None)
        option_index = 0
        for child_node in domtools.children(variation_node,
                                            ['reading', 'option']):
            if child_node.localName == 'reading':
                reading = _XMLDecoder._decode_reading(child_node)
                reading.cycles = cycles
                result.append(reading)
            elif child_node.localName == 'option':
                readings = _XMLDecoder._decode_option(child_node)
                for reading_index, reading in enumerate(readings):
                    reading.cycles = cycles
                    reading.optionSetIndex = option_index
                    reading.optionSetSize = len(readings)
                    reading.optionIndex = reading_index
                result.extend(readings)
                option_index += 1
        return result
示例#2
0
    def _decode_option(option_node):
        '''
        Decode an <option> element and return all its readings as a list.
        '''

        result = []
        for reading_node in domtools.children(option_node, 'reading'):
            result.append(_XMLDecoder._decode_reading(reading_node))
        return result
示例#3
0
    def decode_weekday_lectionary(lectionary_node):
        '''
        Decode the <lectionary> element for the weekday lectionary and
        return all its masses as a list.
        '''

        result = []
        for season_node in domtools.children(lectionary_node, 'season'):
            result.extend(_XMLDecoder._decode_season(season_node))
        return result
示例#4
0
    def decode_special_lectionary(lectionary_node):
        '''
        Decode the <lectionary> element for the special lectionary
        and return all its masses as a list.
        '''

        result = []
        for mass_node in domtools.children(lectionary_node, 'mass'):
            mass = _XMLDecoder._decode_mass(mass_node)
            result.append(mass)
        return result
示例#5
0
    def _decode_week(week_node):
        '''
        Decode a <week> element and return all its masses as a list.
        '''

        result = []
        for mass_node in domtools.children(week_node, 'mass'):
            mass = _XMLDecoder._decode_mass(mass_node)
            mass.weekid = domtools.attr(week_node, 'id', ifMissing=None)
            result.append(mass)
        return result
示例#6
0
    def _decode_season(season_node):
        '''
        Decode a <season> element and return all its masses as a
        list.
        '''

        result = []
        seasonid = domtools.attr(season_node, 'id', ifMissing=None)
        for child_node in domtools.children(season_node, ['mass', 'week']):
            if child_node.localName == 'mass':
                mass = _XMLDecoder._decode_mass(child_node)
                mass.seasonid = seasonid
                result.append(mass)
            elif child_node.localName == 'week':
                masses = _XMLDecoder._decode_week(child_node)
                for mass in masses:
                    mass.seasonid = seasonid
                result.extend(masses)
        return result
示例#7
0
    def _decode_mass(mass_node):
        '''
        Decode a single <mass> element and return it as a
        :class:`Mass` objects.
        '''

        fixedMonth, fixedDay = None, None
        fixedDate = domtools.attr(mass_node, 'date', None)
        if fixedDate is not None:
            fixedMonth, fixedDay = fixedDate.split('-')
            fixedMonth, fixedDay = int(fixedMonth), int(fixedDay)

        weekid = domtools.attr(mass_node, 'weekid', ifMissing=None)
        id_ = domtools.attr(mass_node, 'id', ifMissing=None)
        name = domtools.attr(mass_node, 'name', ifMissing=None)
        longname = domtools.attr(mass_node, 'longname', ifMissing=None)

        readings = []
        option_index = 0
        for child_node in domtools.children(
                mass_node, ['reading', 'option', 'variation']):
            if child_node.localName == 'reading':
                readings.append(_XMLDecoder._decode_reading(child_node))
            elif child_node.localName == 'option':
                optional_readings = _XMLDecoder._decode_option(child_node)
                for optional_reading_index, optional_reading in enumerate(
                        optional_readings):
                    optional_reading.optionSetIndex = option_index
                    optional_reading.optionSetSize = len(optional_readings)
                    optional_reading.optionIndex = optional_reading_index
                readings.extend(optional_readings)
                option_index += 1
            elif child_node.localName == 'variation':
                readings.extend(_XMLDecoder._decode_variation(child_node))

        mass = Mass(readings)
        mass.name = name
        mass.longName = longname
        mass.fixedMonth = fixedMonth
        mass.fixedDay = fixedDay
        mass.id = id_
        mass.weekid = weekid
        return mass