Add hooks for opening and closing the uploaded file
authorKarl O. Pinc <kop@karlpinc.com>
Wed, 13 Jan 2021 22:50:15 +0000 (16:50 -0600)
committerKarl O. Pinc <kop@karlpinc.com>
Wed, 13 Jan 2021 22:50:15 +0000 (16:50 -0600)
src/pgwui_core/core.py

index 4fd045cda54c253be9efa45a94574ef700c6ec44..fca5958ce9eb7dc82d5302abbdd6b4007bc0990f 100644 (file)
@@ -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()