Example #1
0
    def _to_DOM(self):
        """
        Dumps object data to a fully traversable DOM representation of the
        object.

        :returns: a ``xml.etree.Element`` object

        """
        root_node = ET.Element("so2index")
        reference_time_node = ET.SubElement(root_node, "reference_time")
        reference_time_node.text = str(self._reference_time)
        reception_time_node = ET.SubElement(root_node, "reception_time")
        reception_time_node.text = str(self._reception_time)
        interval_node = ET.SubElement(root_node, "interval")
        interval_node.text = str(self._interval)
        so2_samples_node = ET.SubElement(root_node, "so2_samples")
        for smpl in self._so2_samples:
            s = smpl.copy()
            # turn values to 12 decimal digits-formatted strings
            s['pressure'] = '{:.12e}'.format(s['pressure'])
            s['value'] = '{:.12e}'.format(s['value'])
            s['precision'] = '{:.12e}'.format(s['precision'])
            xmlutils.create_DOM_node_from_dict(s, "so2_sample",
                                               so2_samples_node)
        root_node.append(self._location._to_DOM())
        return root_node
Example #2
0
    def _to_DOM(self):
        """
        Dumps object data to a fully traversable DOM representation of the
        object.

        :returns: a ``xml.etree.Element`` object

        """
        root_node = ET.Element("weather")
        status_node = ET.SubElement(root_node, "status")
        status_node.text = self._status
        weather_code_node = ET.SubElement(root_node, "weather_code")
        weather_code_node.text = str(self._weather_code)
        xmlutils.create_DOM_node_from_dict(self._rain, "rain", root_node)
        xmlutils.create_DOM_node_from_dict(self._snow, "snow", root_node)
        xmlutils.create_DOM_node_from_dict(self._pressure, "pressure",
                                           root_node)
        node_sunrise_time = ET.SubElement(root_node, "sunrise_time")
        node_sunrise_time.text = str(self._sunrise_time)
        weather_icon_name_node = ET.SubElement(root_node, "weather_icon_name")
        weather_icon_name_node.text = self._weather_icon_name
        clouds_node = ET.SubElement(root_node, "clouds")
        clouds_node.text = str(self._clouds)
        xmlutils.create_DOM_node_from_dict(self._temperature, "temperature",
                                           root_node)
        detailed_status_node = ET.SubElement(root_node, "detailed_status")
        detailed_status_node.text = self._detailed_status
        reference_time_node = ET.SubElement(root_node, "reference_time")
        reference_time_node.text = str(self._reference_time)
        sunset_time_node = ET.SubElement(root_node, "sunset_time")
        sunset_time_node.text = str(self._sunset_time)
        humidity_node = ET.SubElement(root_node, "humidity")
        humidity_node.text = str(self._humidity)
        xmlutils.create_DOM_node_from_dict(self._wind, "wind", root_node)
        return root_node
Example #3
0
    def _to_DOM(self):
        """
        Dumps object data to a fully traversable DOM representation of the
        object.

        :returns: a ``xml.etree.Element`` object

        """
        root_node = ET.Element("coindex")
        reference_time_node = ET.SubElement(root_node, "reference_time")
        reference_time_node.text = str(self._reference_time)
        reception_time_node = ET.SubElement(root_node, "reception_time")
        reception_time_node.text = str(self._reception_time)
        interval_node = ET.SubElement(root_node, "interval")
        interval_node.text = str(self._interval)
        co_samples_node = ET.SubElement(root_node, "co_samples")
        for smpl in self._co_samples:
            s = smpl.copy()
            # turn values to 12 decimal digits-formatted strings
            s['pressure'] = '{:.12e}'.format(s['pressure'])
            s['value'] = '{:.12e}'.format(s['value'])
            s['precision'] = '{:.12e}'.format(s['precision'])
            xmlutils.create_DOM_node_from_dict(s, "co_sample",
                                               co_samples_node)
        root_node.append(self._location._to_DOM())
        return root_node
