Features: 1) Add support for parsing files directly from zip-encoded streams.
Fixes: 1) Correct parsing logic to ensure consistent handling of file objects regardless of source type. Extra: Refactor indentation and reduce duplicate logic for file parsing.
This commit is contained in:
parent
43c8df0c05
commit
97b877c943
1 changed files with 20 additions and 9 deletions
|
|
@ -215,20 +215,31 @@ class Command(BaseCommand):
|
|||
with zipfile.ZipFile(str(filepath)).open(name + ".txt", "r") as f:
|
||||
zip_member = f
|
||||
file_obj = io.TextIOWrapper(zip_member, encoding="utf-8")
|
||||
|
||||
for row in file_obj:
|
||||
if not row.startswith("#"):
|
||||
yield dict(
|
||||
list(
|
||||
zip(
|
||||
settings.files[filekey]["fields"],
|
||||
row.rstrip("\n").split("\t"),
|
||||
)
|
||||
)
|
||||
)
|
||||
else:
|
||||
with open(os.path.join(self.data_dir, filename), encoding="utf-8") as f:
|
||||
file_obj = f
|
||||
|
||||
for row in file_obj:
|
||||
if not row.startswith("#"):
|
||||
yield dict(
|
||||
list(
|
||||
zip(
|
||||
settings.files[filekey]["fields"],
|
||||
row.rstrip("\n").split("\t"),
|
||||
for row in file_obj:
|
||||
if not row.startswith("#"):
|
||||
yield dict(
|
||||
list(
|
||||
zip(
|
||||
settings.files[filekey]["fields"],
|
||||
row.rstrip("\n").split("\t"),
|
||||
)
|
||||
)
|
||||
)
|
||||
)
|
||||
)
|
||||
|
||||
def parse(self, data):
|
||||
for line in data:
|
||||
|
|
|
|||
Loading…
Reference in a new issue