|
26 | 26 | from io import BytesIO
|
27 | 27 | from itertools import chain
|
28 | 28 | from pathlib import Path, PurePosixPath
|
29 |
| -from typing import Any, Callable, Dict, Generator, List, Optional, Tuple, TypeVar, Union |
| 29 | +from typing import Any, Dict, Generator, List, Optional, Tuple, TypeVar, Union |
30 | 30 | from unittest.mock import patch
|
31 | 31 | from urllib.parse import urljoin, urlparse
|
32 | 32 | from xml.etree import ElementTree as ET
|
|
47 | 47 | from . import tqdm as hf_tqdm
|
48 | 48 | from ._filelock import FileLock
|
49 | 49 | from .extract import ExtractManager
|
50 |
| -from .track import TrackedIterable |
| 50 | +from .track import TrackedIterableFromGenerator |
51 | 51 |
|
52 | 52 |
|
53 | 53 | logger = logging.get_logger(__name__) # pylint: disable=invalid-name
|
@@ -1564,23 +1564,7 @@ def xxml_dom_minidom_parse(filename_or_file, download_config: Optional[DownloadC
|
1564 | 1564 | return xml.dom.minidom.parse(f, **kwargs)
|
1565 | 1565 |
|
1566 | 1566 |
|
1567 |
| -class _IterableFromGenerator(TrackedIterable): |
1568 |
| - """Utility class to create an iterable from a generator function, in order to reset the generator when needed.""" |
1569 |
| - |
1570 |
| - def __init__(self, generator: Callable, *args, **kwargs): |
1571 |
| - super().__init__() |
1572 |
| - self.generator = generator |
1573 |
| - self.args = args |
1574 |
| - self.kwargs = kwargs |
1575 |
| - |
1576 |
| - def __iter__(self): |
1577 |
| - for x in self.generator(*self.args, **self.kwargs): |
1578 |
| - self.last_item = x |
1579 |
| - yield x |
1580 |
| - self.last_item = None |
1581 |
| - |
1582 |
| - |
1583 |
| -class ArchiveIterable(_IterableFromGenerator): |
| 1567 | +class ArchiveIterable(TrackedIterableFromGenerator): |
1584 | 1568 | """An iterable of (path, fileobj) from a TAR archive, used by `iter_archive`"""
|
1585 | 1569 |
|
1586 | 1570 | @staticmethod
|
@@ -1645,7 +1629,7 @@ def from_urlpath(cls, urlpath_or_buf, download_config: Optional[DownloadConfig]
|
1645 | 1629 | return cls(cls._iter_from_urlpath, urlpath_or_buf, download_config)
|
1646 | 1630 |
|
1647 | 1631 |
|
1648 |
| -class FilesIterable(_IterableFromGenerator): |
| 1632 | +class FilesIterable(TrackedIterableFromGenerator): |
1649 | 1633 | """An iterable of paths from a list of directories or files"""
|
1650 | 1634 |
|
1651 | 1635 | @classmethod
|
|
0 commit comments