def map_to_resource(self, data_element): trv = DataElementTreeTraverser(data_element, self, direction=PROCESSING_DIRECTIONS.READ) visitor = ResourceBuilderDataElementTreeVisitor() trv.run(visitor) return visitor.resource
def run(self, data_element): trv = DataElementTreeTraverser(data_element, self._mapping, direction=PROCESSING_DIRECTIONS.WRITE) vst = JsonDataElementTreeVisitor() trv.run(vst) rpr_string = dumps(vst.json_data) self._stream.write(rpr_string)
def run(self, data_element): # We also emit None values to make sure every data row has the same # number of fields. trv = DataElementTreeTraverser(data_element, self._mapping, ignore_none_values=False) vst = CsvDataElementTreeVisitor(self.get_option('encoding')) trv.run(vst) csv_data = vst.csv_data if len(csv_data) > 0: wrt = writer(self._stream, dialect=self.get_option('dialect')) wrt.writerow(csv_data.fields) for row_data in csv_data.data: wrt.writerow(row_data)
def run(self, data_element): trv = DataElementTreeTraverser(data_element, self._mapping) vst = JsonDataElementTreeVisitor() trv.run(vst) rpr_string = dumps(vst.json_data) self._stream.write(rpr_string)
def test_mapping_invalid_dataelement_raises_error(self): invalid_de = InvalidKindDataElement() invalid_de.mapping = self.mapping # pylint: disable=W0201 also_provides(invalid_de, IDataElement) trv = DataElementTreeTraverser(invalid_de, self.mapping.as_pruning()) self.assert_raises(ValueError, trv.run, None)