self._fc = fc
def __iter__(self):
- return next(self._store)
+ for item in self._store:
+ yield item
def __len__(self):
return len(self._store)
self.lineno = 0
def __iter__(self):
- return self
-
- def __next__(self):
- '''
- Iterator to return a thunk which, when called, delivers the
- next object to be loaded into the db.'''
- self.lineno += 1
- return self._thunk()
+ for thunk in self._thunk():
+ self.lineno += 1
+ yield thunk
def _thunk():
'''
super(SQLData, self).__init__()
self.stmts = stmts
- def gen(stmts):
- for stmt in stmts:
- yield stmt
-
- self.stmt_gen = gen(stmts)
-
def _thunk(self):
- stmt = next(self.stmt_gen)
- return lambda: stmt
+ for stmt in self.stmts:
+ yield lambda: stmt
class UploadData(DBData):
Return a thunk which, when called, delivers the
UploadDataLine of the next line of the uploaded file..
'''
- line = next(self._fileo)
- return lambda: UploadDataLine(line,
- self.lineno,
- self._parser,
- self._mapper)
+ for line in self._fileo:
+ yield lambda: UploadDataLine(line,
+ self.lineno,
+ self._parser,
+ self._mapper)
def _extend(self, line, seq):
'''Give the list as many elements as there are in the header.
'''
response = super(UploadHandler, self).write(result, errors)
if hasattr(self, 'data'):
- response['lines'] = self.data.lineno - 1
+ response['lines'] = self.data.lineno
response['e_cnt'] = len(errors)
response['db_changed'] = (not response['errors']
and self.uf['action'] != '')
def cleanup(self):
'''Finish after processing all lines.'''
lines = self.ue.data.lineno
- if lines == 1:
+ if lines == 0:
raise core_ex.DataLineError(
1,
'File contains no data',