def run(self, params={}): decoded = base64.b64decode(params[Input.CSV]).decode() csv_good = utils.csv_syntax_good(decoded) fields_good = utils.fields_syntax_good(params[Input.FIELDS]) if csv_good and fields_good: csv_array = utils.parse_csv_string(decoded) fields = utils.get_field_list(params[Input.FIELDS], len(csv_array[0])) if fields: filtered = [] for line in csv_array: filtered.append(utils.keep_fields(line, fields)) converted = utils.convert_csv_array(filtered) return { Output.FILTERED: base64.b64encode(converted.encode()).decode() } else: raise PluginException(cause='Wrong input', assistance='Invalid field indices') elif not csv_good: raise PluginException(cause='Wrong input', assistance='Improper syntax in CSV bytes') else: raise PluginException( cause='Wrong input', assistance='Improper syntax in fields string')
def run(self, params={}): csv_good = utils.csv_syntax_good(params['csv']) fields_good = utils.fields_syntax_good(params['fields']) if csv_good and fields_good: csv_array = utils.parse_csv_string(params['csv']) fields = utils.get_field_list(params['fields'], len(csv_array[0])) if fields: filtered = [] for line in csv_array: filtered.append(utils.keep_fields(line, fields)) return {'string': utils.convert_csv_array(filtered)} else: raise ValueError('Invalid field indices') elif not csv_good: raise ValueError('Improper syntax in CSV string') else: raise ValueError('Improper syntax in fields string')
def run(self, params={}): csv_good = utils.csv_syntax_good(params[Input.CSV]) fields_good = utils.fields_syntax_good(params[Input.FIELDS]) if csv_good and fields_good: csv_array = utils.parse_csv_string(params[Input.CSV]) fields = utils.get_field_list(params[Input.FIELDS], len(csv_array[0])) if fields: filtered = [] for line in csv_array: filtered.append(utils.keep_fields(line, fields)) return {Output.STRING: utils.convert_csv_array(filtered)} else: raise PluginException(cause="Wrong input", assistance="Invalid field indices") elif not csv_good: raise PluginException(cause="Wrong input", assistance="Improper syntax in CSV bytes") else: raise PluginException( cause="Wrong input", assistance="Improper syntax in fields string")