Skip to content
This repository has been archived by the owner on Aug 25, 2024. It is now read-only.

Commit

Permalink
source: csv: Strip spaces in columns by default
Browse files Browse the repository at this point in the history
Fixes: #317
  • Loading branch information
nitesh585 authored Mar 24, 2021
1 parent d1d2b0c commit cfadbd0
Showing 1 changed file with 5 additions and 0 deletions.
5 changes: 5 additions & 0 deletions dffml/source/csv.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ async def dec(self):
CSV_SOURCE_CONFIG_DEFAULT_tag = "untagged"
CSV_SOURCE_CONFIG_DEFAULT_tag_COLUMN = "tag"
CSV_SOURCE_CONFIG_DEFAULT_LOADFILES_NAME = None
CSV_SOURCE_CONFIG_DEFAULT_NOSTRIP = False


@config
Expand All @@ -51,6 +52,7 @@ class CSVSourceConfig(FileSourceConfig):
tag: str = CSV_SOURCE_CONFIG_DEFAULT_tag
tagcol: str = CSV_SOURCE_CONFIG_DEFAULT_tag_COLUMN
loadfiles: List[str] = CSV_SOURCE_CONFIG_DEFAULT_LOADFILES_NAME
nostrip: bool = CSV_SOURCE_CONFIG_DEFAULT_NOSTRIP


# CSVSource is a bit of a mess
Expand Down Expand Up @@ -101,6 +103,9 @@ async def read_csv(self, fd, open_file):
# If there is no key track row index to be used as key by tag
index = {}
for row in dict_reader:
# Strip the keys and values of row
if not self.config.nostrip:
row = {k.strip(): v.strip() for k, v in row.items()}
# Grab tag from row
tag = row.get(self.config.tagcol, self.config.tag)
# Load via ConfigLoaders if loadfiles parameter is given
Expand Down

0 comments on commit cfadbd0

Please sign in to comment.