from pgwui_core import exceptions as core_ex
+# Line-by-line processing errors
+
+class CannotReReadError(core_ex.DataLineError):
+ def __init__(self, filename, lineno, exp):
+ super().__init__(
+ lineno,
+ f'Cannot re-open ({filename}) to read db data',
+ f'The error is: {exp}')
+
+
# PGWUI setting related exceptions
class Error(core_ex.Error):
trim (boolean) Trim leading and trailing whitespace?
filepath Path of file (zip_root relative)
- reopened The file has been re-opened after reading the header line
'''
super().__init__(fileo, file_fmt, null_data, null_rep, trim=True)
self.path = path
self.filepath = archive_path(path)
self.relation = relation
- self.reopened = False
def _thunk(self):
'''Get the thunk which returns the next udl
'''
+ # Reopen the file, now that it is time to upload it
try:
- yield from super()._thunk()
- except ValueError:
- # The file isn't open
- if self.reopened:
- super()._thunk().close()
- return # skip this file
- # Reopen the file, now that it is time to upload it
- self.reopened = True
- try:
- self.open_fileo(self.path.open('rb'))
- except OSError as exp:
- # If the file does not open on the next iteration it is skipped
- raise ex.CannotReadError(self.filepath, exp)
- next(super()._thunk()) # skip header
- yield from super()._thunk()
+ self.open_fileo(self.path.open('rb'))
+ except OSError as exp:
+ saved = exp
+
+ def thunk():
+ raise ex.CannotReReadError(self.filepath, self.lineno, saved)
+ yield thunk
+ self.lineno -= 1
+ return # shut down generator
+ next(super()._thunk()) # skip header
+ yield from super()._thunk()
@attr.s