def test_dst_range(self):
     y1 = 2005
     y2 = 2006
     r1 = dst_range(y1)
     r2 = dst_range(y2)
     # Make sure the correct DST start and end ISO 8601 strings are reported
     # the 2005:
     self.assert_comparison('r1.dst_start_text()', '==',
                            "'2005-04-03T10:00:00Z'")
     self.assert_comparison('r1.dst_end_text()', '==',
                            "'2005-10-30T09:00:00Z'")
     # Make sure the correct DST start and end ISO 8601 strings are reported
     # the 2006:
     self.assert_comparison('r2.dst_start_text()', '==',
                            "'2006-04-02T10:00:00Z'")
     self.assert_comparison('r2.dst_end_text()', '==',
                            "'2006-10-29T09:00:00Z'")
     # Make sure the ID and value comparisons are valid:
     self.assert_comparison('r1', 'is not', 'DSTRange(y1)')
     self.assert_comparison('r1', '==', 'DSTRange(y1)')
     self.assert_comparison('r1', '!=', 'r2')
     # Ensure that DSTRanges were cached:
     self.assert_comparison('dst_range(y1)', 'is', 'r1')
     self.assert_comparison('dst_range(y2)', 'is', 'r2')
     return
    def format(self, data):
        stream = StreamWithCallback(self.output_callback)
        stream.set_meta('data',data)
        stream.set_meta('index',0)
        formatter = SGMLFormatter()
        stream.set_meta('formatter',formatter)
        stream.set_meta('remaining', '')
        #
        #
        #
        stream.write('<?xml version="1.0" encoding="utf-8"?>\n')
        if self.add_smtp_envelope:
            #
            # <Envelope>
            #
            formatter.open_tag(
                'Envelope', **{
                'xmlns:xsd':'http://www.w3.org/2001/XMLSchema',
                'xmlns:xsi':'http://www.w3.org/2001/XMLSchema-instance',
                }
                )
            #
            # <Header/>
            #
            formatter.open_close_tag(
                'Header', xmlns="http://schemas.xmlsoap.org/soap/envelope/"
                )
            #
            # <Body>
            #
            formatter.open_tag(
                'Body', xmlns="http://schemas.xmlsoap.org/soap/envelope/"
                )
            #
            # <Process>
            #
            formatter.open_tag(
                'Process',
                xmlns=("http://rddl.xmlinside.net/PowerMeasurement/data/ion/" +
                       "pushmessaging/service/1/")
                )
        #
        # <Data>
        #
        attributes = {
            'id':self.data_id(),
            'xmlns':(
                "http://rddl.xmlinside.net/PowerMeasurement/data/ion/" +
                "pushmessaging/2/"
                ),
            'xmlns:ident':(
                "http://rddl.xmlinside.net/PowerMeasurement/data/ion/" +
                "identity/1/"
                ),
            }
        formatter.open_tag('Data', **attributes)
        #
        # <ident:GeneratedBy/>
        #
        attributes = {
            'ident:name':self.generated_by,
            'ident:namespace':self.generated_by_namespace,
            'ident:dateTime':W3CDateTime().as_string_local(),
            }
        if self.generated_by_type:
            attributes['ident:type'] = self.generated_by_type,
        if self.generated_by_signature:
            attributes['ident:signature'] = self.generated_by_signature,
        formatter.open_close_tag('ident:GeneratedBy', **attributes)
