From: Karl O. Pinc Date: Wed, 13 Jan 2021 22:50:15 +0000 (-0600) Subject: Add hooks for opening and closing the uploaded file X-Git-Url: https://papio.biology.duke.edu/gitweb/?a=commitdiff_plain;h=68cd3ebc389818f551d1b0911a9b80e40064c6ea;p=pgwui_core Add hooks for opening and closing the uploaded file --- diff --git a/src/pgwui_core/core.py b/src/pgwui_core/core.py index 4fd045c..fca5958 100644 --- a/src/pgwui_core/core.py +++ b/src/pgwui_core/core.py @@ -879,6 +879,18 @@ class UploadData(DBData): return self._extend(line, line.split('\t')) self._parser = tab_parser + def open_fileo(self, fileo): + '''Setup the buffered text stream for self.fileo + ''' + # Read lines as text with line endings intact. + # newline='' required by csv.reader() + self._fileo = io.TextIOWrapper(fileo, newline='') + + def close_fileo(self): + '''Close self.fileo + ''' + self._fileo.close() + def __init__(self, fileo, file_fmt, null_data, null_rep, trim=True): ''' fileo Uploaded file object @@ -931,9 +943,7 @@ class UploadData(DBData): def do_trim(st): return st - # Read lines as text with line endings intact. - # newline='' required by csv.reader() - self._fileo = io.TextIOWrapper(fileo, newline='') + self.open_fileo(fileo) # Get column headings eol, self.headers = get_headers()