Code Duplication    Length = 29-32 lines in 2 locations

amd/io.py 2 locations

@@ 142-173 (lines=32) @@
139
                self.current_filename = file
140
                yield from file_parser(os.path.join(path, file))
141
142
    def _map(self, func: Callable, iterable: Iterable) -> Iterable[PeriodicSet]:
143
        """Iterates over iterable, passing items through parser and yielding the result.
144
        Applies warning and include_if filters, catches bad structures and warns.
145
        """
146
147
        for item in iterable:
148
149
            with warnings.catch_warnings(record=True) as warning_msgs:
150
151
                if not self.show_warnings:
152
                    warnings.simplefilter('ignore')
153
154
                if any(not check(item) for check in self.include_if):
155
                    continue
156
157
                try:
158
                    periodic_set = func(item)
159
                except ParseError as err:
160
                    warnings.warn(err, category=UserWarning)
161
                    continue
162
163
            for warning in warning_msgs:
164
                msg = f'{periodic_set.name}: {warning.message}'
165
                warnings.warn(msg, category=warning.category)
166
167
            if self.current_filename:
168
                periodic_set.tags['filename'] = self.current_filename
169
170
            for key, func in self.extract_data.items():
171
                periodic_set.tags[key] = func(item)
172
173
            yield periodic_set
174
175
176
class CSDReader:
@@ 297-325 (lines=29) @@
294
                except RuntimeError:
295
                    warnings.warn(f'Identifier {refcode} not found in database')
296
297
    def _map(self, func: Callable, iterable: Iterable) -> Iterable[PeriodicSet]:
298
        """Iterates over iterable, passing items through parser and yielding the result.
299
        Applies warning and include_if filters, catches bad structures and warns.
300
        """
301
302
        for item in iterable:
303
304
            with warnings.catch_warnings(record=True) as warning_msgs:
305
306
                if not self.show_warnings:
307
                    warnings.simplefilter('ignore')
308
309
                if any(not check(item) for check in self.include_if):
310
                    continue
311
312
                try:
313
                    periodic_set = func(item)
314
                except ParseError as err:
315
                    warnings.warn(err, category=UserWarning)
316
                    continue
317
318
            for warning in warning_msgs:
319
                msg = f'{periodic_set.name}: {warning.message}'
320
                warnings.warn(msg, category=warning.category)
321
322
            for key, func in self.extract_data.items():
323
                periodic_set.tags[key] = func(item)
324
325
            yield periodic_set
326
327
328
def entry_to_periodicset(entry,