Example #4
0
    def _to_DOM(self):
        """
        Dumps object data to a fully traversable DOM representation of the
        object.

        :returns: a ``xml.etree.Element`` object

        """
        root_node = ET.Element("weather")
        status_node = ET.SubElement(root_node, "status")
        status_node.text = self._status
        weather_code_node = ET.SubElement(root_node, "weather_code")
        weather_code_node.text = str(self._weather_code)
        xmlutils.create_DOM_node_from_dict(self._rain, "rain", root_node)
        xmlutils.create_DOM_node_from_dict(self._snow, "snow", root_node)
        xmlutils.create_DOM_node_from_dict(self._pressure, "pressure",
                                             root_node)
        node_sunrise_time = ET.SubElement(root_node, "sunrise_time")
        node_sunrise_time.text = str(self._sunrise_time)
        weather_icon_name_node = ET.SubElement(root_node, "weather_icon_name")
        weather_icon_name_node.text = self._weather_icon_name
        clouds_node = ET.SubElement(root_node, "clouds")
        clouds_node.text = str(self._clouds)
        xmlutils.create_DOM_node_from_dict(self._temperature,
                                                "temperature", root_node)
        detailed_status_node = ET.SubElement(root_node, "detailed_status")
        detailed_status_node.text = self._detailed_status
        reference_time_node = ET.SubElement(root_node, "reference_time")
        reference_time_node.text = str(self._reference_time)
        sunset_time_node = ET.SubElement(root_node, "sunset_time")
        sunset_time_node.text = str(self._sunset_time)
        humidity_node = ET.SubElement(root_node, "humidity")
        humidity_node.text = str(self._humidity)
        xmlutils.create_DOM_node_from_dict(self._wind, "wind", root_node)
        return root_node
Example #5
0
 def test_create_DOM_node_from_dict_when_input_is_None(self):
     d = None
     name = "test"
     test_root_node = ET.Element("root")
     expected = "<root></root>"
     xmlutils.create_DOM_node_from_dict(d, name, test_root_node)
     result_DOM_tree = ET.ElementTree(test_root_node)
     self.assertEqual(expected, ET.tostring(result_DOM_tree.getroot(),
                                             encoding='utf8',
                                             method='html').decode('utf-8'))
Example #6
0
 def test_create_DOM_node_from_dict(self):
     d = {"a": 43.2, "b": None}
     name = "test"
     test_root_node = ET.Element("root")
     expected = "<root><test><a>43.2</a></test></root>"
     xmlutils.create_DOM_node_from_dict(d, name, test_root_node)
     result_DOM_tree = ET.ElementTree(test_root_node)
     self.assertEqual(expected, ET.tostring(result_DOM_tree.getroot(),
                                             encoding='utf8',
                                             method='html').decode('utf-8'))
Example #7
0
 def test_create_DOM_node_from_dict_when_input_is_None(self):
     d = None
     name = "test"
     test_root_node = ET.Element("root")
     expected = "<root></root>"
     xmlutils.create_DOM_node_from_dict(d, name, test_root_node)
     result_DOM_tree = ET.ElementTree(test_root_node)
     self.assertEqual(
         expected,
         ET.tostring(result_DOM_tree.getroot(),
                     encoding='utf8',
                     method='html').decode('utf-8'))
Example #8
0
 def test_create_DOM_node_from_dict(self):
     d = {"a": 43.2, "b": None}
     name = "test"
     test_root_node = ET.Element("root")
     expected = "<root><test><a>43.2</a></test></root>"
     xmlutils.create_DOM_node_from_dict(d, name, test_root_node)
     result_DOM_tree = ET.ElementTree(test_root_node)
     self.assertEqual(
         expected,
         ET.tostring(result_DOM_tree.getroot(),
                     encoding='utf8',
                     method='html').decode('utf-8'))
Example #9
0
    def _to_DOM(self):
        """
        Dumps object data to a fully traversable DOM representation of the
        object.

        :returns: a ``xml.etree.Element`` object

        """
        root_node = ET.Element("station_history")
        station_id_node = ET.SubElement(root_node, "station_id")
        station_id_node.text = str(self._station_ID)
        interval_node = ET.SubElement(root_node, "interval")
        interval_node.text = self._interval
        reception_time_node = ET.SubElement(root_node, "reception_time")
        reception_time_node.text = str(self._reception_time)
        measurements_node = ET.SubElement(root_node, "measurements")
        for m in self._measurements:
            d = self._measurements[m].copy()
            d['reference_time'] = m
            xmlutils.create_DOM_node_from_dict(d, "measurement",
                                               measurements_node)
        return root_node
Example #10
0
    def _to_DOM(self):
        """
        Dumps object data to a fully traversable DOM representation of the
        object.

        :returns: a ``xml.etree.Element`` object

        """
        root_node = ET.Element("station_history")
        station_id_node = ET.SubElement(root_node, "station_id")
        station_id_node.text = str(self._station_ID)
        interval_node = ET.SubElement(root_node, "interval")
        interval_node.text = self._interval
        reception_time_node = ET.SubElement(root_node, "reception_time")
        reception_time_node.text = str(self._reception_time)
        measurements_node = ET.SubElement(root_node, "measurements")
        for m in self._measurements:
            d = self._measurements[m].copy()
            d['reference_time'] = m
            xmlutils.create_DOM_node_from_dict(d, "measurement",
                                               measurements_node)
        return root_node