# Not required according to Stephan Jones
#         formatter.open_tag(
#             'Configuration', **{
#             'ident:template':self.configuration_template,
#             'ident:owner':self.configuration_owner,
#             'ident:tag1':self.configuration_tag1,
#             'ident:tag2':self.configuration_tag2,
#             'ident:revision':self.configuration_revision,
#             'xmlns:ident':('http://rddl.xmlinside.net/PowerMeasurement' +
#                           '/data/ion/identity/1/'),
#             'xmlns':('http://rddl.xmlinside.net/PowerMeasurement/data' +
#                      '/ion/identity/1/')
#             }
#             )
#         formatter.open_tag('ident:Timezone')
#         formatter.open_tag('ident:Bias')
#         formatter.add_text(self.timezone_bias)
#         formatter.close_tag('ident:Bias', True)
#         formatter.open_tag('ident:DSTBias')
#         formatter.add_text(self.timezone_dst_bias)
#         formatter.close_tag('ident:DSTBias', True)
#         formatter.open_tag('ident:DSTStart')
#         formatter.add_text(self.timezone_dst_start)
#         formatter.close_tag('ident:DSTStart', True)
#         formatter.open_tag('ident:DSTEnd')
#         formatter.add_text(self.timezone_dst_end)
#         formatter.close_tag('ident:DSTEnd', True)
#         formatter.close_tag('ident:Timezone')
#         formatter.close_tag('Configuration')
        #
        # <Device>
        #
        attributes = {
            'ident:name':self.device_name,
            'ident:namespace':self.device_namespace,
            'ident:type':self.device_type,
            }
        if self.device_signature:
            attributes['ident:signature'] = self.device_signature,
        formatter.open_tag('Device', **attributes)
        #
        # <ident:Configuration>
        #
        attributes = {}
        if self.device_configuration_template:
            attributes['ident:template'] = self.device_configuration_template
        if self.device_configuration_owner:
            attributes['ident:owner'] = self.device_configuration_owner
        if self.device_configuration_tag1:
            attributes['ident:tag1'] = self.device_configuration_tag1
        if self.device_configuration_tag2:
            attributes['ident:tag2'] = self.device_configuration_tag2
        if self.device_configuration_revision:
            attributes['ident:revision'] = self.device_configuration_revision
        formatter.open_tag('ident:Configuration', **attributes)
        #
        # <ident:Timezone>
        #
        formatter.open_tag('ident:Timezone')
        #
        # <ident:Bias>
        #
        formatter.open_tag('ident:Bias')
        formatter.add_text(DST_BIAS.bias_text())
        #
        # </ident:Bias>
        #
        formatter.close_tag('ident:Bias', True)
        dst_bias_text = DST_BIAS.dst_bias_text()
        if dst_bias_text:
            #
            # <ident:DSTBias>
            #
            formatter.open_tag('ident:DSTBias')
            formatter.add_text(dst_bias_text)
            #
            # </ident:DSTBias>
            #
            formatter.close_tag('ident:DSTBias', True)
        this_year = time.localtime().tm_year
        last_year = this_year - 1
        for year in (last_year, this_year):
            dst_range_object = dst_range(year)
            dst_start = dst_range_object.dst_start_text()
            dst_end = dst_range_object.dst_end_text()
            if dst_start:
                #
                # <ident:DSTStart>
                #
                formatter.open_tag('ident:DSTStart')
                formatter.add_text(dst_start)
                #
                # </ident:DSTStart>
                #
                formatter.close_tag('ident:DSTStart', True)
                if dst_end:
                    #
                    # <ident:DSTEnd>
                    #
                    formatter.open_tag('ident:DSTEnd')
                    formatter.add_text(dst_end)
                    #
                    # </ident:DSTEnd>
                    #
                    formatter.close_tag('ident:DSTEnd', True)
        #
        # </ident:Timezone>
        #
        formatter.close_tag('ident:Timezone')
        #
        # </ident:Configuration>
        #
        formatter.close_tag('ident:Configuration')
        #
        # <DataRecorder>
        #
        attributes = {
            'id':self.data_recorder_id,
            'label':self.data_recorder_label,
            }
        if self.data_recorder_handle:
            attributes['handle'] = self.data_recorder_handle
        formatter.open_tag('DataRecorder', **attributes)
        #
        # <Channels>
        #
        formatter.open_tag('Channels')
        channel_list = self._channel_map.values()
        def cmp_channel_list(c1, c2):
            return cmp(c1.mmafmt_channel_id, c2.mmafmt_channel_id)
        channel_list.sort(cmp_channel_list)
        for column_node in channel_list:
            #
            # <Channel/>
            #
            attributes = {
                'id':column_node.mmafmt_channel_id,
                'label':column_node.mmafmt_channel_label,
                }
            if column_node.mmafmt_channel_pos:
                attributes['pos'] = column_node.mmafmt_channel_pos
            formatter.open_close_tag('Channel', **attributes)
        #
        # </Channels>
        #
        formatter.close_tag('Channels')
        #
        # <DataRecords>
        #
        formatter.open_tag('DataRecords')
        return stream